summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael van Tellingen <michaelvantellingen@gmail.com>2013-02-14 09:45:55 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-02-14 10:22:59 +0100
commit138de533ff677b470a1e7b4b6ff084a5b7a7444b (patch)
treef7be64117ff4d463ba6a7f28701c319f1d091843 /tests
parentf1029b308f3ea967a5d93aea2b730671898a56f5 (diff)
Fixed #19819 - Improved template filter errors handling.
Wrap the Parser.compile_filter method call with a try/except and call the newly added Parser.compile_filter_error(). Overwrite this method in the DebugParser to throw the correct error. Since this error was otherwise catched by the compile_function try/except block the debugger highlighted the wrong line.
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/templates/parser.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/tests/regressiontests/templates/parser.py b/tests/regressiontests/templates/parser.py
index 6c9deee9ff..9422da80d7 100644
--- a/tests/regressiontests/templates/parser.py
+++ b/tests/regressiontests/templates/parser.py
@@ -4,8 +4,10 @@ Testing some internals of the template processing. These are *not* examples to b
from __future__ import unicode_literals
from django.template import (TokenParser, FilterExpression, Parser, Variable,
- TemplateSyntaxError)
+ Template, TemplateSyntaxError)
+from django.test.utils import override_settings
from django.utils.unittest import TestCase
+from django.utils import six
class ParserTests(TestCase):
@@ -83,3 +85,11 @@ class ParserTests(TestCase):
self.assertRaises(TemplateSyntaxError,
Variable, "article._hidden"
)
+
+ @override_settings(DEBUG=True, TEMPLATE_DEBUG=True)
+ def test_compile_filter_error(self):
+ # regression test for #19819
+ msg = "Could not parse the remainder: '@bar' from 'foo@bar'"
+ with six.assertRaisesRegex(self, TemplateSyntaxError, msg) as cm:
+ Template("{% if 1 %}{{ foo@bar }}{% endif %}")
+ self.assertEqual(cm.exception.django_template_source[1], (10, 23))