summaryrefslogtreecommitdiff
path: root/tests/template_tests/tests.py
diff options
context:
space:
mode:
authordjango-bot <ops@djangoproject.com>2022-02-03 20:24:19 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-02-07 20:37:05 +0100
commit9c19aff7c7561e3a82978a272ecdaad40dda5c00 (patch)
treef0506b668a013d0063e5fba3dbf4863b466713ba /tests/template_tests/tests.py
parentf68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff)
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'tests/template_tests/tests.py')
-rw-r--r--tests/template_tests/tests.py57
1 files changed, 29 insertions, 28 deletions
diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py
index 33837114c6..b849b4a2e7 100644
--- a/tests/template_tests/tests.py
+++ b/tests/template_tests/tests.py
@@ -1,8 +1,6 @@
import sys
-from django.template import (
- Context, Engine, TemplateDoesNotExist, TemplateSyntaxError,
-)
+from django.template import Context, Engine, TemplateDoesNotExist, TemplateSyntaxError
from django.template.base import UNKNOWN_SOURCE
from django.test import SimpleTestCase, override_settings
from django.urls import NoReverseMatch
@@ -15,10 +13,10 @@ class TemplateTestMixin:
return Engine(debug=self.debug_engine, **kwargs)
def test_string_origin(self):
- template = self._engine().from_string('string template')
+ template = self._engine().from_string("string template")
self.assertEqual(template.origin.name, UNKNOWN_SOURCE)
self.assertIsNone(template.origin.loader_name)
- self.assertEqual(template.source, 'string template')
+ self.assertEqual(template.source, "string template")
@override_settings(SETTINGS_MODULE=None)
def test_url_reverse_no_settings_module(self):
@@ -26,7 +24,7 @@ class TemplateTestMixin:
#9005 -- url tag shouldn't require settings.SETTINGS_MODULE to
be set.
"""
- t = self._engine().from_string('{% url will_not_match %}')
+ t = self._engine().from_string("{% url will_not_match %}")
c = Context()
with self.assertRaises(NoReverseMatch):
t.render(c)
@@ -36,7 +34,7 @@ class TemplateTestMixin:
#19827 -- url tag should keep original strack trace when reraising
exception.
"""
- t = self._engine().from_string('{% url will_not_match %}')
+ t = self._engine().from_string("{% url will_not_match %}")
c = Context()
try:
t.render(c)
@@ -46,7 +44,9 @@ class TemplateTestMixin:
while tb.tb_next is not None:
tb = tb.tb_next
depth += 1
- self.assertGreater(depth, 5, "The traceback context was lost when reraising the traceback.")
+ self.assertGreater(
+ depth, 5, "The traceback context was lost when reraising the traceback."
+ )
def test_no_wrapped_exception(self):
"""
@@ -62,8 +62,8 @@ class TemplateTestMixin:
if self.debug_engine:
debug = e.exception.template_debug
- self.assertEqual(debug['start'], 0)
- self.assertEqual(debug['end'], 14)
+ self.assertEqual(debug["start"], 0)
+ self.assertEqual(debug["end"], 14)
def test_invalid_block_suggestion(self):
"""
@@ -75,7 +75,7 @@ class TemplateTestMixin:
"Invalid block tag on line 1: 'endblock', expected 'elif', 'else' "
"or 'endif'. Did you forget to register or load this tag?"
)
- with self.settings(USE_I18N=True), translation.override('de'):
+ with self.settings(USE_I18N=True), translation.override("de"):
with self.assertRaisesMessage(TemplateSyntaxError, msg):
engine.from_string("{% if 1 %}lala{% endblock %}{% endif %}")
@@ -101,8 +101,8 @@ class TemplateTestMixin:
if self.debug_engine:
debug = e.exception.template_debug
- self.assertEqual((debug['start'], debug['end']), (10, 23))
- self.assertEqual((debug['during']), '{{ foo@bar }}')
+ self.assertEqual((debug["start"], debug["end"]), (10, 23))
+ self.assertEqual((debug["during"]), "{{ foo@bar }}")
def test_compile_tag_error(self):
"""
@@ -110,46 +110,46 @@ class TemplateTestMixin:
information.
"""
engine = self._engine(
- libraries={'bad_tag': 'template_tests.templatetags.bad_tag'},
+ libraries={"bad_tag": "template_tests.templatetags.bad_tag"},
)
with self.assertRaises(RuntimeError) as e:
engine.from_string("{% load bad_tag %}{% badtag %}")
if self.debug_engine:
- self.assertEqual(e.exception.template_debug['during'], '{% badtag %}')
+ self.assertEqual(e.exception.template_debug["during"], "{% badtag %}")
def test_compile_tag_error_27584(self):
engine = self._engine(
app_dirs=True,
- libraries={'tag_27584': 'template_tests.templatetags.tag_27584'},
+ libraries={"tag_27584": "template_tests.templatetags.tag_27584"},
)
- t = engine.get_template('27584_parent.html')
+ t = engine.get_template("27584_parent.html")
with self.assertRaises(TemplateSyntaxError) as e:
t.render(Context())
if self.debug_engine:
- self.assertEqual(e.exception.template_debug['during'], '{% badtag %}')
+ self.assertEqual(e.exception.template_debug["during"], "{% badtag %}")
def test_compile_tag_error_27956(self):
"""Errors in a child of {% extends %} are displayed correctly."""
engine = self._engine(
app_dirs=True,
- libraries={'tag_27584': 'template_tests.templatetags.tag_27584'},
+ libraries={"tag_27584": "template_tests.templatetags.tag_27584"},
)
- t = engine.get_template('27956_child.html')
+ t = engine.get_template("27956_child.html")
with self.assertRaises(TemplateSyntaxError) as e:
t.render(Context())
if self.debug_engine:
- self.assertEqual(e.exception.template_debug['during'], '{% badtag %}')
+ self.assertEqual(e.exception.template_debug["during"], "{% badtag %}")
def test_render_tag_error_in_extended_block(self):
"""Errors in extended block are displayed correctly."""
e = self._engine(app_dirs=True)
- template = e.get_template('test_extends_block_error.html')
+ template = e.get_template("test_extends_block_error.html")
context = Context()
with self.assertRaises(TemplateDoesNotExist) as cm:
template.render(context)
if self.debug_engine:
self.assertEqual(
- cm.exception.template_debug['during'],
+ cm.exception.template_debug["during"],
escape('{% include "missing.html" %}'),
)
@@ -158,7 +158,7 @@ class TemplateTestMixin:
#18169 -- NoReverseMatch should not be silence in block.super.
"""
engine = self._engine(app_dirs=True)
- t = engine.get_template('included_content.html')
+ t = engine.get_template("included_content.html")
with self.assertRaises(NoReverseMatch):
t.render(Context())
@@ -168,17 +168,18 @@ class TemplateTestMixin:
objects.
"""
engine = self._engine()
- parent = engine.from_string('{% block content %}parent{% endblock %}')
+ parent = engine.from_string("{% block content %}parent{% endblock %}")
child = engine.from_string(
- '{% extends parent %}{% block content %}child{% endblock %}')
- self.assertEqual(child.render(Context({'parent': parent})), 'child')
+ "{% extends parent %}{% block content %}child{% endblock %}"
+ )
+ self.assertEqual(child.render(Context({"parent": parent})), "child")
def test_node_origin(self):
"""
#25848 -- Set origin on Node so debugging tools can determine which
template the node came from even if extending or including templates.
"""
- template = self._engine().from_string('content')
+ template = self._engine().from_string("content")
for node in template.nodelist:
self.assertEqual(node.origin, template.origin)