diff options
| author | django-bot <ops@djangoproject.com> | 2022-02-08 12:09:55 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-08 12:15:38 +0100 |
| commit | 6a682b38e75d4c975b4c4493565a59f1bc14397c (patch) | |
| tree | 0bd9cda550bea26238656d9f120d769e8b41bb9e /tests/template_tests/syntax_tests/test_width_ratio.py | |
| parent | e73ce08888e6f34d3f050377cfd2fbb733be94a9 (diff) | |
[4.0.x] Refs #33476 -- Reformatted code with Black.
Backport of 9c19aff7c7561e3a82978a272ecdaad40dda5c00 from main.
Diffstat (limited to 'tests/template_tests/syntax_tests/test_width_ratio.py')
| -rw-r--r-- | tests/template_tests/syntax_tests/test_width_ratio.py | 160 |
1 files changed, 87 insertions, 73 deletions
diff --git a/tests/template_tests/syntax_tests/test_width_ratio.py b/tests/template_tests/syntax_tests/test_width_ratio.py index 7db90a44e1..3f3a072f96 100644 --- a/tests/template_tests/syntax_tests/test_width_ratio.py +++ b/tests/template_tests/syntax_tests/test_width_ratio.py @@ -5,150 +5,164 @@ from ..utils import setup class WidthRatioTagTests(SimpleTestCase): - libraries = {'custom': 'template_tests.templatetags.custom'} + libraries = {"custom": "template_tests.templatetags.custom"} - @setup({'widthratio01': '{% widthratio a b 0 %}'}) + @setup({"widthratio01": "{% widthratio a b 0 %}"}) def test_widthratio01(self): - output = self.engine.render_to_string('widthratio01', {'a': 50, 'b': 100}) - self.assertEqual(output, '0') + output = self.engine.render_to_string("widthratio01", {"a": 50, "b": 100}) + self.assertEqual(output, "0") - @setup({'widthratio02': '{% widthratio a b 100 %}'}) + @setup({"widthratio02": "{% widthratio a b 100 %}"}) def test_widthratio02(self): - output = self.engine.render_to_string('widthratio02', {'a': 0, 'b': 0}) - self.assertEqual(output, '0') + output = self.engine.render_to_string("widthratio02", {"a": 0, "b": 0}) + self.assertEqual(output, "0") - @setup({'widthratio03': '{% widthratio a b 100 %}'}) + @setup({"widthratio03": "{% widthratio a b 100 %}"}) def test_widthratio03(self): - output = self.engine.render_to_string('widthratio03', {'a': 0, 'b': 100}) - self.assertEqual(output, '0') + output = self.engine.render_to_string("widthratio03", {"a": 0, "b": 100}) + self.assertEqual(output, "0") - @setup({'widthratio04': '{% widthratio a b 100 %}'}) + @setup({"widthratio04": "{% widthratio a b 100 %}"}) def test_widthratio04(self): - output = self.engine.render_to_string('widthratio04', {'a': 50, 'b': 100}) - self.assertEqual(output, '50') + output = self.engine.render_to_string("widthratio04", {"a": 50, "b": 100}) + self.assertEqual(output, "50") - @setup({'widthratio05': '{% widthratio a b 100 %}'}) + @setup({"widthratio05": "{% widthratio a b 100 %}"}) def test_widthratio05(self): - output = self.engine.render_to_string('widthratio05', {'a': 100, 'b': 100}) - self.assertEqual(output, '100') + output = self.engine.render_to_string("widthratio05", {"a": 100, "b": 100}) + self.assertEqual(output, "100") - @setup({'widthratio06': '{% widthratio a b 100 %}'}) + @setup({"widthratio06": "{% widthratio a b 100 %}"}) def test_widthratio06(self): """ 62.5 should round to 62 """ - output = self.engine.render_to_string('widthratio06', {'a': 50, 'b': 80}) - self.assertEqual(output, '62') + output = self.engine.render_to_string("widthratio06", {"a": 50, "b": 80}) + self.assertEqual(output, "62") - @setup({'widthratio07': '{% widthratio a b 100 %}'}) + @setup({"widthratio07": "{% widthratio a b 100 %}"}) def test_widthratio07(self): """ 71.4 should round to 71 """ - output = self.engine.render_to_string('widthratio07', {'a': 50, 'b': 70}) - self.assertEqual(output, '71') + output = self.engine.render_to_string("widthratio07", {"a": 50, "b": 70}) + self.assertEqual(output, "71") # Raise exception if we don't have 3 args, last one an integer - @setup({'widthratio08': '{% widthratio %}'}) + @setup({"widthratio08": "{% widthratio %}"}) def test_widthratio08(self): with self.assertRaises(TemplateSyntaxError): - self.engine.get_template('widthratio08') + self.engine.get_template("widthratio08") - @setup({'widthratio09': '{% widthratio a b %}'}) + @setup({"widthratio09": "{% widthratio a b %}"}) def test_widthratio09(self): with self.assertRaises(TemplateSyntaxError): - self.engine.render_to_string('widthratio09', {'a': 50, 'b': 100}) + self.engine.render_to_string("widthratio09", {"a": 50, "b": 100}) - @setup({'widthratio10': '{% widthratio a b 100.0 %}'}) + @setup({"widthratio10": "{% widthratio a b 100.0 %}"}) def test_widthratio10(self): - output = self.engine.render_to_string('widthratio10', {'a': 50, 'b': 100}) - self.assertEqual(output, '50') + output = self.engine.render_to_string("widthratio10", {"a": 50, "b": 100}) + self.assertEqual(output, "50") - @setup({'widthratio11': '{% widthratio a b c %}'}) + @setup({"widthratio11": "{% widthratio a b c %}"}) def test_widthratio11(self): """ #10043: widthratio should allow max_width to be a variable """ - output = self.engine.render_to_string('widthratio11', {'a': 50, 'c': 100, 'b': 100}) - self.assertEqual(output, '50') + output = self.engine.render_to_string( + "widthratio11", {"a": 50, "c": 100, "b": 100} + ) + self.assertEqual(output, "50") # #18739: widthratio should handle None args consistently with # non-numerics - @setup({'widthratio12a': '{% widthratio a b c %}'}) + @setup({"widthratio12a": "{% widthratio a b c %}"}) def test_widthratio12a(self): - output = self.engine.render_to_string('widthratio12a', {'a': 'a', 'c': 100, 'b': 100}) - self.assertEqual(output, '') + output = self.engine.render_to_string( + "widthratio12a", {"a": "a", "c": 100, "b": 100} + ) + self.assertEqual(output, "") - @setup({'widthratio12b': '{% widthratio a b c %}'}) + @setup({"widthratio12b": "{% widthratio a b c %}"}) def test_widthratio12b(self): - output = self.engine.render_to_string('widthratio12b', {'a': None, 'c': 100, 'b': 100}) - self.assertEqual(output, '') + output = self.engine.render_to_string( + "widthratio12b", {"a": None, "c": 100, "b": 100} + ) + self.assertEqual(output, "") - @setup({'widthratio13a': '{% widthratio a b c %}'}) + @setup({"widthratio13a": "{% widthratio a b c %}"}) def test_widthratio13a(self): - output = self.engine.render_to_string('widthratio13a', {'a': 0, 'c': 100, 'b': 'b'}) - self.assertEqual(output, '') + output = self.engine.render_to_string( + "widthratio13a", {"a": 0, "c": 100, "b": "b"} + ) + self.assertEqual(output, "") - @setup({'widthratio13b': '{% widthratio a b c %}'}) + @setup({"widthratio13b": "{% widthratio a b c %}"}) def test_widthratio13b(self): - output = self.engine.render_to_string('widthratio13b', {'a': 0, 'c': 100, 'b': None}) - self.assertEqual(output, '') + output = self.engine.render_to_string( + "widthratio13b", {"a": 0, "c": 100, "b": None} + ) + self.assertEqual(output, "") - @setup({'widthratio14a': '{% widthratio a b c %}'}) + @setup({"widthratio14a": "{% widthratio a b c %}"}) def test_widthratio14a(self): with self.assertRaises(TemplateSyntaxError): - self.engine.render_to_string('widthratio14a', {'a': 0, 'c': 'c', 'b': 100}) + self.engine.render_to_string("widthratio14a", {"a": 0, "c": "c", "b": 100}) - @setup({'widthratio14b': '{% widthratio a b c %}'}) + @setup({"widthratio14b": "{% widthratio a b c %}"}) def test_widthratio14b(self): with self.assertRaises(TemplateSyntaxError): - self.engine.render_to_string('widthratio14b', {'a': 0, 'c': None, 'b': 100}) + self.engine.render_to_string("widthratio14b", {"a": 0, "c": None, "b": 100}) - @setup({'widthratio15': '{% load custom %}{% widthratio a|noop:"x y" b 0 %}'}) + @setup({"widthratio15": '{% load custom %}{% widthratio a|noop:"x y" b 0 %}'}) def test_widthratio15(self): """ Test whitespace in filter argument """ - output = self.engine.render_to_string('widthratio15', {'a': 50, 'b': 100}) - self.assertEqual(output, '0') + output = self.engine.render_to_string("widthratio15", {"a": 50, "b": 100}) + self.assertEqual(output, "0") # Widthratio with variable assignment - @setup({'widthratio16': '{% widthratio a b 100 as variable %}-{{ variable }}-'}) + @setup({"widthratio16": "{% widthratio a b 100 as variable %}-{{ variable }}-"}) def test_widthratio16(self): - output = self.engine.render_to_string('widthratio16', {'a': 50, 'b': 100}) - self.assertEqual(output, '-50-') + output = self.engine.render_to_string("widthratio16", {"a": 50, "b": 100}) + self.assertEqual(output, "-50-") - @setup({'widthratio17': '{% widthratio a b 100 as variable %}-{{ variable }}-'}) + @setup({"widthratio17": "{% widthratio a b 100 as variable %}-{{ variable }}-"}) def test_widthratio17(self): - output = self.engine.render_to_string('widthratio17', {'a': 100, 'b': 100}) - self.assertEqual(output, '-100-') + output = self.engine.render_to_string("widthratio17", {"a": 100, "b": 100}) + self.assertEqual(output, "-100-") - @setup({'widthratio18': '{% widthratio a b 100 as %}'}) + @setup({"widthratio18": "{% widthratio a b 100 as %}"}) def test_widthratio18(self): with self.assertRaises(TemplateSyntaxError): - self.engine.get_template('widthratio18') + self.engine.get_template("widthratio18") - @setup({'widthratio19': '{% widthratio a b 100 not_as variable %}'}) + @setup({"widthratio19": "{% widthratio a b 100 not_as variable %}"}) def test_widthratio19(self): with self.assertRaises(TemplateSyntaxError): - self.engine.get_template('widthratio19') + self.engine.get_template("widthratio19") - @setup({'widthratio20': '{% widthratio a b 100 %}'}) + @setup({"widthratio20": "{% widthratio a b 100 %}"}) def test_widthratio20(self): - output = self.engine.render_to_string('widthratio20', {'a': float('inf'), 'b': float('inf')}) - self.assertEqual(output, '') + output = self.engine.render_to_string( + "widthratio20", {"a": float("inf"), "b": float("inf")} + ) + self.assertEqual(output, "") - @setup({'widthratio21': '{% widthratio a b 100 %}'}) + @setup({"widthratio21": "{% widthratio a b 100 %}"}) def test_widthratio21(self): - output = self.engine.render_to_string('widthratio21', {'a': float('inf'), 'b': 2}) - self.assertEqual(output, '') + output = self.engine.render_to_string( + "widthratio21", {"a": float("inf"), "b": 2} + ) + self.assertEqual(output, "") - @setup({'t': '{% widthratio a b 100 as variable %}-{{ variable }}-'}) + @setup({"t": "{% widthratio a b 100 as variable %}-{{ variable }}-"}) def test_zerodivisionerror_as_var(self): - output = self.engine.render_to_string('t', {'a': 0, 'b': 0}) - self.assertEqual(output, '-0-') + output = self.engine.render_to_string("t", {"a": 0, "b": 0}) + self.assertEqual(output, "-0-") - @setup({'t': '{% widthratio a b c as variable %}-{{ variable }}-'}) + @setup({"t": "{% widthratio a b c as variable %}-{{ variable }}-"}) def test_typeerror_as_var(self): - output = self.engine.render_to_string('t', {'a': 'a', 'c': 100, 'b': 100}) - self.assertEqual(output, '--') + output = self.engine.render_to_string("t", {"a": "a", "c": 100, "b": 100}) + self.assertEqual(output, "--") |
