bpo-36582: Make collections.UserString.encode() return bytes, not str (GH-13138) (GH-15557)

(cherry picked from commit 2a16eea71f)

Co-authored-by: Daniel Fortunov <asqui@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2019-08-27 21:59:54 -07:00 committed by Raymond Hettinger
parent 03c52f2f63
commit 2cb82d2a88
4 changed files with 20 additions and 6 deletions

View file

@ -51,6 +51,20 @@ class UserStringTest(
str3 = ustr3('TEST')
self.assertEqual(fmt2 % str3, 'value is TEST')
def test_encode_default_args(self):
self.checkequal(b'hello', 'hello', 'encode')
# Check that encoding defaults to utf-8
self.checkequal(b'\xf0\xa3\x91\x96', '\U00023456', 'encode')
# Check that errors defaults to 'strict'
self.checkraises(UnicodeError, '\ud800', 'encode')
def test_encode_explicit_none_args(self):
self.checkequal(b'hello', 'hello', 'encode', None, None)
# Check that encoding defaults to utf-8
self.checkequal(b'\xf0\xa3\x91\x96', '\U00023456', 'encode', None, None)
# Check that errors defaults to 'strict'
self.checkraises(UnicodeError, '\ud800', 'encode', None, None)
if __name__ == "__main__":
unittest.main()