summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_userstring.py
diff options
context:
space:
mode:
authorDaniel Fortunov <asqui@users.noreply.github.com>2019-08-28 04:38:09 (GMT)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>2019-08-28 04:38:09 (GMT)
commit2a16eea71f56c2d8f38c295c8ce71a9a9a140aff (patch)
tree71726a024fdfef5d79c432687fce143bbf2b41bd /Lib/test/test_userstring.py
parent98d90f745d35d5d07bffcb46788b50e05eea56c6 (diff)
downloadcpython-2a16eea71f56c2d8f38c295c8ce71a9a9a140aff.zip
cpython-2a16eea71f56c2d8f38c295c8ce71a9a9a140aff.tar.gz
cpython-2a16eea71f56c2d8f38c295c8ce71a9a9a140aff.tar.bz2
bpo-36582: Make collections.UserString.encode() return bytes, not str (GH-13138)
Diffstat (limited to 'Lib/test/test_userstring.py')
-rw-r--r--Lib/test/test_userstring.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_userstring.py b/Lib/test/test_userstring.py
index 19b0acf..4d1d8b6 100644
--- a/Lib/test/test_userstring.py
+++ b/Lib/test/test_userstring.py
@@ -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()