summaryrefslogtreecommitdiff
path: root/lib/python2.7/json/tests/test_dump.py
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2015-09-23 20:45:19 -0700
committerJosh Gao <jmgao@google.com>2015-09-23 20:46:13 -0700
commitf79bdee20cacc521d7ec3a8720a43087b47326d6 (patch)
treeee9330bdc29d1af5a033ca862a10a33e5e1c1b7f /lib/python2.7/json/tests/test_dump.py
parentdf5f01881b6d4e9c59be106b4063247433737773 (diff)
downloadlinux-x86-f79bdee20cacc521d7ec3a8720a43087b47326d6.tar.gz
Import gdb 7.10 linux-x86_64 prebuilt.
Taken from aosp-master-ndk build 2274331. Bug: http://b/21920612 Change-Id: I2129ab5b85c96273bdb97ee9ca82116bb4db87fa
Diffstat (limited to 'lib/python2.7/json/tests/test_dump.py')
-rw-r--r--lib/python2.7/json/tests/test_dump.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/python2.7/json/tests/test_dump.py b/lib/python2.7/json/tests/test_dump.py
new file mode 100644
index 0000000..cd92569
--- /dev/null
+++ b/lib/python2.7/json/tests/test_dump.py
@@ -0,0 +1,32 @@
+from cStringIO import StringIO
+from json.tests import PyTest, CTest
+
+
+class TestDump(object):
+ def test_dump(self):
+ sio = StringIO()
+ self.json.dump({}, sio)
+ self.assertEqual(sio.getvalue(), '{}')
+
+ def test_dumps(self):
+ self.assertEqual(self.dumps({}), '{}')
+
+ def test_encode_truefalse(self):
+ self.assertEqual(self.dumps(
+ {True: False, False: True}, sort_keys=True),
+ '{"false": true, "true": false}')
+ self.assertEqual(self.dumps(
+ {2: 3.0, 4.0: 5L, False: 1, 6L: True}, sort_keys=True),
+ '{"false": 1, "2": 3.0, "4.0": 5, "6": true}')
+
+ # Issue 16228: Crash on encoding resized list
+ def test_encode_mutated(self):
+ a = [object()] * 10
+ def crasher(obj):
+ del a[-1]
+ self.assertEqual(self.dumps(a, default=crasher),
+ '[null, null, null, null, null]')
+
+
+class TestPyDump(TestDump, PyTest): pass
+class TestCDump(TestDump, CTest): pass