summaryrefslogtreecommitdiff
path: root/tests/utils_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/utils_tests')
-rw-r--r--tests/utils_tests/test_autoreload.py11
-rw-r--r--tests/utils_tests/test_html.py27
-rw-r--r--tests/utils_tests/test_jslex.py7
-rw-r--r--tests/utils_tests/test_lazyobject.py3
-rw-r--r--tests/utils_tests/test_text.py9
5 files changed, 36 insertions, 21 deletions
diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py
index c50d141cf3..6fe7ae64fa 100644
--- a/tests/utils_tests/test_autoreload.py
+++ b/tests/utils_tests/test_autoreload.py
@@ -558,11 +558,12 @@ class ReloaderTests(SimpleTestCase):
def ensure_file(self, path):
path.parent.mkdir(exist_ok=True, parents=True)
path.touch()
- # On Linux and Windows updating the mtime of a file using touch() will set a timestamp
- # value that is in the past, as the time value for the last kernel tick is used rather
- # than getting the correct absolute time.
- # To make testing simpler set the mtime to be the observed time when this function is
- # called.
+ # On Linux and Windows updating the mtime of a file using touch() will
+ # set a timestamp value that is in the past, as the time value for the
+ # last kernel tick is used rather than getting the correct absolute
+ # time.
+ # To make testing simpler set the mtime to be the observed time when
+ # this function is called.
self.set_mtime(path, time.time())
return path.absolute()
diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py
index c38a16de40..dc86925e8d 100644
--- a/tests/utils_tests/test_html.py
+++ b/tests/utils_tests/test_html.py
@@ -183,24 +183,28 @@ class TestUtilsHtml(SimpleTestCase):
(
(
"&<>",
- '<script id="test_id" type="application/json">"\\u0026\\u003C\\u003E"</script>',
+ '<script id="test_id" type="application/json">'
+ '"\\u0026\\u003C\\u003E"</script>',
)
),
# "<", ">" and "&" are quoted inside JSON objects
(
{"a": "<script>test&ing</script>"},
'<script id="test_id" type="application/json">'
- '{"a": "\\u003Cscript\\u003Etest\\u0026ing\\u003C/script\\u003E"}</script>',
+ '{"a": "\\u003Cscript\\u003Etest\\u0026ing\\u003C/script\\u003E"}'
+ "</script>",
),
# Lazy strings are quoted
(
lazystr("&<>"),
- '<script id="test_id" type="application/json">"\\u0026\\u003C\\u003E"</script>',
+ '<script id="test_id" type="application/json">"\\u0026\\u003C\\u003E"'
+ "</script>",
),
(
{"a": lazystr("<script>test&ing</script>")},
'<script id="test_id" type="application/json">'
- '{"a": "\\u003Cscript\\u003Etest\\u0026ing\\u003C/script\\u003E"}</script>',
+ '{"a": "\\u003Cscript\\u003Etest\\u0026ing\\u003C/script\\u003E"}'
+ "</script>",
),
)
for arg, expected in tests:
@@ -228,11 +232,14 @@ class TestUtilsHtml(SimpleTestCase):
("http://example.com/?x=<>\"'", "http://example.com/?x=%3C%3E%22%27"),
(
"http://example.com/?q=http://example.com/?x=1%26q=django",
- "http://example.com/?q=http%3A%2F%2Fexample.com%2F%3Fx%3D1%26q%3Ddjango",
+ "http://example.com/?q=http%3A%2F%2Fexample.com%2F%3Fx%3D1%26q%3D"
+ "django",
),
(
- "http://example.com/?q=http%3A%2F%2Fexample.com%2F%3Fx%3D1%26q%3Ddjango",
- "http://example.com/?q=http%3A%2F%2Fexample.com%2F%3Fx%3D1%26q%3Ddjango",
+ "http://example.com/?q=http%3A%2F%2Fexample.com%2F%3Fx%3D1%26q%3D"
+ "django",
+ "http://example.com/?q=http%3A%2F%2Fexample.com%2F%3Fx%3D1%26q%3D"
+ "django",
),
("http://.www.f oo.bar/", "http://.www.f%20oo.bar/"),
)
@@ -297,11 +304,13 @@ class TestUtilsHtml(SimpleTestCase):
tests = (
(
"Search for google.com/?q=! and see.",
- 'Search for <a href="http://google.com/?q=">google.com/?q=</a>! and see.',
+ 'Search for <a href="http://google.com/?q=">google.com/?q=</a>! and '
+ "see.",
),
(
"Search for google.com/?q=1&lt! and see.",
- 'Search for <a href="http://google.com/?q=1%3C">google.com/?q=1&lt</a>! and see.',
+ 'Search for <a href="http://google.com/?q=1%3C">google.com/?q=1&lt'
+ "</a>! and see.",
),
(
lazystr("Search for google.com/?q=!"),
diff --git a/tests/utils_tests/test_jslex.py b/tests/utils_tests/test_jslex.py
index 0963dd0f16..ee13eb4d64 100644
--- a/tests/utils_tests/test_jslex.py
+++ b/tests/utils_tests/test_jslex.py
@@ -72,7 +72,7 @@ class JsTokensTest(SimpleTestCase):
(r"a=/\//,1", ["id a", "punct =", r"regex /\//", "punct ,", "dnum 1"]),
# next two are from https://www-archive.mozilla.org/js/language/js20-2002-04/rationale/syntax.html#regular-expressions # NOQA
(
- """for (var x = a in foo && "</x>" || mot ? z:/x:3;x<5;y</g/i) {xyz(x++);}""",
+ 'for (var x = a in foo && "</x>" || mot ? z:/x:3;x<5;y</g/i) {xyz(x++);}',
[
"keyword for",
"punct (",
@@ -104,7 +104,7 @@ class JsTokensTest(SimpleTestCase):
],
),
(
- """for (var x = a in foo && "</x>" || mot ? z/x:3;x<5;y</g/i) {xyz(x++);}""",
+ 'for (var x = a in foo && "</x>" || mot ? z/x:3;x<5;y</g/i) {xyz(x++);}',
[
"keyword for",
"punct (",
@@ -240,7 +240,8 @@ class JsTokensTest(SimpleTestCase):
],
),
(
- r""" this._js = "e.str(\"" + this.value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"") + "\")"; """,
+ r' this._js = "e.str(\"" + this.value.replace(/\\/g, "\\\\")'
+ r'.replace(/"/g, "\\\"") + "\")"; ',
[
"keyword this",
"punct .",
diff --git a/tests/utils_tests/test_lazyobject.py b/tests/utils_tests/test_lazyobject.py
index 131d893a44..9ccae595f4 100644
--- a/tests/utils_tests/test_lazyobject.py
+++ b/tests/utils_tests/test_lazyobject.py
@@ -126,7 +126,8 @@ class LazyObjectTestCase(TestCase):
for needle, haystack in test_data:
self.assertIn(needle, self.lazy_wrap(haystack))
- # __contains__ doesn't work when the haystack is a string and the needle a LazyObject
+ # __contains__ doesn't work when the haystack is a string and the
+ # needle a LazyObject.
for needle_haystack in test_data[1:]:
self.assertIn(self.lazy_wrap(needle), haystack)
self.assertIn(self.lazy_wrap(needle), self.lazy_wrap(haystack))
diff --git a/tests/utils_tests/test_text.py b/tests/utils_tests/test_text.py
index caab19a55d..cb2959fe15 100644
--- a/tests/utils_tests/test_text.py
+++ b/tests/utils_tests/test_text.py
@@ -122,10 +122,12 @@ class TestUtilsText(SimpleTestCase):
def test_truncate_html_words(self):
truncator = text.Truncator(
- '<p id="par"><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>'
+ '<p id="par"><strong><em>The quick brown fox jumped over the lazy dog.</em>'
+ "</strong></p>"
)
self.assertEqual(
- '<p id="par"><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>',
+ '<p id="par"><strong><em>The quick brown fox jumped over the lazy dog.</em>'
+ "</strong></p>",
truncator.words(10, html=True),
)
self.assertEqual(
@@ -143,7 +145,8 @@ class TestUtilsText(SimpleTestCase):
# Test with new line inside tag
truncator = text.Truncator(
- '<p>The quick <a href="xyz.html"\n id="mylink">brown fox</a> jumped over the lazy dog.</p>'
+ '<p>The quick <a href="xyz.html"\n id="mylink">brown fox</a> jumped over '
+ "the lazy dog.</p>"
)
self.assertEqual(
'<p>The quick <a href="xyz.html"\n id="mylink">brown…</a></p>',