diff options
| author | django-bot <ops@djangoproject.com> | 2022-02-03 20:24:19 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-07 20:37:05 +0100 |
| commit | 9c19aff7c7561e3a82978a272ecdaad40dda5c00 (patch) | |
| tree | f0506b668a013d0063e5fba3dbf4863b466713ba /tests/utils_tests/test_safestring.py | |
| parent | f68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff) | |
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'tests/utils_tests/test_safestring.py')
| -rw-r--r-- | tests/utils_tests/test_safestring.py | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/tests/utils_tests/test_safestring.py b/tests/utils_tests/test_safestring.py index 80f31d42ac..d7805662f1 100644 --- a/tests/utils_tests/test_safestring.py +++ b/tests/utils_tests/test_safestring.py @@ -9,7 +9,7 @@ class customescape(str): def __html__(self): # Implement specific and wrong escaping in order to be able to detect # when it runs. - return self.replace('<', '<<').replace('>', '>>') + return self.replace("<", "<<").replace(">", ">>") class SafeStringTest(SimpleTestCase): @@ -19,63 +19,64 @@ class SafeStringTest(SimpleTestCase): self.assertEqual(tpl.render(context), expected) def test_mark_safe(self): - s = mark_safe('a&b') + s = mark_safe("a&b") - self.assertRenderEqual('{{ s }}', 'a&b', s=s) - self.assertRenderEqual('{{ s|force_escape }}', 'a&b', s=s) + self.assertRenderEqual("{{ s }}", "a&b", s=s) + self.assertRenderEqual("{{ s|force_escape }}", "a&b", s=s) def test_mark_safe_str(self): """ Calling str() on a SafeString instance doesn't lose the safe status. """ - s = mark_safe('a&b') + s = mark_safe("a&b") self.assertIsInstance(str(s), type(s)) def test_mark_safe_object_implementing_dunder_html(self): - e = customescape('<a&b>') + e = customescape("<a&b>") s = mark_safe(e) self.assertIs(s, e) - self.assertRenderEqual('{{ s }}', '<<a&b>>', s=s) - self.assertRenderEqual('{{ s|force_escape }}', '<a&b>', s=s) + self.assertRenderEqual("{{ s }}", "<<a&b>>", s=s) + self.assertRenderEqual("{{ s|force_escape }}", "<a&b>", s=s) def test_mark_safe_lazy(self): - s = lazystr('a&b') + s = lazystr("a&b") self.assertIsInstance(mark_safe(s), SafeData) - self.assertRenderEqual('{{ s }}', 'a&b', s=mark_safe(s)) + self.assertRenderEqual("{{ s }}", "a&b", s=mark_safe(s)) def test_mark_safe_object_implementing_dunder_str(self): class Obj: def __str__(self): - return '<obj>' + return "<obj>" s = mark_safe(Obj()) - self.assertRenderEqual('{{ s }}', '<obj>', s=s) + self.assertRenderEqual("{{ s }}", "<obj>", s=s) def test_mark_safe_result_implements_dunder_html(self): - self.assertEqual(mark_safe('a&b').__html__(), 'a&b') + self.assertEqual(mark_safe("a&b").__html__(), "a&b") def test_mark_safe_lazy_result_implements_dunder_html(self): - self.assertEqual(mark_safe(lazystr('a&b')).__html__(), 'a&b') + self.assertEqual(mark_safe(lazystr("a&b")).__html__(), "a&b") def test_add_lazy_safe_text_and_safe_text(self): - s = html.escape(lazystr('a')) - s += mark_safe('&b') - self.assertRenderEqual('{{ s }}', 'a&b', s=s) + s = html.escape(lazystr("a")) + s += mark_safe("&b") + self.assertRenderEqual("{{ s }}", "a&b", s=s) - s = html.escapejs(lazystr('a')) - s += mark_safe('&b') - self.assertRenderEqual('{{ s }}', 'a&b', s=s) + s = html.escapejs(lazystr("a")) + s += mark_safe("&b") + self.assertRenderEqual("{{ s }}", "a&b", s=s) def test_mark_safe_as_decorator(self): """ mark_safe used as a decorator leaves the result of a function unchanged. """ + def clean_string_provider(): - return '<html><body>dummy</body></html>' + return "<html><body>dummy</body></html>" self.assertEqual(mark_safe(clean_string_provider)(), clean_string_provider()) @@ -83,9 +84,10 @@ class SafeStringTest(SimpleTestCase): """ mark_safe doesn't affect a callable that has an __html__() method. """ + class SafeStringContainer: def __html__(self): - return '<html></html>' + return "<html></html>" self.assertIs(mark_safe(SafeStringContainer), SafeStringContainer) @@ -93,14 +95,15 @@ class SafeStringTest(SimpleTestCase): """ mark_safe doesn't affect lazy strings (Promise objects). """ + def html_str(): - return '<html></html>' + return "<html></html>" lazy_str = lazy(html_str, str)() self.assertEqual(mark_safe(lazy_str), html_str()) def test_default_additional_attrs(self): - s = SafeString('a&b') + s = SafeString("a&b") msg = "object has no attribute 'dynamic_attr'" with self.assertRaisesMessage(AttributeError, msg): s.dynamic_attr = True |
