summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_json
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-11-25 15:38:20 (GMT)
committerGitHub <noreply@github.com>2017-11-25 15:38:20 (GMT)
commitcfa797c0681b7fef47cf93955fd06b54ddd09a7f (patch)
tree6e4ecf5ed329d339b26f1eb2bf1f73950abbee72 /Lib/test/test_json
parent5b48dc638b7405fd9bde4d854bf477dfeaaddf44 (diff)
downloadcpython-cfa797c0681b7fef47cf93955fd06b54ddd09a7f.zip
cpython-cfa797c0681b7fef47cf93955fd06b54ddd09a7f.tar.gz
cpython-cfa797c0681b7fef47cf93955fd06b54ddd09a7f.tar.bz2
bpo-24641: Improved error message for JSON unserializible keys. (#4364)
Also updated an example for default() in the module docstring. Removed quotes around type name in other error messages.
Diffstat (limited to 'Lib/test/test_json')
-rw-r--r--Lib/test/test_json/test_fail.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/test/test_json/test_fail.py b/Lib/test/test_json/test_fail.py
index 7910521..eb9064e 100644
--- a/Lib/test/test_json/test_fail.py
+++ b/Lib/test/test_json/test_fail.py
@@ -93,12 +93,15 @@ class TestFail:
def test_non_string_keys_dict(self):
data = {'a' : 1, (1, 2) : 2}
+ with self.assertRaisesRegex(TypeError,
+ 'keys must be str, int, float, bool or None, not tuple'):
+ self.dumps(data)
- #This is for c encoder
- self.assertRaises(TypeError, self.dumps, data)
-
- #This is for python encoder
- self.assertRaises(TypeError, self.dumps, data, indent=True)
+ def test_not_serializable(self):
+ import sys
+ with self.assertRaisesRegex(TypeError,
+ 'Object of type module is not JSON serializable'):
+ self.dumps(sys)
def test_truncated_input(self):
test_cases = [