diff options
author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-11-21 01:53:17 (GMT) |
---|---|---|
committer | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-11-21 01:53:17 (GMT) |
commit | d675a2c48a717cd6a960185abc59c50e82ad50d6 (patch) | |
tree | 1e8ad4ce4d6868ab89d4152c032541a4eb5e2c36 /Lib | |
parent | 045aef3795ebb799fa89c4be47cfc9b2448ab1b2 (diff) | |
parent | 5fae0e58549c9270b188a1591ffa6cc4c2d9ab4e (diff) | |
download | cpython-d675a2c48a717cd6a960185abc59c50e82ad50d6.zip cpython-d675a2c48a717cd6a960185abc59c50e82ad50d6.tar.gz cpython-d675a2c48a717cd6a960185abc59c50e82ad50d6.tar.bz2 |
Merge from 3.3: Improve str() and object.__str__() docs (issue #13538).
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_builtin.py | 1 | ||||
-rw-r--r-- | Lib/test/test_unicode.py | 20 |
2 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index c32992c..19d7c70 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -1286,6 +1286,7 @@ class BuiltinTest(unittest.TestCase): self.assertRaises(TypeError, setattr, sys, 1, 'spam') self.assertRaises(TypeError, setattr) + # test_str(): see test_unicode.py and test_bytes.py for str() tests. def test_sum(self): self.assertEqual(sum([]), 0) diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 7da5c8b..6ac62fb 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -1182,6 +1182,26 @@ class UnicodeTest(string_tests.CommonTest, self.assertRaises(TypeError, str, 42, 42, 42) + def test_constructor_keyword_args(self): + """Pass various keyword argument combinations to the constructor.""" + # The object argument can be passed as a keyword. + self.assertEqual(str(object='foo'), 'foo') + self.assertEqual(str(object=b'foo', encoding='utf-8'), 'foo') + # The errors argument without encoding triggers "decode" mode. + self.assertEqual(str(b'foo', errors='strict'), 'foo') # not "b'foo'" + self.assertEqual(str(object=b'foo', errors='strict'), 'foo') + + def test_constructor_defaults(self): + """Check the constructor argument defaults.""" + # The object argument defaults to '' or b''. + self.assertEqual(str(), '') + self.assertEqual(str(errors='strict'), '') + utf8_cent = '¢'.encode('utf-8') + # The encoding argument defaults to utf-8. + self.assertEqual(str(utf8_cent, errors='strict'), '¢') + # The errors argument defaults to strict. + self.assertRaises(UnicodeDecodeError, str, utf8_cent, encoding='ascii') + def test_codecs_utf7(self): utfTests = [ ('A\u2262\u0391.', b'A+ImIDkQ.'), # RFC2152 example |