mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
gh-122163: Add notes for JSON serialization errors (GH-122165)
This allows to identify the source of the error.
This commit is contained in:
parent
c908d1f87d
commit
e6b25e9a09
8 changed files with 135 additions and 66 deletions
|
@ -100,8 +100,27 @@ class TestFail:
|
|||
def test_not_serializable(self):
|
||||
import sys
|
||||
with self.assertRaisesRegex(TypeError,
|
||||
'Object of type module is not JSON serializable'):
|
||||
'Object of type module is not JSON serializable') as cm:
|
||||
self.dumps(sys)
|
||||
self.assertFalse(hasattr(cm.exception, '__notes__'))
|
||||
|
||||
with self.assertRaises(TypeError) as cm:
|
||||
self.dumps([1, [2, 3, sys]])
|
||||
self.assertEqual(cm.exception.__notes__,
|
||||
['when serializing list item 2',
|
||||
'when serializing list item 1'])
|
||||
|
||||
with self.assertRaises(TypeError) as cm:
|
||||
self.dumps((1, (2, 3, sys)))
|
||||
self.assertEqual(cm.exception.__notes__,
|
||||
['when serializing tuple item 2',
|
||||
'when serializing tuple item 1'])
|
||||
|
||||
with self.assertRaises(TypeError) as cm:
|
||||
self.dumps({'a': {'b': sys}})
|
||||
self.assertEqual(cm.exception.__notes__,
|
||||
["when serializing dict item 'b'",
|
||||
"when serializing dict item 'a'"])
|
||||
|
||||
def test_truncated_input(self):
|
||||
test_cases = [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue