mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +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
|
@ -12,8 +12,8 @@ class TestRecursion:
|
|||
x.append(x)
|
||||
try:
|
||||
self.dumps(x)
|
||||
except ValueError:
|
||||
pass
|
||||
except ValueError as exc:
|
||||
self.assertEqual(exc.__notes__, ["when serializing list item 0"])
|
||||
else:
|
||||
self.fail("didn't raise ValueError on list recursion")
|
||||
x = []
|
||||
|
@ -21,8 +21,8 @@ class TestRecursion:
|
|||
x.append(y)
|
||||
try:
|
||||
self.dumps(x)
|
||||
except ValueError:
|
||||
pass
|
||||
except ValueError as exc:
|
||||
self.assertEqual(exc.__notes__, ["when serializing list item 0"]*2)
|
||||
else:
|
||||
self.fail("didn't raise ValueError on alternating list recursion")
|
||||
y = []
|
||||
|
@ -35,8 +35,8 @@ class TestRecursion:
|
|||
x["test"] = x
|
||||
try:
|
||||
self.dumps(x)
|
||||
except ValueError:
|
||||
pass
|
||||
except ValueError as exc:
|
||||
self.assertEqual(exc.__notes__, ["when serializing dict item 'test'"])
|
||||
else:
|
||||
self.fail("didn't raise ValueError on dict recursion")
|
||||
x = {}
|
||||
|
@ -60,8 +60,10 @@ class TestRecursion:
|
|||
enc.recurse = True
|
||||
try:
|
||||
enc.encode(JSONTestObject)
|
||||
except ValueError:
|
||||
pass
|
||||
except ValueError as exc:
|
||||
self.assertEqual(exc.__notes__,
|
||||
["when serializing list item 0",
|
||||
"when serializing type object"])
|
||||
else:
|
||||
self.fail("didn't raise ValueError on default recursion")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue