Skip to content

Commit

Permalink
Refs #27804 -- Used subTest() in tests.utils_tests.test_text.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdufresne committed Jun 4, 2020
1 parent 9e57b1e commit f47d5aa
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions tests/utils_tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def test_smart_split(self):
['a', 'b', 'c', 'd']),
]
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):
truncator = text.Truncator('The quick brown fox jumped over the lazy dog.')
Expand Down Expand Up @@ -206,9 +207,11 @@ def test_slugify(self):
('İstanbul', 'istanbul', True),
)
for value, output, is_unicode in items:
self.assertEqual(text.slugify(value, allow_unicode=is_unicode), output)
# interning the result may be useful, e.g. when fed to Path.
self.assertEqual(sys.intern(text.slugify('a')), 'a')
with self.subTest(value=value):
self.assertEqual(text.slugify(value, allow_unicode=is_unicode), output)
# 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)
def test_unescape_entities(self):
Expand All @@ -224,8 +227,9 @@ def test_unescape_entities(self):
('foo & bar', 'foo & bar'),
]
for value, output in items:
self.assertEqual(text.unescape_entities(value), output)
self.assertEqual(text.unescape_entities(lazystr(value)), output)
with self.subTest(value=value):
self.assertEqual(text.unescape_entities(value), output)
self.assertEqual(text.unescape_entities(lazystr(value)), output)

def test_unescape_entities_deprecated(self):
msg = (
Expand All @@ -243,8 +247,9 @@ def test_unescape_string_literal(self):
("'\'ab\' c'", "'ab' c"),
]
for value, output in items:
self.assertEqual(text.unescape_string_literal(value), output)
self.assertEqual(text.unescape_string_literal(lazystr(value)), output)
with self.subTest(value=value):
self.assertEqual(text.unescape_string_literal(value), output)
self.assertEqual(text.unescape_string_literal(lazystr(value)), output)

def test_get_valid_filename(self):
filename = "^&'@{}[],$=!-#()%+~_123.txt"
Expand Down

0 comments on commit f47d5aa

Please sign in to comment.