diff options
author | Hai Shi <shihai1992@gmail.com> | 2020-10-08 19:20:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-08 19:20:57 (GMT) |
commit | 3f342376ab0da3b4c8a38a27edfafba8e8cdf52d (patch) | |
tree | 441a977552bdb482f8b472596180e67bd2df9c92 /Lib/test | |
parent | bfe6e03cd6931813dd61b50f5fdf7d8a8848f4cd (diff) | |
download | cpython-3f342376ab0da3b4c8a38a27edfafba8e8cdf52d.zip cpython-3f342376ab0da3b4c8a38a27edfafba8e8cdf52d.tar.gz cpython-3f342376ab0da3b4c8a38a27edfafba8e8cdf52d.tar.bz2 |
bpo-39337: Add a test case for normalizing of codec names (GH-19069)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_codecs.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index ed508f3..ddf4e08 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -3415,5 +3415,30 @@ class Rot13UtilTest(unittest.TestCase): 'To be, or not to be, that is the question') +class CodecNameNormalizationTest(unittest.TestCase): + """Test codec name normalization""" + def test_normalized_encoding(self): + FOUND = (1, 2, 3, 4) + NOT_FOUND = (None, None, None, None) + def search_function(encoding): + if encoding == "aaa_8": + return FOUND + else: + return NOT_FOUND + + codecs.register(search_function) + self.addCleanup(codecs.unregister, search_function) + self.assertEqual(FOUND, codecs.lookup('aaa_8')) + self.assertEqual(FOUND, codecs.lookup('AAA-8')) + self.assertEqual(FOUND, codecs.lookup('AAA---8')) + self.assertEqual(FOUND, codecs.lookup('AAA 8')) + self.assertEqual(FOUND, codecs.lookup('aaa\xe9\u20ac-8')) + self.assertEqual(NOT_FOUND, codecs.lookup('AAA.8')) + self.assertEqual(NOT_FOUND, codecs.lookup('AAA...8')) + self.assertEqual(NOT_FOUND, codecs.lookup('BBB-8')) + self.assertEqual(NOT_FOUND, codecs.lookup('BBB.8')) + self.assertEqual(NOT_FOUND, codecs.lookup('a\xe9\u20ac-8')) + + if __name__ == "__main__": unittest.main() |