Skip to content

Commit 3f34237

Browse files
authored
bpo-39337: Add a test case for normalizing of codec names (GH-19069)
1 parent bfe6e03 commit 3f34237

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Lib/test/test_codecs.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3415,5 +3415,30 @@ def test_rot13_func(self):
34153415
'To be, or not to be, that is the question')
34163416

34173417

3418+
class CodecNameNormalizationTest(unittest.TestCase):
3419+
"""Test codec name normalization"""
3420+
def test_normalized_encoding(self):
3421+
FOUND = (1, 2, 3, 4)
3422+
NOT_FOUND = (None, None, None, None)
3423+
def search_function(encoding):
3424+
if encoding == "aaa_8":
3425+
return FOUND
3426+
else:
3427+
return NOT_FOUND
3428+
3429+
codecs.register(search_function)
3430+
self.addCleanup(codecs.unregister, search_function)
3431+
self.assertEqual(FOUND, codecs.lookup('aaa_8'))
3432+
self.assertEqual(FOUND, codecs.lookup('AAA-8'))
3433+
self.assertEqual(FOUND, codecs.lookup('AAA---8'))
3434+
self.assertEqual(FOUND, codecs.lookup('AAA 8'))
3435+
self.assertEqual(FOUND, codecs.lookup('aaa\xe9\u20ac-8'))
3436+
self.assertEqual(NOT_FOUND, codecs.lookup('AAA.8'))
3437+
self.assertEqual(NOT_FOUND, codecs.lookup('AAA...8'))
3438+
self.assertEqual(NOT_FOUND, codecs.lookup('BBB-8'))
3439+
self.assertEqual(NOT_FOUND, codecs.lookup('BBB.8'))
3440+
self.assertEqual(NOT_FOUND, codecs.lookup('a\xe9\u20ac-8'))
3441+
3442+
34183443
if __name__ == "__main__":
34193444
unittest.main()

0 commit comments

Comments
 (0)