aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_json/test_fail.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_json/test_fail.py')
-rw-r--r--Lib/test/test_json/test_fail.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/Lib/test/test_json/test_fail.py b/Lib/test/test_json/test_fail.py
index a74240f1107..7c1696cc66d 100644
--- a/Lib/test/test_json/test_fail.py
+++ b/Lib/test/test_json/test_fail.py
@@ -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 = [