Refs #27804 -- Used subTest() in tests.utils_tests.test_text.

This commit is contained in:
Jon Dufresne 2020-06-04 02:16:21 -07:00 committed by GitHub
parent 9e57b1efb5
commit f47d5aac62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 8 deletions

View File

@ -52,7 +52,8 @@ class TestUtilsText(SimpleTestCase):
['a', 'b', 'c', 'd']), ['a', 'b', 'c', 'd']),
] ]
for test, expected in testdata: for test, expected in testdata:
self.assertEqual(list(text.smart_split(test)), expected) with self.subTest(value=test):
self.assertEqual(list(text.smart_split(test)), expected)
def test_truncate_chars(self): def test_truncate_chars(self):
truncator = text.Truncator('The quick brown fox jumped over the lazy dog.') truncator = text.Truncator('The quick brown fox jumped over the lazy dog.')
@ -206,9 +207,11 @@ class TestUtilsText(SimpleTestCase):
('İstanbul', 'istanbul', True), ('İstanbul', 'istanbul', True),
) )
for value, output, is_unicode in items: for value, output, is_unicode in items:
self.assertEqual(text.slugify(value, allow_unicode=is_unicode), output) with self.subTest(value=value):
# interning the result may be useful, e.g. when fed to Path. self.assertEqual(text.slugify(value, allow_unicode=is_unicode), output)
self.assertEqual(sys.intern(text.slugify('a')), 'a') # Interning the result may be useful, e.g. when fed to Path.
with self.subTest('intern'):
self.assertEqual(sys.intern(text.slugify('a')), 'a')
@ignore_warnings(category=RemovedInDjango40Warning) @ignore_warnings(category=RemovedInDjango40Warning)
def test_unescape_entities(self): def test_unescape_entities(self):
@ -224,8 +227,9 @@ class TestUtilsText(SimpleTestCase):
('foo & bar', 'foo & bar'), ('foo & bar', 'foo & bar'),
] ]
for value, output in items: for value, output in items:
self.assertEqual(text.unescape_entities(value), output) with self.subTest(value=value):
self.assertEqual(text.unescape_entities(lazystr(value)), output) self.assertEqual(text.unescape_entities(value), output)
self.assertEqual(text.unescape_entities(lazystr(value)), output)
def test_unescape_entities_deprecated(self): def test_unescape_entities_deprecated(self):
msg = ( msg = (
@ -243,8 +247,9 @@ class TestUtilsText(SimpleTestCase):
("'\'ab\' c'", "'ab' c"), ("'\'ab\' c'", "'ab' c"),
] ]
for value, output in items: for value, output in items:
self.assertEqual(text.unescape_string_literal(value), output) with self.subTest(value=value):
self.assertEqual(text.unescape_string_literal(lazystr(value)), output) self.assertEqual(text.unescape_string_literal(value), output)
self.assertEqual(text.unescape_string_literal(lazystr(value)), output)
def test_get_valid_filename(self): def test_get_valid_filename(self):
filename = "^&'@{}[],$=!-#()%+~_123.txt" filename = "^&'@{}[],$=!-#()%+~_123.txt"