summaryrefslogtreecommitdiff
path: root/tests/template_tests/test_base.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/test_base.py
parentf68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff)
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'tests/template_tests/test_base.py')
-rw-r--r--tests/template_tests/test_base.py44
1 files changed, 24 insertions, 20 deletions
diff --git a/tests/template_tests/test_base.py b/tests/template_tests/test_base.py
index 64fc562626..7b85d1de80 100644
--- a/tests/template_tests/test_base.py
+++ b/tests/template_tests/test_base.py
@@ -6,28 +6,30 @@ from django.utils.translation import gettext_lazy
class LexerTestMixin:
template_string = (
- 'text\n'
- '{% if test %}{{ varvalue }}{% endif %}'
- '{#comment {{not a var}} %{not a block}% #}'
- 'end text'
+ "text\n"
+ "{% if test %}{{ varvalue }}{% endif %}"
+ "{#comment {{not a var}} %{not a block}% #}"
+ "end text"
)
expected_token_tuples = [
# (token_type, contents, lineno, position)
- (TokenType.TEXT, 'text\n', 1, (0, 5)),
- (TokenType.BLOCK, 'if test', 2, (5, 18)),
- (TokenType.VAR, 'varvalue', 2, (18, 32)),
- (TokenType.BLOCK, 'endif', 2, (32, 43)),
- (TokenType.COMMENT, 'comment {{not a var}} %{not a block}%', 2, (43, 85)),
- (TokenType.TEXT, 'end text', 2, (85, 93)),
+ (TokenType.TEXT, "text\n", 1, (0, 5)),
+ (TokenType.BLOCK, "if test", 2, (5, 18)),
+ (TokenType.VAR, "varvalue", 2, (18, 32)),
+ (TokenType.BLOCK, "endif", 2, (32, 43)),
+ (TokenType.COMMENT, "comment {{not a var}} %{not a block}%", 2, (43, 85)),
+ (TokenType.TEXT, "end text", 2, (85, 93)),
]
def test_tokenize(self):
tokens = self.lexer_class(self.template_string).tokenize()
- token_tuples = [(t.token_type, t.contents, t.lineno, t.position) for t in tokens]
+ token_tuples = [
+ (t.token_type, t.contents, t.lineno, t.position) for t in tokens
+ ]
self.assertEqual(token_tuples, self.make_expected())
def make_expected(self):
- raise NotImplementedError('This method must be implemented by a subclass.')
+ raise NotImplementedError("This method must be implemented by a subclass.")
class LexerTests(LexerTestMixin, SimpleTestCase):
@@ -47,14 +49,14 @@ class DebugLexerTests(LexerTestMixin, SimpleTestCase):
class TemplateTests(SimpleTestCase):
def test_lazy_template_string(self):
- template_string = gettext_lazy('lazy string')
+ template_string = gettext_lazy("lazy string")
self.assertEqual(Template(template_string).render(Context()), template_string)
def test_repr(self):
template = Template(
- '<html><body>\n'
- '{% if test %}<h1>{{ varvalue }}</h1>{% endif %}'
- '</body></html>'
+ "<html><body>\n"
+ "{% if test %}<h1>{{ varvalue }}</h1>{% endif %}"
+ "</body></html>"
)
self.assertEqual(
repr(template),
@@ -64,19 +66,21 @@ class TemplateTests(SimpleTestCase):
class VariableDoesNotExistTests(SimpleTestCase):
def test_str(self):
- exc = VariableDoesNotExist(msg='Failed lookup in %r', params=({'foo': 'bar'},))
+ exc = VariableDoesNotExist(msg="Failed lookup in %r", params=({"foo": "bar"},))
self.assertEqual(str(exc), "Failed lookup in {'foo': 'bar'}")
class VariableTests(SimpleTestCase):
def test_integer_literals(self):
- self.assertEqual(Variable('999999999999999999999999999').literal, 999999999999999999999999999)
+ self.assertEqual(
+ Variable("999999999999999999999999999").literal, 999999999999999999999999999
+ )
def test_nonliterals(self):
"""Variable names that aren't resolved as literals."""
var_names = []
- for var in ('inf', 'infinity', 'iNFiniTy', 'nan'):
- var_names.extend((var, '-' + var, '+' + var))
+ for var in ("inf", "infinity", "iNFiniTy", "nan"):
+ var_names.extend((var, "-" + var, "+" + var))
for var in var_names:
with self.subTest(var=var):
self.assertIsNone(Variable(var).literal)