Skip to content
Prev Previous commit
Next Next commit
apply victor's comment
  • Loading branch information
shihai1991 committed Oct 12, 2020
commit 95c1d980d08200d622d04ed559c0449cb102c9ec
15 changes: 8 additions & 7 deletions Lib/test/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3417,7 +3417,7 @@ def test_rot13_func(self):

class CodecNameNormalizationTest(unittest.TestCase):
"""Test codec name normalization"""
def test_normalized_encoding(self):
def test_codecs_lookup(self):
FOUND = (1, 2, 3, 4)
NOT_FOUND = (None, None, None, None)
def search_function(encoding):
Expand All @@ -3439,19 +3439,20 @@ def search_function(encoding):
self.assertEqual(NOT_FOUND, codecs.lookup('BBB.8'))
self.assertEqual(NOT_FOUND, codecs.lookup('a\xe9\u20ac-8'))


class EncodingNormalizationTest(unittest.TestCase):

def test_normalization(self):
def test_encodings_normalize_encoding(self):
Comment thread
shihai1991 marked this conversation as resolved.
# encodings.normalize_encoding() ignores non-ASCII letters.
out = encodings.normalize_encoding('utf\xE9\u20AC\U0010ffff-8')
self.assertEqual(out, 'utf_8')
out = encodings.normalize_encoding('utf_8')
Comment thread
shihai1991 marked this conversation as resolved.
Outdated
self.assertEqual(out, 'utf_8')
Comment thread
shihai1991 marked this conversation as resolved.
Outdated
out = encodings.normalize_encoding('utf\xE9\u20AC\U0010ffff-8')
self.assertEqual(out, 'utf_8')
out = encodings.normalize_encoding('utf 8')
self.assertEqual(out, 'utf_8')
Comment thread
shihai1991 marked this conversation as resolved.
Outdated
# encodings.normalize_encoding() doesn't convert
# characters to lower case.
out = encodings.normalize_encoding('UTF 8')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind to add a comment to explain that the function does not convert upper case letters to lower case letters, just to make the purpose of this test even more explicit?

@shihai1991 shihai1991 Oct 12, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I don't know how to exact explain it~
I found a case in https://github.com/python/cpython/blob/master/Lib/locale.py#L358.
Looks like It's fine to update encodings.normalize_encoding() to conver to lower-case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just describe the fact, Lol~

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can enhance this encodings.normalize_encoding()? I am not sure~

self.assertEqual(out, 'UTF_8')
out = encodings.normalize_encoding('utf.8')
self.assertEqual(out, 'utf.8')
out = encodings.normalize_encoding('utf...8')
Comment thread
shihai1991 marked this conversation as resolved.
Outdated
self.assertEqual(out, 'utf...8')

Expand Down