From: Samuel Colvin Date: Mon, 3 Jul 2017 14:53:12 +0000 (+0100) Subject: fix line numbers in errors X-Git-Url: https://git.devinivas.org/?a=commitdiff_plain;h=9351d2933057d03ecd5e356cde8b9f9416a7a147;p=chevron.git fix line numbers in errors --- 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 @@ class ExpandedCoverage(unittest.TestCase): 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__":