mirror of
https://github.com/python/cpython.git
synced 2025-08-19 00:00:48 +00:00
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:
parent
03c52f2f63
commit
2cb82d2a88
4 changed files with 20 additions and 6 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue