summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_json
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-12-17 12:32:48 (GMT)
committerGitHub <noreply@github.com>2022-12-17 12:32:48 (GMT)
commit0fe61d0838218b18bcff4bf434beba3e8dbcc42b (patch)
tree54d1b62faa69456c80603aeba76953e0f4749a66 /Lib/test/test_json
parent2b38a9aa747785f6d540e95e6846d6510de6b306 (diff)
downloadcpython-0fe61d0838218b18bcff4bf434beba3e8dbcc42b.zip
cpython-0fe61d0838218b18bcff4bf434beba3e8dbcc42b.tar.gz
cpython-0fe61d0838218b18bcff4bf434beba3e8dbcc42b.tar.bz2
gh-100272: Fix JSON serialization of OrderedDict (GH-100273)
It now preserves the order of keys.
Diffstat (limited to 'Lib/test/test_json')
-rw-r--r--Lib/test/test_json/test_default.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_json/test_default.py b/Lib/test/test_json/test_default.py
index 9b8325e..3ce1668 100644
--- a/Lib/test/test_json/test_default.py
+++ b/Lib/test/test_json/test_default.py
@@ -1,3 +1,4 @@
+import collections
from test.test_json import PyTest, CTest
@@ -7,6 +8,16 @@ class TestDefault:
self.dumps(type, default=repr),
self.dumps(repr(type)))
+ def test_ordereddict(self):
+ od = collections.OrderedDict(a=1, b=2, c=3, d=4)
+ od.move_to_end('b')
+ self.assertEqual(
+ self.dumps(od),
+ '{"a": 1, "c": 3, "d": 4, "b": 2}')
+ self.assertEqual(
+ self.dumps(od, sort_keys=True),
+ '{"a": 1, "b": 2, "c": 3, "d": 4}')
+
class TestPyDefault(TestDefault, PyTest): pass
class TestCDefault(TestDefault, CTest): pass