Issue #19361: JSON decoder now raises JSONDecodeError instead of ValueError.

This commit is contained in:
Serhiy Storchaka 2015-01-26 13:16:30 +02:00
parent 4e5d9eac2c
commit 47efb4a5dc
10 changed files with 144 additions and 83 deletions

View file

@ -63,12 +63,12 @@ def test_keys_reuse(self):
def test_extra_data(self):
s = '[1, 2, 3]5'
msg = 'Extra data'
self.assertRaisesRegex(ValueError, msg, self.loads, s)
self.assertRaisesRegex(self.JSONDecodeError, msg, self.loads, s)
def test_invalid_escape(self):
s = '["abc\\y"]'
msg = 'escape'
self.assertRaisesRegex(ValueError, msg, self.loads, s)
self.assertRaisesRegex(self.JSONDecodeError, msg, self.loads, s)
def test_invalid_input_type(self):
msg = 'the JSON object must be str'
@ -80,10 +80,10 @@ def test_invalid_input_type(self):
def test_string_with_utf8_bom(self):
# see #18958
bom_json = "[1,2,3]".encode('utf-8-sig').decode('utf-8')
with self.assertRaises(ValueError) as cm:
with self.assertRaises(self.JSONDecodeError) as cm:
self.loads(bom_json)
self.assertIn('BOM', str(cm.exception))
with self.assertRaises(ValueError) as cm:
with self.assertRaises(self.JSONDecodeError) as cm:
self.json.load(StringIO(bom_json))
self.assertIn('BOM', str(cm.exception))
# make sure that the BOM is not detected in the middle of a string