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.
This commit is contained in:
Serhiy Storchaka 2017-11-25 17:38:20 +02:00 committed by GitHub
parent 5b48dc638b
commit cfa797c068
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 13 deletions

View file

@ -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 = [