Skip to content
Prev Previous commit
Next Next commit
apply victor's comments
  • Loading branch information
shihai1991 committed Oct 10, 2020
commit 2e73d13ef9e7999ac7fe575c5eb380f41d59cb37
13 changes: 6 additions & 7 deletions Lib/test/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3442,19 +3442,18 @@ def search_function(encoding):

class EncodingNormalizationTest(unittest.TestCase):

def test_bpo39337(self):
"""
bpo-39337: similar to _Py_normalize_encoding(),
encodings.normalize_encoding() should ignore non-ASCII letters.
"""
import encodings

def test_normalization(self):
# 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')
self.assertEqual(out, 'utf_8')
out = encodings.normalize_encoding('utf 8')
self.assertEqual(out, 'utf_8')
out = encodings.normalize_encoding('UTF 8')
Copy link
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?

Copy link
Member Author

@shihai1991 shihai1991 Oct 12, 2020

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
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
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')


if __name__ == "__main__":
Expand Down