diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2013-10-20 22:52:33 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2013-10-20 22:52:33 (GMT) |
commit | a0e768ccc250dbe6ffab812b7964538013ae36c4 (patch) | |
tree | 80630a60d1c6dc489f7fd398e7ac6227fe34a1c1 /Lib/test | |
parent | 4ea16e56ebd39e95392e3549c7dad2dd4d6ed602 (diff) | |
download | cpython-a0e768ccc250dbe6ffab812b7964538013ae36c4.zip cpython-a0e768ccc250dbe6ffab812b7964538013ae36c4.tar.gz cpython-a0e768ccc250dbe6ffab812b7964538013ae36c4.tar.bz2 |
#19307: Improve error message for json.load(s) while passing objects of the wrong type.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_json/test_decode.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/test/test_json/test_decode.py b/Lib/test/test_json/test_decode.py index d23e285..05d07b7 100644 --- a/Lib/test/test_json/test_decode.py +++ b/Lib/test/test_json/test_decode.py @@ -1,5 +1,5 @@ import decimal -from io import StringIO +from io import StringIO, BytesIO from collections import OrderedDict from test.test_json import PyTest, CTest @@ -70,5 +70,12 @@ class TestDecode: msg = 'escape' self.assertRaisesRegex(ValueError, msg, self.loads, s) + def test_invalid_input_type(self): + msg = 'the JSON object must be str' + for value in [1, 3.14, b'bytes', b'\xff\x00', [], {}, None]: + self.assertRaisesRegex(TypeError, msg, self.loads, value) + with self.assertRaisesRegex(TypeError, msg): + self.json.load(BytesIO(b'[1,2,3]')) + class TestPyDecode(TestDecode, PyTest): pass class TestCDecode(TestDecode, CTest): pass |