diff options
author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-11-21 01:45:51 (GMT) |
---|---|---|
committer | Chris Jerdonek <chris.jerdonek@gmail.com> | 2012-11-21 01:45:51 (GMT) |
commit | 5fae0e58549c9270b188a1591ffa6cc4c2d9ab4e (patch) | |
tree | 5e955cf6e54ee57cf3531687ddf4c01681c34786 /Lib | |
parent | 9ddfb19e4197be4abc0b74236f207a3efc853c04 (diff) | |
download | cpython-5fae0e58549c9270b188a1591ffa6cc4c2d9ab4e.zip cpython-5fae0e58549c9270b188a1591ffa6cc4c2d9ab4e.tar.gz cpython-5fae0e58549c9270b188a1591ffa6cc4c2d9ab4e.tar.bz2 |
Improve str() and object.__str__() documentation (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 a811c4c..9aaedd3 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 |