summaryrefslogtreecommitdiffstats
path: root/Lib/json/tests/test_decode.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/json/tests/test_decode.py')
-rw-r--r--Lib/json/tests/test_decode.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/json/tests/test_decode.py b/Lib/json/tests/test_decode.py
index 609f622..67c4c29 100644
--- a/Lib/json/tests/test_decode.py
+++ b/Lib/json/tests/test_decode.py
@@ -1,7 +1,9 @@
import decimal
from unittest import TestCase
+from io import StringIO
import json
+from collections import OrderedDict
class TestDecode(TestCase):
def test_decimal(self):
@@ -13,3 +15,20 @@ class TestDecode(TestCase):
rval = json.loads('1', parse_int=float)
self.assert_(isinstance(rval, float))
self.assertEquals(rval, 1.0)
+
+ def test_object_pairs_hook(self):
+ s = '{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}'
+ p = [("xkd", 1), ("kcw", 2), ("art", 3), ("hxm", 4),
+ ("qrt", 5), ("pad", 6), ("hoy", 7)]
+ self.assertEqual(json.loads(s), eval(s))
+ self.assertEqual(json.loads(s, object_pairs_hook = lambda x: x), p)
+ self.assertEqual(json.load(StringIO(s),
+ object_pairs_hook=lambda x: x), p)
+ od = json.loads(s, object_pairs_hook = OrderedDict)
+ self.assertEqual(od, OrderedDict(p))
+ self.assertEqual(type(od), OrderedDict)
+ # the object_pairs_hook takes priority over the object_hook
+ self.assertEqual(json.loads(s,
+ object_pairs_hook = OrderedDict,
+ object_hook = lambda x: None),
+ OrderedDict(p))