From 44cd86bbdddb1f7b05deba2c1986a1e98f992429 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Mon, 26 Aug 2019 16:04:35 +0900 Subject: [PATCH] bpo-37805: Add tests for json.dump(..., skipkeys=True) (GH-15489) https://bugs.python.org/issue37805 Automerge-Triggered-By: @methane --- Lib/test/test_json/test_dump.py | 10 ++++++++++ .../Tests/2019-08-25-19-51-46.bpo-37805.Kl1sti.rst | 1 + 2 files changed, 11 insertions(+) create mode 100644 Misc/NEWS.d/next/Tests/2019-08-25-19-51-46.bpo-37805.Kl1sti.rst diff --git a/Lib/test/test_json/test_dump.py b/Lib/test/test_json/test_dump.py index fd0d86b392c..13b40020781 100644 --- a/Lib/test/test_json/test_dump.py +++ b/Lib/test/test_json/test_dump.py @@ -12,6 +12,16 @@ class TestDump: def test_dumps(self): self.assertEqual(self.dumps({}), '{}') + def test_dump_skipkeys(self): + v = {b'invalid_key': False, 'valid_key': True} + with self.assertRaises(TypeError): + self.json.dumps(v) + + s = self.json.dumps(v, skipkeys=True) + o = self.json.loads(s) + self.assertIn('valid_key', o) + self.assertNotIn(b'invalid_key', o) + def test_encode_truefalse(self): self.assertEqual(self.dumps( {True: False, False: True}, sort_keys=True), diff --git a/Misc/NEWS.d/next/Tests/2019-08-25-19-51-46.bpo-37805.Kl1sti.rst b/Misc/NEWS.d/next/Tests/2019-08-25-19-51-46.bpo-37805.Kl1sti.rst new file mode 100644 index 00000000000..478c38c3d4c --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2019-08-25-19-51-46.bpo-37805.Kl1sti.rst @@ -0,0 +1 @@ +Add tests for json.dump(..., skipkeys=True). Patch by Dong-hee Na.