2018-07-31 13:57:11 +00:00
|
|
|
from django.template import Context, Template, Variable, VariableDoesNotExist
|
2017-01-26 20:10:15 +00:00
|
|
|
from django.test import SimpleTestCase
|
2018-07-31 13:57:11 +00:00
|
|
|
from django.utils.translation import gettext_lazy
|
|
|
|
|
|
|
|
|
|
|
|
class TemplateTests(SimpleTestCase):
|
|
|
|
def test_lazy_template_string(self):
|
|
|
|
template_string = gettext_lazy('lazy string')
|
|
|
|
self.assertEqual(Template(template_string).render(Context()), template_string)
|
2017-01-26 20:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VariableDoesNotExistTests(SimpleTestCase):
|
|
|
|
def test_str(self):
|
|
|
|
exc = VariableDoesNotExist(msg='Failed lookup in %r', params=({'foo': 'bar'},))
|
|
|
|
self.assertEqual(str(exc), "Failed lookup in {'foo': 'bar'}")
|
2017-10-21 10:24:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VariableTests(SimpleTestCase):
|
|
|
|
def test_integer_literals(self):
|
|
|
|
self.assertEqual(Variable('999999999999999999999999999').literal, 999999999999999999999999999)
|
2017-10-22 00:55:26 +00:00
|
|
|
|
|
|
|
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 var_names:
|
|
|
|
with self.subTest(var=var):
|
|
|
|
self.assertIsNone(Variable(var).literal)
|