From 9351d2933057d03ecd5e356cde8b9f9416a7a147 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Mon, 3 Jul 2017 15:53:12 +0100 Subject: [PATCH 1/2] fix line numbers in errors --- .gitignore | 1 + chevron/tokenizer.py | 3 +++ test_spec.py | 16 ++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/.gitignore b/.gitignore index e86540c..4707f0a 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ pip-log.txt # Mr Developer .mr.developer.cfg +.idea/ diff --git a/chevron/tokenizer.py b/chevron/tokenizer.py index ed5799e..4362eab 100644 --- a/chevron/tokenizer.py +++ b/chevron/tokenizer.py @@ -160,6 +160,9 @@ def tokenize(template, def_ldel='{{', def_rdel='}}'): the literal itself. """ + global _CURRENT_LINE, _LAST_TAG_LINE + _CURRENT_LINE = 1 + _LAST_TAG_LINE = None # If the template is a file-like object then read it try: template = template.read() diff --git a/test_spec.py b/test_spec.py index 5b34811..a02819e 100755 --- a/test_spec.py +++ b/test_spec.py @@ -202,6 +202,22 @@ def test_closing_tag_only(self): self.assertRaises(chevron.ChevronError, chevron.render, **args) + def test_current_line_rest(self): + args = { + 'template': 'first line\nsecond line\n {{ foo } bar', + 'data': {'foo': 'xx'} + } + + self.assertRaisesRegexp(chevron.ChevronError, + 'unclosed tag at line 3', + chevron.render, **args) + self.assertRaisesRegexp(chevron.ChevronError, + 'unclosed tag at line 3', + chevron.render, **args) + self.assertRaisesRegexp(chevron.ChevronError, + 'unclosed tag at line 3', + chevron.render, **args) + # Run unit tests from command line if __name__ == "__main__": From 1193cd6d8746f52eab7dc247bb00e3e90048392d Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Mon, 3 Jul 2017 17:30:25 +0100 Subject: [PATCH 2/2] add unitest2 to support assertRaisesRegexp on 2.6 --- test_spec.py | 7 ++++++- tox.ini | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/test_spec.py b/test_spec.py index a02819e..3c476db 100755 --- a/test_spec.py +++ b/test_spec.py @@ -1,12 +1,17 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -import unittest import os import json import chevron +import sys +if sys.version_info < (2, 7): + import unittest2 as unittest +else: + import unittest + SPECS_PATH = os.path.join('spec', 'specs') SPECS = [path for path in os.listdir(SPECS_PATH) if path.endswith('.json')] STACHE = chevron.render diff --git a/tox.ini b/tox.ini index 4814333..f051395 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ envlist = py26, py27, py32, py33, py34, py35, pypy, flake8 [testenv] -deps = coverage +deps = coverage,unitest2 commands = coverage run --source={toxinidir}/chevron {toxinidir}/test_spec.py coverage report -m @@ -12,4 +12,4 @@ commands = python {toxinidir}/test_spec.py [testenv:flake8] deps = flake8 -commands = flake8 \ No newline at end of file +commands = flake8