mirror of
https://github.com/python/cpython.git
synced 2025-10-21 22:22:48 +00:00
#19307: Improve error message for json.load(s) while passing objects of the wrong type.
This commit is contained in:
parent
4ea16e56eb
commit
a0e768ccc2
3 changed files with 14 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue