diff options
Diffstat (limited to 'tests/template_tests')
| -rw-r--r-- | tests/template_tests/filter_tests/test_date.py | 4 | ||||
| -rw-r--r-- | tests/template_tests/filter_tests/test_random.py | 8 | ||||
| -rw-r--r-- | tests/template_tests/filter_tests/test_timesince.py | 16 | ||||
| -rw-r--r-- | tests/template_tests/filter_tests/test_timeuntil.py | 8 | ||||
| -rw-r--r-- | tests/template_tests/filter_tests/test_truncatewords.py | 13 | ||||
| -rw-r--r-- | tests/template_tests/filter_tests/test_urlize.py | 2 | ||||
| -rw-r--r-- | tests/template_tests/filter_tests/test_urlizetrunc.py | 2 | ||||
| -rw-r--r-- | tests/template_tests/syntax_tests/test_extends.py | 4 | ||||
| -rw-r--r-- | tests/template_tests/syntax_tests/test_for.py | 4 | ||||
| -rw-r--r-- | tests/template_tests/syntax_tests/test_if_changed.py | 4 | ||||
| -rw-r--r-- | tests/template_tests/syntax_tests/test_url.py | 4 | ||||
| -rw-r--r-- | tests/template_tests/templatetags/custom.py | 4 | ||||
| -rw-r--r-- | tests/template_tests/templatetags/inclusion.py | 49 | ||||
| -rw-r--r-- | tests/template_tests/test_custom.py | 5 | ||||
| -rw-r--r-- | tests/template_tests/test_extends.py | 17 | ||||
| -rw-r--r-- | tests/template_tests/test_nodelist.py | 18 |
16 files changed, 123 insertions, 39 deletions
diff --git a/tests/template_tests/filter_tests/test_date.py b/tests/template_tests/filter_tests/test_date.py index 612742a501..1740df47da 100644 --- a/tests/template_tests/filter_tests/test_date.py +++ b/tests/template_tests/filter_tests/test_date.py @@ -42,7 +42,9 @@ class DateTests(TimezoneTestCase): # Timezone name @setup({'date06': '{{ d|date:"e" }}'}) def test_date06(self): - output = self.engine.render_to_string('date06', {'d': datetime(2009, 3, 12, tzinfo=timezone.get_fixed_timezone(30))}) + output = self.engine.render_to_string( + 'date06', {'d': datetime(2009, 3, 12, tzinfo=timezone.get_fixed_timezone(30))} + ) self.assertEqual(output, '+0030') @setup({'date07': '{{ d|date:"e" }}'}) diff --git a/tests/template_tests/filter_tests/test_random.py b/tests/template_tests/filter_tests/test_random.py index 155e473c7e..acb8a82f1d 100644 --- a/tests/template_tests/filter_tests/test_random.py +++ b/tests/template_tests/filter_tests/test_random.py @@ -8,10 +8,14 @@ class RandomTests(SimpleTestCase): @setup({'random01': '{{ a|random }} {{ b|random }}'}) def test_random01(self): - output = self.engine.render_to_string('random01', {'a': ['a&b', 'a&b'], 'b': [mark_safe('a&b'), mark_safe('a&b')]}) + output = self.engine.render_to_string( + 'random01', {'a': ['a&b', 'a&b'], 'b': [mark_safe('a&b'), mark_safe('a&b')]} + ) self.assertEqual(output, 'a&b a&b') @setup({'random02': '{% autoescape off %}{{ a|random }} {{ b|random }}{% endautoescape %}'}) def test_random02(self): - output = self.engine.render_to_string('random02', {'a': ['a&b', 'a&b'], 'b': [mark_safe('a&b'), mark_safe('a&b')]}) + output = self.engine.render_to_string( + 'random02', {'a': ['a&b', 'a&b'], 'b': [mark_safe('a&b'), mark_safe('a&b')]} + ) self.assertEqual(output, 'a&b a&b') diff --git a/tests/template_tests/filter_tests/test_timesince.py b/tests/template_tests/filter_tests/test_timesince.py index 52901cea36..0572b5bd1c 100644 --- a/tests/template_tests/filter_tests/test_timesince.py +++ b/tests/template_tests/filter_tests/test_timesince.py @@ -18,17 +18,23 @@ class TimesinceTests(TimezoneTestCase): # Default compare with datetime.now() @setup({'timesince01': '{{ a|timesince }}'}) def test_timesince01(self): - output = self.engine.render_to_string('timesince01', {'a': datetime.now() + timedelta(minutes=-1, seconds=-10)}) + output = self.engine.render_to_string( + 'timesince01', {'a': datetime.now() + timedelta(minutes=-1, seconds=-10)} + ) self.assertEqual(output, '1\xa0minute') @setup({'timesince02': '{{ a|timesince }}'}) def test_timesince02(self): - output = self.engine.render_to_string('timesince02', {'a': datetime.now() - timedelta(days=1, minutes=1)}) + output = self.engine.render_to_string( + 'timesince02', {'a': datetime.now() - timedelta(days=1, minutes=1)} + ) self.assertEqual(output, '1\xa0day') @setup({'timesince03': '{{ a|timesince }}'}) def test_timesince03(self): - output = self.engine.render_to_string('timesince03', {'a': datetime.now() - timedelta(hours=1, minutes=25, seconds=10)}) + output = self.engine.render_to_string( + 'timesince03', {'a': datetime.now() - timedelta(hours=1, minutes=25, seconds=10)} + ) self.assertEqual(output, '1\xa0hour, 25\xa0minutes') # Compare to a given parameter @@ -62,7 +68,9 @@ class TimesinceTests(TimezoneTestCase): @setup({'timesince08': '{{ earlier|timesince:now }}'}) def test_timesince08(self): - output = self.engine.render_to_string('timesince08', {'now': self.now, 'earlier': self.now - timedelta(days=7)}) + output = self.engine.render_to_string( + 'timesince08', {'now': self.now, 'earlier': self.now - timedelta(days=7)} + ) self.assertEqual(output, '1\xa0week') @setup({'timesince09': '{{ later|timesince }}'}) diff --git a/tests/template_tests/filter_tests/test_timeuntil.py b/tests/template_tests/filter_tests/test_timeuntil.py index 5befabb379..2fe633ffa2 100644 --- a/tests/template_tests/filter_tests/test_timeuntil.py +++ b/tests/template_tests/filter_tests/test_timeuntil.py @@ -25,7 +25,9 @@ class TimeuntilTests(TimezoneTestCase): @setup({'timeuntil03': '{{ a|timeuntil }}'}) def test_timeuntil03(self): - output = self.engine.render_to_string('timeuntil03', {'a': (datetime.now() + timedelta(hours=8, minutes=10, seconds=10))}) + output = self.engine.render_to_string( + 'timeuntil03', {'a': (datetime.now() + timedelta(hours=8, minutes=10, seconds=10))} + ) self.assertEqual(output, '8\xa0hours, 10\xa0minutes') # Compare to a given parameter @@ -53,7 +55,9 @@ class TimeuntilTests(TimezoneTestCase): @setup({'timeuntil07': '{{ earlier|timeuntil:now }}'}) def test_timeuntil07(self): - output = self.engine.render_to_string('timeuntil07', {'now': self.now, 'earlier': self.now - timedelta(days=7)}) + output = self.engine.render_to_string( + 'timeuntil07', {'now': self.now, 'earlier': self.now - timedelta(days=7)} + ) self.assertEqual(output, '0\xa0minutes') @setup({'timeuntil08': '{{ later|timeuntil }}'}) diff --git a/tests/template_tests/filter_tests/test_truncatewords.py b/tests/template_tests/filter_tests/test_truncatewords.py index 97b6013bb1..4941e736fd 100644 --- a/tests/template_tests/filter_tests/test_truncatewords.py +++ b/tests/template_tests/filter_tests/test_truncatewords.py @@ -7,15 +7,20 @@ from ..utils import setup class TruncatewordsTests(SimpleTestCase): - @setup({'truncatewords01': - '{% autoescape off %}{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}{% endautoescape %}'}) + @setup({ + 'truncatewords01': '{% autoescape off %}{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}{% endautoescape %}' + }) def test_truncatewords01(self): - output = self.engine.render_to_string('truncatewords01', {'a': 'alpha & bravo', 'b': mark_safe('alpha & bravo')}) + output = self.engine.render_to_string( + 'truncatewords01', {'a': 'alpha & bravo', 'b': mark_safe('alpha & bravo')} + ) self.assertEqual(output, 'alpha & ... alpha & ...') @setup({'truncatewords02': '{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}'}) def test_truncatewords02(self): - output = self.engine.render_to_string('truncatewords02', {'a': 'alpha & bravo', 'b': mark_safe('alpha & bravo')}) + output = self.engine.render_to_string( + 'truncatewords02', {'a': 'alpha & bravo', 'b': mark_safe('alpha & bravo')} + ) self.assertEqual(output, 'alpha & ... alpha & ...') diff --git a/tests/template_tests/filter_tests/test_urlize.py b/tests/template_tests/filter_tests/test_urlize.py index 1d14778905..81451f2d4e 100644 --- a/tests/template_tests/filter_tests/test_urlize.py +++ b/tests/template_tests/filter_tests/test_urlize.py @@ -340,7 +340,7 @@ class FunctionTests(SimpleTestCase): def test_autoescape(self): self.assertEqual( urlize('foo<a href=" google.com ">bar</a>buz'), - 'foo<a href=" <a href="http://google.com" rel="nofollow">google.com</a> ">bar</a>buz', + 'foo<a href=" <a href="http://google.com" rel="nofollow">google.com</a> ">bar</a>buz' ) def test_autoescape_off(self): diff --git a/tests/template_tests/filter_tests/test_urlizetrunc.py b/tests/template_tests/filter_tests/test_urlizetrunc.py index cb5c2a6daf..4badf44029 100644 --- a/tests/template_tests/filter_tests/test_urlizetrunc.py +++ b/tests/template_tests/filter_tests/test_urlizetrunc.py @@ -82,7 +82,7 @@ class FunctionTests(SimpleTestCase): def test_autoescape(self): self.assertEqual( urlizetrunc('foo<a href=" google.com ">bar</a>buz', 10), - 'foo<a href=" <a href="http://google.com" rel="nofollow">google.com</a> ">bar</a>buz', + 'foo<a href=" <a href="http://google.com" rel="nofollow">google.com</a> ">bar</a>buz' ) def test_autoescape_off(self): diff --git a/tests/template_tests/syntax_tests/test_extends.py b/tests/template_tests/syntax_tests/test_extends.py index 46600cb76c..bc320a2fc2 100644 --- a/tests/template_tests/syntax_tests/test_extends.py +++ b/tests/template_tests/syntax_tests/test_extends.py @@ -251,7 +251,9 @@ class InheritanceTests(SimpleTestCase): """ Inheritance from local context without use of template loader """ - context_template = self.engine.from_string("1{% block first %}_{% endblock %}3{% block second %}_{% endblock %}") + context_template = self.engine.from_string( + "1{% block first %}_{% endblock %}3{% block second %}_{% endblock %}" + ) output = self.engine.render_to_string('inheritance24', {'context_template': context_template}) self.assertEqual(output, '1234') diff --git a/tests/template_tests/syntax_tests/test_for.py b/tests/template_tests/syntax_tests/test_for.py index 32fc5f0e3e..f3d571cff1 100644 --- a/tests/template_tests/syntax_tests/test_for.py +++ b/tests/template_tests/syntax_tests/test_for.py @@ -95,7 +95,9 @@ class ForTagTests(SimpleTestCase): @setup({'for-tag-unpack13': '{% for x,y,z in items %}{{ x }}:{{ y }},{{ z }}/{% endfor %}'}) def test_for_tag_unpack13(self): - output = self.engine.render_to_string('for-tag-unpack13', {'items': (('one', 1, 'carrot'), ('two', 2, 'cheese'))}) + output = self.engine.render_to_string( + 'for-tag-unpack13', {'items': (('one', 1, 'carrot'), ('two', 2, 'cheese'))} + ) if self.engine.string_if_invalid: self.assertEqual(output, 'one:1,carrot/two:2,cheese/') else: diff --git a/tests/template_tests/syntax_tests/test_if_changed.py b/tests/template_tests/syntax_tests/test_if_changed.py index ee67c64218..bf8a95d8a4 100644 --- a/tests/template_tests/syntax_tests/test_if_changed.py +++ b/tests/template_tests/syntax_tests/test_if_changed.py @@ -182,7 +182,9 @@ class IfChangedTests(SimpleTestCase): # When the IfChangeNode stores state at 'self' it stays at '3' and skip the last yielded value below. iter2 = iter([1, 2, 3]) output2 = template.render(Context({'foo': range(3), 'get_value': lambda: next(iter2)})) - self.assertEqual(output2, '[0,1,2,3]', 'Expected [0,1,2,3] in second parallel template, got {}'.format(output2)) + self.assertEqual( + output2, '[0,1,2,3]', 'Expected [0,1,2,3] in second parallel template, got {}'.format(output2) + ) yield 3 gen1 = gen() diff --git a/tests/template_tests/syntax_tests/test_url.py b/tests/template_tests/syntax_tests/test_url.py index bd1ea885d0..0877a316f1 100644 --- a/tests/template_tests/syntax_tests/test_url.py +++ b/tests/template_tests/syntax_tests/test_url.py @@ -127,7 +127,9 @@ class UrlTagTests(SimpleTestCase): @ignore_warnings(category=RemovedInDjango110Warning) @setup({'url19': '{% url named_url client.id %}'}) def test_url19(self): - output = self.engine.render_to_string('url19', {'client': {'id': 1}, 'named_url': 'template_tests.views.client'}) + output = self.engine.render_to_string( + 'url19', {'client': {'id': 1}, 'named_url': 'template_tests.views.client'} + ) self.assertEqual(output, '/client/1/') @setup({'url20': '{% url url_name_in_var client.id %}'}) diff --git a/tests/template_tests/templatetags/custom.py b/tests/template_tests/templatetags/custom.py index 9d47ca4201..ea1d7c6e67 100644 --- a/tests/template_tests/templatetags/custom.py +++ b/tests/template_tests/templatetags/custom.py @@ -80,7 +80,9 @@ simple_one_default.anything = "Expected simple_one_default __dict__" @register.simple_tag def simple_unlimited_args(one, two='hi', *args): """Expected simple_unlimited_args __doc__""" - return "simple_unlimited_args - Expected result: %s" % (', '.join(six.text_type(arg) for arg in [one, two] + list(args))) + return "simple_unlimited_args - Expected result: %s" % ( + ', '.join(six.text_type(arg) for arg in [one, two] + list(args)) + ) simple_unlimited_args.anything = "Expected simple_unlimited_args __dict__" diff --git a/tests/template_tests/templatetags/inclusion.py b/tests/template_tests/templatetags/inclusion.py index 54cc81abe3..185cdb1917 100644 --- a/tests/template_tests/templatetags/inclusion.py +++ b/tests/template_tests/templatetags/inclusion.py @@ -59,21 +59,34 @@ inclusion_no_params_with_context.anything = "Expected inclusion_no_params_with_c @register.inclusion_tag(engine.get_template('inclusion.html'), takes_context=True) def inclusion_no_params_with_context_from_template(context): """Expected inclusion_no_params_with_context_from_template __doc__""" - return {"result": "inclusion_no_params_with_context_from_template - Expected result (context value: %s)" % context['value']} -inclusion_no_params_with_context_from_template.anything = "Expected inclusion_no_params_with_context_from_template __dict__" + return { + "result": ( + "inclusion_no_params_with_context_from_template - Expected result (context value: %s)" % context['value'] + ) + } +inclusion_no_params_with_context_from_template.anything = ( + "Expected inclusion_no_params_with_context_from_template __dict__" +) @register.inclusion_tag('inclusion.html', takes_context=True) def inclusion_params_and_context(context, arg): """Expected inclusion_params_and_context __doc__""" - return {"result": "inclusion_params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)} + return { + "result": "inclusion_params_and_context - Expected result (context value: %s): %s" % (context['value'], arg) + } inclusion_params_and_context.anything = "Expected inclusion_params_and_context __dict__" @register.inclusion_tag(engine.get_template('inclusion.html'), takes_context=True) def inclusion_params_and_context_from_template(context, arg): """Expected inclusion_params_and_context_from_template __doc__""" - return {"result": "inclusion_params_and_context_from_template - Expected result (context value: %s): %s" % (context['value'], arg)} + return { + "result": ( + "inclusion_params_and_context_from_template - Expected result " + "(context value: %s): %s" % (context['value'], arg) + ) + } inclusion_params_and_context_from_template.anything = "Expected inclusion_params_and_context_from_template __dict__" @@ -108,28 +121,48 @@ inclusion_one_default_from_template.anything = "Expected inclusion_one_default_f @register.inclusion_tag('inclusion.html') def inclusion_unlimited_args(one, two='hi', *args): """Expected inclusion_unlimited_args __doc__""" - return {"result": "inclusion_unlimited_args - Expected result: %s" % (', '.join(six.text_type(arg) for arg in [one, two] + list(args)))} + return { + "result": ( + "inclusion_unlimited_args - Expected result: %s" % ( + ', '.join(six.text_type(arg) for arg in [one, two] + list(args)) + ) + ) + } inclusion_unlimited_args.anything = "Expected inclusion_unlimited_args __dict__" @register.inclusion_tag(engine.get_template('inclusion.html')) def inclusion_unlimited_args_from_template(one, two='hi', *args): """Expected inclusion_unlimited_args_from_template __doc__""" - return {"result": "inclusion_unlimited_args_from_template - Expected result: %s" % (', '.join(six.text_type(arg) for arg in [one, two] + list(args)))} + return { + "result": ( + "inclusion_unlimited_args_from_template - Expected result: %s" % ( + ', '.join(six.text_type(arg) for arg in [one, two] + list(args)) + ) + ) + } inclusion_unlimited_args_from_template.anything = "Expected inclusion_unlimited_args_from_template __dict__" @register.inclusion_tag('inclusion.html') def inclusion_only_unlimited_args(*args): """Expected inclusion_only_unlimited_args __doc__""" - return {"result": "inclusion_only_unlimited_args - Expected result: %s" % (', '.join(six.text_type(arg) for arg in args))} + return { + "result": "inclusion_only_unlimited_args - Expected result: %s" % ( + ', '.join(six.text_type(arg) for arg in args) + ) + } inclusion_only_unlimited_args.anything = "Expected inclusion_only_unlimited_args __dict__" @register.inclusion_tag(engine.get_template('inclusion.html')) def inclusion_only_unlimited_args_from_template(*args): """Expected inclusion_only_unlimited_args_from_template __doc__""" - return {"result": "inclusion_only_unlimited_args_from_template - Expected result: %s" % (', '.join(six.text_type(arg) for arg in args))} + return { + "result": "inclusion_only_unlimited_args_from_template - Expected result: %s" % ( + ', '.join(six.text_type(arg) for arg in args) + ) + } inclusion_only_unlimited_args_from_template.anything = "Expected inclusion_only_unlimited_args_from_template __dict__" diff --git a/tests/template_tests/test_custom.py b/tests/template_tests/test_custom.py index dec97589d6..1b63953860 100644 --- a/tests/template_tests/test_custom.py +++ b/tests/template_tests/test_custom.py @@ -162,7 +162,10 @@ class InclusionTagTests(TagTestCase): 'inclusion_params_and_context - Expected result (context value: 42): 37\n'), ('{% load inclusion %}{% inclusion_two_params 37 42 %}', 'inclusion_two_params - Expected result: 37, 42\n'), - ('{% load inclusion %}{% inclusion_one_default 37 %}', 'inclusion_one_default - Expected result: 37, hi\n'), + ( + '{% load inclusion %}{% inclusion_one_default 37 %}', + 'inclusion_one_default - Expected result: 37, hi\n' + ), ('{% load inclusion %}{% inclusion_one_default 37 two="hello" %}', 'inclusion_one_default - Expected result: 37, hello\n'), ('{% load inclusion %}{% inclusion_one_default one=99 two="hello" %}', diff --git a/tests/template_tests/test_extends.py b/tests/template_tests/test_extends.py index 03a674e25b..7a9008cf54 100644 --- a/tests/template_tests/test_extends.py +++ b/tests/template_tests/test_extends.py @@ -42,16 +42,19 @@ class ExtendsBehaviorTests(SimpleTestCase): def test_recursive_multiple_loaders(self): engine = Engine( dirs=[os.path.join(RECURSIVE, 'fs')], - loaders=[ - ('django.template.loaders.locmem.Loader', { - 'one.html': '{% extends "one.html" %}{% block content %}{{ block.super }} locmem-one{% endblock %}', - 'two.html': '{% extends "two.html" %}{% block content %}{{ block.super }} locmem-two{% endblock %}', + loaders=[( + 'django.template.loaders.locmem.Loader', { + 'one.html': ( + '{% extends "one.html" %}{% block content %}{{ block.super }} locmem-one{% endblock %}' + ), + 'two.html': ( + '{% extends "two.html" %}{% block content %}{{ block.super }} locmem-two{% endblock %}' + ), 'three.html': ( '{% extends "three.html" %}{% block content %}{{ block.super }} locmem-three{% endblock %}' ), - }), - 'django.template.loaders.filesystem.Loader', - ], + } + ), 'django.template.loaders.filesystem.Loader'], ) template = engine.get_template('one.html') output = template.render(Context({})) diff --git a/tests/template_tests/test_nodelist.py b/tests/template_tests/test_nodelist.py index 46b48404dd..042702e3c0 100644 --- a/tests/template_tests/test_nodelist.py +++ b/tests/template_tests/test_nodelist.py @@ -56,9 +56,21 @@ class ErrorIndexTest(TestCase): def test_correct_exception_index(self): tests = [ ('{% load bad_tag %}{% for i in range %}{% badsimpletag %}{% endfor %}', (38, 56)), - ('{% load bad_tag %}{% for i in range %}{% for j in range %}{% badsimpletag %}{% endfor %}{% endfor %}', (58, 76)), - ('{% load bad_tag %}{% for i in range %}{% badsimpletag %}{% for j in range %}Hello{% endfor %}{% endfor %}', (38, 56)), - ('{% load bad_tag %}{% for i in range %}{% for j in five %}{% badsimpletag %}{% endfor %}{% endfor %}', (38, 57)), + ( + '{% load bad_tag %}{% for i in range %}{% for j in range %}' + '{% badsimpletag %}{% endfor %}{% endfor %}', + (58, 76) + ), + ( + '{% load bad_tag %}{% for i in range %}{% badsimpletag %}' + '{% for j in range %}Hello{% endfor %}{% endfor %}', + (38, 56) + ), + ( + '{% load bad_tag %}{% for i in range %}{% for j in five %}' + '{% badsimpletag %}{% endfor %}{% endfor %}', + (38, 57) + ), ('{% load bad_tag %}{% for j in five %}{% badsimpletag %}{% endfor %}', (18, 37)), ] context = Context({ |
