summaryrefslogtreecommitdiff
path: root/lib/python2.7/json/tests
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
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')
-rw-r--r--lib/python2.7/json/tests/__init__.py73
-rw-r--r--lib/python2.7/json/tests/__init__.pycbin0 -> 3933 bytes
-rw-r--r--lib/python2.7/json/tests/__init__.pyobin0 -> 3933 bytes
-rw-r--r--lib/python2.7/json/tests/test_check_circular.py34
-rw-r--r--lib/python2.7/json/tests/test_check_circular.pycbin0 -> 2831 bytes
-rw-r--r--lib/python2.7/json/tests/test_check_circular.pyobin0 -> 2831 bytes
-rw-r--r--lib/python2.7/json/tests/test_decode.py64
-rw-r--r--lib/python2.7/json/tests/test_decode.pycbin0 -> 4676 bytes
-rw-r--r--lib/python2.7/json/tests/test_decode.pyobin0 -> 4676 bytes
-rw-r--r--lib/python2.7/json/tests/test_default.py12
-rw-r--r--lib/python2.7/json/tests/test_default.pycbin0 -> 1280 bytes
-rw-r--r--lib/python2.7/json/tests/test_default.pyobin0 -> 1280 bytes
-rw-r--r--lib/python2.7/json/tests/test_dump.py32
-rw-r--r--lib/python2.7/json/tests/test_dump.pycbin0 -> 2599 bytes
-rw-r--r--lib/python2.7/json/tests/test_dump.pyobin0 -> 2599 bytes
-rw-r--r--lib/python2.7/json/tests/test_encode_basestring_ascii.py41
-rw-r--r--lib/python2.7/json/tests/test_encode_basestring_ascii.pycbin0 -> 3695 bytes
-rw-r--r--lib/python2.7/json/tests/test_encode_basestring_ascii.pyobin0 -> 3695 bytes
-rw-r--r--lib/python2.7/json/tests/test_fail.py105
-rw-r--r--lib/python2.7/json/tests/test_fail.pycbin0 -> 3218 bytes
-rw-r--r--lib/python2.7/json/tests/test_fail.pyobin0 -> 3218 bytes
-rw-r--r--lib/python2.7/json/tests/test_float.py37
-rw-r--r--lib/python2.7/json/tests/test_float.pycbin0 -> 2823 bytes
-rw-r--r--lib/python2.7/json/tests/test_float.pyobin0 -> 2823 bytes
-rw-r--r--lib/python2.7/json/tests/test_indent.py60
-rw-r--r--lib/python2.7/json/tests/test_indent.pycbin0 -> 2783 bytes
-rw-r--r--lib/python2.7/json/tests/test_indent.pyobin0 -> 2783 bytes
-rw-r--r--lib/python2.7/json/tests/test_pass1.py75
-rw-r--r--lib/python2.7/json/tests/test_pass1.pycbin0 -> 2737 bytes
-rw-r--r--lib/python2.7/json/tests/test_pass1.pyobin0 -> 2737 bytes
-rw-r--r--lib/python2.7/json/tests/test_pass2.py18
-rw-r--r--lib/python2.7/json/tests/test_pass2.pycbin0 -> 1348 bytes
-rw-r--r--lib/python2.7/json/tests/test_pass2.pyobin0 -> 1348 bytes
-rw-r--r--lib/python2.7/json/tests/test_pass3.py24
-rw-r--r--lib/python2.7/json/tests/test_pass3.pycbin0 -> 1443 bytes
-rw-r--r--lib/python2.7/json/tests/test_pass3.pyobin0 -> 1443 bytes
-rw-r--r--lib/python2.7/json/tests/test_recursion.py108
-rw-r--r--lib/python2.7/json/tests/test_recursion.pycbin0 -> 5198 bytes
-rw-r--r--lib/python2.7/json/tests/test_recursion.pyobin0 -> 5198 bytes
-rw-r--r--lib/python2.7/json/tests/test_scanstring.py109
-rw-r--r--lib/python2.7/json/tests/test_scanstring.pycbin0 -> 4817 bytes
-rw-r--r--lib/python2.7/json/tests/test_scanstring.pyobin0 -> 4817 bytes
-rw-r--r--lib/python2.7/json/tests/test_separators.py44
-rw-r--r--lib/python2.7/json/tests/test_separators.pycbin0 -> 2101 bytes
-rw-r--r--lib/python2.7/json/tests/test_separators.pyobin0 -> 2101 bytes
-rw-r--r--lib/python2.7/json/tests/test_speedups.py23
-rw-r--r--lib/python2.7/json/tests/test_speedups.pycbin0 -> 2091 bytes
-rw-r--r--lib/python2.7/json/tests/test_speedups.pyobin0 -> 2091 bytes
-rw-r--r--lib/python2.7/json/tests/test_tool.py69
-rw-r--r--lib/python2.7/json/tests/test_tool.pycbin0 -> 3052 bytes
-rw-r--r--lib/python2.7/json/tests/test_tool.pyobin0 -> 3052 bytes
-rw-r--r--lib/python2.7/json/tests/test_unicode.py89
-rw-r--r--lib/python2.7/json/tests/test_unicode.pycbin0 -> 6341 bytes
-rw-r--r--lib/python2.7/json/tests/test_unicode.pyobin0 -> 6341 bytes
54 files changed, 1017 insertions, 0 deletions
diff --git a/lib/python2.7/json/tests/__init__.py b/lib/python2.7/json/tests/__init__.py
new file mode 100644
index 0000000..90cb2b7
--- /dev/null
+++ b/lib/python2.7/json/tests/__init__.py
@@ -0,0 +1,73 @@
+import os
+import sys
+import json
+import doctest
+import unittest
+
+from test import test_support
+
+# import json with and without accelerations
+cjson = test_support.import_fresh_module('json', fresh=['_json'])
+pyjson = test_support.import_fresh_module('json', blocked=['_json'])
+
+# create two base classes that will be used by the other tests
+class PyTest(unittest.TestCase):
+ json = pyjson
+ loads = staticmethod(pyjson.loads)
+ dumps = staticmethod(pyjson.dumps)
+
+@unittest.skipUnless(cjson, 'requires _json')
+class CTest(unittest.TestCase):
+ if cjson is not None:
+ json = cjson
+ loads = staticmethod(cjson.loads)
+ dumps = staticmethod(cjson.dumps)
+
+# test PyTest and CTest checking if the functions come from the right module
+class TestPyTest(PyTest):
+ def test_pyjson(self):
+ self.assertEqual(self.json.scanner.make_scanner.__module__,
+ 'json.scanner')
+ self.assertEqual(self.json.decoder.scanstring.__module__,
+ 'json.decoder')
+ self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__,
+ 'json.encoder')
+
+class TestCTest(CTest):
+ def test_cjson(self):
+ self.assertEqual(self.json.scanner.make_scanner.__module__, '_json')
+ self.assertEqual(self.json.decoder.scanstring.__module__, '_json')
+ self.assertEqual(self.json.encoder.c_make_encoder.__module__, '_json')
+ self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__,
+ '_json')
+
+
+here = os.path.dirname(__file__)
+
+def test_suite():
+ suite = additional_tests()
+ loader = unittest.TestLoader()
+ for fn in os.listdir(here):
+ if fn.startswith("test") and fn.endswith(".py"):
+ modname = "json.tests." + fn[:-3]
+ __import__(modname)
+ module = sys.modules[modname]
+ suite.addTests(loader.loadTestsFromModule(module))
+ return suite
+
+def additional_tests():
+ suite = unittest.TestSuite()
+ for mod in (json, json.encoder, json.decoder):
+ suite.addTest(doctest.DocTestSuite(mod))
+ suite.addTest(TestPyTest('test_pyjson'))
+ suite.addTest(TestCTest('test_cjson'))
+ return suite
+
+def main():
+ suite = test_suite()
+ runner = unittest.TextTestRunner()
+ runner.run(suite)
+
+if __name__ == '__main__':
+ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+ main()
diff --git a/lib/python2.7/json/tests/__init__.pyc b/lib/python2.7/json/tests/__init__.pyc
new file mode 100644
index 0000000..c5e1e0e
--- /dev/null
+++ b/lib/python2.7/json/tests/__init__.pyc
Binary files differ
diff --git a/lib/python2.7/json/tests/__init__.pyo b/lib/python2.7/json/tests/__init__.pyo
new file mode 100644
index 0000000..c5e1e0e
--- /dev/null
+++ b/lib/python2.7/json/tests/__init__.pyo
Binary files differ
diff --git a/lib/python2.7/json/tests/test_check_circular.py b/lib/python2.7/json/tests/test_check_circular.py
new file mode 100644
index 0000000..3ad3d24
--- /dev/null
+++ b/lib/python2.7/json/tests/test_check_circular.py
@@ -0,0 +1,34 @@
+from json.tests import PyTest, CTest
+
+
+def default_iterable(obj):
+ return list(obj)
+
+class TestCheckCircular(object):
+ def test_circular_dict(self):
+ dct = {}
+ dct['a'] = dct
+ self.assertRaises(ValueError, self.dumps, dct)
+
+ def test_circular_list(self):
+ lst = []
+ lst.append(lst)
+ self.assertRaises(ValueError, self.dumps, lst)
+
+ def test_circular_composite(self):
+ dct2 = {}
+ dct2['a'] = []
+ dct2['a'].append(dct2)
+ self.assertRaises(ValueError, self.dumps, dct2)
+
+ def test_circular_default(self):
+ self.dumps([set()], default=default_iterable)
+ self.assertRaises(TypeError, self.dumps, [set()])
+
+ def test_circular_off_default(self):
+ self.dumps([set()], default=default_iterable, check_circular=False)
+ self.assertRaises(TypeError, self.dumps, [set()], check_circular=False)
+
+
+class TestPyCheckCircular(TestCheckCircular, PyTest): pass
+class TestCCheckCircular(TestCheckCircular, CTest): pass
diff --git a/lib/python2.7/json/tests/test_check_circular.pyc b/lib/python2.7/json/tests/test_check_circular.pyc
new file mode 100644
index 0000000..f354e6e
--- /dev/null
+++ b/lib/python2.7/json/tests/test_check_circular.pyc
Binary files differ
diff --git a/lib/python2.7/json/tests/test_check_circular.pyo b/lib/python2.7/json/tests/test_check_circular.pyo
new file mode 100644
index 0000000..f354e6e
--- /dev/null
+++ b/lib/python2.7/json/tests/test_check_circular.pyo
Binary files differ
diff --git a/lib/python2.7/json/tests/test_decode.py b/lib/python2.7/json/tests/test_decode.py
new file mode 100644
index 0000000..ffd1aa4
--- /dev/null
+++ b/lib/python2.7/json/tests/test_decode.py
@@ -0,0 +1,64 @@
+import decimal
+from StringIO import StringIO
+from collections import OrderedDict
+from json.tests import PyTest, CTest
+
+
+class TestDecode(object):
+ def test_decimal(self):
+ rval = self.loads('1.1', parse_float=decimal.Decimal)
+ self.assertTrue(isinstance(rval, decimal.Decimal))
+ self.assertEqual(rval, decimal.Decimal('1.1'))
+
+ def test_float(self):
+ rval = self.loads('1', parse_int=float)
+ self.assertTrue(isinstance(rval, float))
+ self.assertEqual(rval, 1.0)
+
+ def test_decoder_optimizations(self):
+ # Several optimizations were made that skip over calls to
+ # the whitespace regex, so this test is designed to try and
+ # exercise the uncommon cases. The array cases are already covered.
+ rval = self.loads('{ "key" : "value" , "k":"v" }')
+ self.assertEqual(rval, {"key":"value", "k":"v"})
+
+ def test_empty_objects(self):
+ self.assertEqual(self.loads('{}'), {})
+ self.assertEqual(self.loads('[]'), [])
+ self.assertEqual(self.loads('""'), u"")
+ self.assertIsInstance(self.loads('""'), unicode)
+
+ 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(self.loads(s), eval(s))
+ self.assertEqual(self.loads(s, object_pairs_hook=lambda x: x), p)
+ self.assertEqual(self.json.load(StringIO(s),
+ object_pairs_hook=lambda x: x), p)
+ od = self.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(self.loads(s, object_pairs_hook=OrderedDict,
+ object_hook=lambda x: None),
+ OrderedDict(p))
+ # check that empty objects literals work (see #17368)
+ self.assertEqual(self.loads('{}', object_pairs_hook=OrderedDict),
+ OrderedDict())
+ self.assertEqual(self.loads('{"empty": {}}',
+ object_pairs_hook=OrderedDict),
+ OrderedDict([('empty', OrderedDict())]))
+
+ def test_extra_data(self):
+ s = '[1, 2, 3]5'
+ msg = 'Extra data'
+ self.assertRaisesRegexp(ValueError, msg, self.loads, s)
+
+ def test_invalid_escape(self):
+ s = '["abc\\y"]'
+ msg = 'escape'
+ self.assertRaisesRegexp(ValueError, msg, self.loads, s)
+
+class TestPyDecode(TestDecode, PyTest): pass
+class TestCDecode(TestDecode, CTest): pass
diff --git a/lib/python2.7/json/tests/test_decode.pyc b/lib/python2.7/json/tests/test_decode.pyc
new file mode 100644
index 0000000..296249b
--- /dev/null
+++ b/lib/python2.7/json/tests/test_decode.pyc
Binary files differ
diff --git a/lib/python2.7/json/tests/test_decode.pyo b/lib/python2.7/json/tests/test_decode.pyo
new file mode 100644
index 0000000..296249b
--- /dev/null
+++ b/lib/python2.7/json/tests/test_decode.pyo
Binary files differ
diff --git a/lib/python2.7/json/tests/test_default.py b/lib/python2.7/json/tests/test_default.py
new file mode 100644
index 0000000..c2a07f6
--- /dev/null
+++ b/lib/python2.7/json/tests/test_default.py
@@ -0,0 +1,12 @@
+from json.tests import PyTest, CTest
+
+
+class TestDefault(object):
+ def test_default(self):
+ self.assertEqual(
+ self.dumps(type, default=repr),
+ self.dumps(repr(type)))
+
+
+class TestPyDefault(TestDefault, PyTest): pass
+class TestCDefault(TestDefault, CTest): pass
diff --git a/lib/python2.7/json/tests/test_default.pyc b/lib/python2.7/json/tests/test_default.pyc
new file mode 100644
index 0000000..4ef367e
--- /dev/null
+++ b/lib/python2.7/json/tests/test_default.pyc
Binary files differ
diff --git a/lib/python2.7/json/tests/test_default.pyo b/lib/python2.7/json/tests/test_default.pyo
new file mode 100644
index 0000000..4ef367e
--- /dev/null
+++ b/lib/python2.7/json/tests/test_default.pyo
Binary files differ
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
diff --git a/lib/python2.7/json/tests/test_dump.pyc b/lib/python2.7/json/tests/test_dump.pyc
new file mode 100644
index 0000000..2e23305
--- /dev/null
+++ b/lib/python2.7/json/tests/test_dump.pyc
Binary files differ
diff --git a/lib/python2.7/json/tests/test_dump.pyo b/lib/python2.7/json/tests/test_dump.pyo
new file mode 100644
index 0000000..2e23305
--- /dev/null
+++ b/lib/python2.7/json/tests/test_dump.pyo
Binary files differ
diff --git a/lib/python2.7/json/tests/test_encode_basestring_ascii.py b/lib/python2.7/json/tests/test_encode_basestring_ascii.py
new file mode 100644
index 0000000..9f9d5a5
--- /dev/null
+++ b/lib/python2.7/json/tests/test_encode_basestring_ascii.py
@@ -0,0 +1,41 @@
+from collections import OrderedDict
+from json.tests import PyTest, CTest
+
+
+CASES = [
+ (u'/\\"\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\x08\x0c\n\r\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?', '"/\\\\\\"\\ucafe\\ubabe\\uab98\\ufcde\\ubcda\\uef4a\\b\\f\\n\\r\\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?"'),
+ (u'\u0123\u4567\u89ab\ucdef\uabcd\uef4a', '"\\u0123\\u4567\\u89ab\\ucdef\\uabcd\\uef4a"'),
+ (u'controls', '"controls"'),
+ (u'\x08\x0c\n\r\t', '"\\b\\f\\n\\r\\t"'),
+ (u'{"object with 1 member":["array with 1 element"]}', '"{\\"object with 1 member\\":[\\"array with 1 element\\"]}"'),
+ (u' s p a c e d ', '" s p a c e d "'),
+ (u'\U0001d120', '"\\ud834\\udd20"'),
+ (u'\u03b1\u03a9', '"\\u03b1\\u03a9"'),
+ ('\xce\xb1\xce\xa9', '"\\u03b1\\u03a9"'),
+ (u'\u03b1\u03a9', '"\\u03b1\\u03a9"'),
+ ('\xce\xb1\xce\xa9', '"\\u03b1\\u03a9"'),
+ (u'\u03b1\u03a9', '"\\u03b1\\u03a9"'),
+ (u'\u03b1\u03a9', '"\\u03b1\\u03a9"'),
+ (u"`1~!@#$%^&*()_+-={':[,]}|;.</>?", '"`1~!@#$%^&*()_+-={\':[,]}|;.</>?"'),
+ (u'\x08\x0c\n\r\t', '"\\b\\f\\n\\r\\t"'),
+ (u'\u0123\u4567\u89ab\ucdef\uabcd\uef4a', '"\\u0123\\u4567\\u89ab\\ucdef\\uabcd\\uef4a"'),
+]
+
+class TestEncodeBasestringAscii(object):
+ def test_encode_basestring_ascii(self):
+ fname = self.json.encoder.encode_basestring_ascii.__name__
+ for input_string, expect in CASES:
+ result = self.json.encoder.encode_basestring_ascii(input_string)
+ self.assertEqual(result, expect,
+ '{0!r} != {1!r} for {2}({3!r})'.format(
+ result, expect, fname, input_string))
+
+ def test_ordered_dict(self):
+ # See issue 6105
+ items = [('one', 1), ('two', 2), ('three', 3), ('four', 4), ('five', 5)]
+ s = self.dumps(OrderedDict(items))
+ self.assertEqual(s, '{"one": 1, "two": 2, "three": 3, "four": 4, "five": 5}')
+
+
+class TestPyEncodeBasestringAscii(TestEncodeBasestringAscii, PyTest): pass
+class TestCEncodeBasestringAscii(TestEncodeBasestringAscii, CTest): pass
diff --git a/lib/python2.7/json/tests/test_encode_basestring_ascii.pyc b/lib/python2.7/json/tests/test_encode_basestring_ascii.pyc
new file mode 100644
index 0000000..a8577ca
--- /dev/null
+++ b/lib/python2.7/json/tests/test_encode_basestring_ascii.pyc
Binary files differ
diff --git a/lib/python2.7/json/tests/test_encode_basestring_ascii.pyo b/lib/python2.7/json/tests/test_encode_basestring_ascii.pyo
new file mode 100644
index 0000000..a8577ca
--- /dev/null
+++ b/lib/python2.7/json/tests/test_encode_basestring_ascii.pyo
Binary files differ
diff --git a/lib/python2.7/json/tests/test_fail.py b/lib/python2.7/json/tests/test_fail.py
new file mode 100644
index 0000000..e31b379
--- /dev/null
+++ b/lib/python2.7/json/tests/test_fail.py
@@ -0,0 +1,105 @@
+from json.tests import PyTest, CTest
+
+# 2007-10-05
+JSONDOCS = [
+ # http://json.org/JSON_checker/test/fail1.json
+ '"A JSON payload should be an object or array, not a string."',
+ # http://json.org/JSON_checker/test/fail2.json
+ '["Unclosed array"',
+ # http://json.org/JSON_checker/test/fail3.json
+ '{unquoted_key: "keys must be quoted"}',
+ # http://json.org/JSON_checker/test/fail4.json
+ '["extra comma",]',
+ # http://json.org/JSON_checker/test/fail5.json
+ '["double extra comma",,]',
+ # http://json.org/JSON_checker/test/fail6.json
+ '[ , "<-- missing value"]',
+ # http://json.org/JSON_checker/test/fail7.json
+ '["Comma after the close"],',
+ # http://json.org/JSON_checker/test/fail8.json
+ '["Extra close"]]',
+ # http://json.org/JSON_checker/test/fail9.json
+ '{"Extra comma": true,}',
+ # http://json.org/JSON_checker/test/fail10.json
+ '{"Extra value after close": true} "misplaced quoted value"',
+ # http://json.org/JSON_checker/test/fail11.json
+ '{"Illegal expression": 1 + 2}',
+ # http://json.org/JSON_checker/test/fail12.json
+ '{"Illegal invocation": alert()}',
+ # http://json.org/JSON_checker/test/fail13.json
+ '{"Numbers cannot have leading zeroes": 013}',
+ # http://json.org/JSON_checker/test/fail14.json
+ '{"Numbers cannot be hex": 0x14}',
+ # http://json.org/JSON_checker/test/fail15.json
+ '["Illegal backslash escape: \\x15"]',
+ # http://json.org/JSON_checker/test/fail16.json
+ '[\\naked]',
+ # http://json.org/JSON_checker/test/fail17.json
+ '["Illegal backslash escape: \\017"]',
+ # http://json.org/JSON_checker/test/fail18.json
+ '[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]',
+ # http://json.org/JSON_checker/test/fail19.json
+ '{"Missing colon" null}',
+ # http://json.org/JSON_checker/test/fail20.json
+ '{"Double colon":: null}',
+ # http://json.org/JSON_checker/test/fail21.json
+ '{"Comma instead of colon", null}',
+ # http://json.org/JSON_checker/test/fail22.json
+ '["Colon instead of comma": false]',
+ # http://json.org/JSON_checker/test/fail23.json
+ '["Bad value", truth]',
+ # http://json.org/JSON_checker/test/fail24.json
+ "['single quote']",
+ # http://json.org/JSON_checker/test/fail25.json
+ '["\ttab\tcharacter\tin\tstring\t"]',
+ # http://json.org/JSON_checker/test/fail26.json
+ '["tab\\ character\\ in\\ string\\ "]',
+ # http://json.org/JSON_checker/test/fail27.json
+ '["line\nbreak"]',
+ # http://json.org/JSON_checker/test/fail28.json
+ '["line\\\nbreak"]',
+ # http://json.org/JSON_checker/test/fail29.json
+ '[0e]',
+ # http://json.org/JSON_checker/test/fail30.json
+ '[0e+]',
+ # http://json.org/JSON_checker/test/fail31.json
+ '[0e+-1]',
+ # http://json.org/JSON_checker/test/fail32.json
+ '{"Comma instead if closing brace": true,',
+ # http://json.org/JSON_checker/test/fail33.json
+ '["mismatch"}',
+ # http://code.google.com/p/simplejson/issues/detail?id=3
+ u'["A\u001FZ control characters in string"]',
+]
+
+SKIPS = {
+ 1: "why not have a string payload?",
+ 18: "spec doesn't specify any nesting limitations",
+}
+
+class TestFail(object):
+ def test_failures(self):
+ for idx, doc in enumerate(JSONDOCS):
+ idx = idx + 1
+ if idx in SKIPS:
+ self.loads(doc)
+ continue
+ try:
+ self.loads(doc)
+ except ValueError:
+ pass
+ else:
+ self.fail("Expected failure for fail{0}.json: {1!r}".format(idx, doc))
+
+ def test_non_string_keys_dict(self):
+ data = {'a' : 1, (1, 2) : 2}
+
+ #This is for c encoder
+ self.assertRaises(TypeError, self.dumps, data)
+
+ #This is for python encoder
+ self.assertRaises(TypeError, self.dumps, data, indent=True)
+
+
+class TestPyFail(TestFail, PyTest): pass
+class TestCFail(TestFail, CTest): pass
diff --git a/lib/python2.7/json/tests/test_fail.pyc b/lib/python2.7/json/tests/test_fail.pyc
new file mode 100644
index 0000000..ffc1a39
--- /dev/null
+++ b/lib/python2.7/json/tests/test_fail.pyc
Binary files differ
diff --git a/lib/python2.7/json/tests/test_fail.pyo b/lib/python2.7/json/tests/test_fail.pyo
new file mode 100644
index 0000000..ffc1a39
--- /dev/null
+++ b/lib/python2.7/json/tests/test_fail.pyo
Binary files differ
diff --git a/lib/python2.7/json/tests/test_float.py b/lib/python2.7/json/tests/test_float.py
new file mode 100644
index 0000000..049f9ae
--- /dev/null
+++ b/lib/python2.7/json/tests/test_float.py
@@ -0,0 +1,37 @@
+import math
+from json.tests import PyTest, CTest
+
+
+class TestFloat(object):
+ def test_floats(self):
+ for num in [1617161771.7650001, math.pi, math.pi**100,
+ math.pi**-100, 3.1]:
+ self.assertEqual(float(self.dumps(num)), num)
+ self.assertEqual(self.loads(self.dumps(num)), num)
+ self.assertEqual(self.loads(unicode(self.dumps(num))), num)
+
+ def test_ints(self):
+ for num in [1, 1L, 1<<32, 1<<64]:
+ self.assertEqual(self.dumps(num), str(num))
+ self.assertEqual(int(self.dumps(num)), num)
+ self.assertEqual(self.loads(self.dumps(num)), num)
+ self.assertEqual(self.loads(unicode(self.dumps(num))), num)
+
+ def test_out_of_range(self):
+ self.assertEqual(self.loads('[23456789012E666]'), [float('inf')])
+ self.assertEqual(self.loads('[-23456789012E666]'), [float('-inf')])
+
+ def test_allow_nan(self):
+ for val in (float('inf'), float('-inf'), float('nan')):
+ out = self.dumps([val])
+ if val == val: # inf
+ self.assertEqual(self.loads(out), [val])
+ else: # nan
+ res = self.loads(out)
+ self.assertEqual(len(res), 1)
+ self.assertNotEqual(res[0], res[0])
+ self.assertRaises(ValueError, self.dumps, [val], allow_nan=False)
+
+
+class TestPyFloat(TestFloat, PyTest): pass
+class TestCFloat(TestFloat, CTest): pass
diff --git a/lib/python2.7/json/tests/test_float.pyc b/lib/python2.7/json/tests/test_float.pyc
new file mode 100644
index 0000000..74f67a4
--- /dev/null
+++ b/lib/python2.7/json/tests/test_float.pyc
Binary files differ
diff --git a/lib/python2.7/json/tests/test_float.pyo b/lib/python2.7/json/tests/test_float.pyo
new file mode 100644
index 0000000..74f67a4
--- /dev/null
+++ b/lib/python2.7/json/tests/test_float.pyo
Binary files differ
diff --git a/lib/python2.7/json/tests/test_indent.py b/lib/python2.7/json/tests/test_indent.py
new file mode 100644
index 0000000..9b18761
--- /dev/null
+++ b/lib/python2.7/json/tests/test_indent.py
@@ -0,0 +1,60 @@
+import textwrap
+from StringIO import StringIO
+from json.tests import PyTest, CTest
+
+
+class TestIndent(object):
+ def test_indent(self):
+ h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh', 'i-vhbjkhnth',
+ {'nifty': 87}, {'field': 'yes', 'morefield': False} ]
+
+ expect = textwrap.dedent("""\
+ [
+ [
+ "blorpie"
+ ],
+ [
+ "whoops"
+ ],
+ [],
+ "d-shtaeou",
+ "d-nthiouh",
+ "i-vhbjkhnth",
+ {
+ "nifty": 87
+ },
+ {
+ "field": "yes",
+ "morefield": false
+ }
+ ]""")
+
+
+ d1 = self.dumps(h)
+ d2 = self.dumps(h, indent=2, sort_keys=True, separators=(',', ': '))
+
+ h1 = self.loads(d1)
+ h2 = self.loads(d2)
+
+ self.assertEqual(h1, h)
+ self.assertEqual(h2, h)
+ self.assertEqual(d2, expect)
+
+ def test_indent0(self):
+ h = {3: 1}
+ def check(indent, expected):
+ d1 = self.dumps(h, indent=indent)
+ self.assertEqual(d1, expected)
+
+ sio = StringIO()
+ self.json.dump(h, sio, indent=indent)
+ self.assertEqual(sio.getvalue(), expected)
+
+ # indent=0 should emit newlines
+ check(0, '{\n"3": 1\n}')
+ # indent=None is more compact
+ check(None, '{"3": 1}')
+
+
+class TestPyIndent(TestIndent, PyTest): pass
+class TestCIndent(TestIndent, CTest): pass
diff --git a/lib/python2.7/json/tests/test_indent.pyc b/lib/python2.7/json/tests/test_indent.pyc
new file mode 100644
index 0000000..1fdc5f2
--- /dev/null
+++ b/lib/python2.7/json/tests/test_indent.pyc
Binary files differ
diff --git a/lib/python2.7/json/tests/test_indent.pyo b/lib/python2.7/json/tests/test_indent.pyo
new file mode 100644
index 0000000..1fdc5f2
--- /dev/null
+++ b/lib/python2.7/json/tests/test_indent.pyo
Binary files differ
diff --git a/lib/python2.7/json/tests/test_pass1.py b/lib/python2.7/json/tests/test_pass1.py
new file mode 100644
index 0000000..df8259b
--- /dev/null
+++ b/lib/python2.7/json/tests/test_pass1.py
@@ -0,0 +1,75 @@
+from json.tests import PyTest, CTest
+
+
+# from http://json.org/JSON_checker/test/pass1.json
+JSON = r'''
+[
+ "JSON Test Pattern pass1",
+ {"object with 1 member":["array with 1 element"]},
+ {},
+ [],
+ -42,
+ true,
+ false,
+ null,
+ {
+ "integer": 1234567890,
+ "real": -9876.543210,
+ "e": 0.123456789e-12,
+ "E": 1.234567890E+34,
+ "": 23456789012E66,
+ "zero": 0,
+ "one": 1,
+ "space": " ",
+ "quote": "\"",
+ "backslash": "\\",
+ "controls": "\b\f\n\r\t",
+ "slash": "/ & \/",
+ "alpha": "abcdefghijklmnopqrstuvwyz",
+ "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
+ "digit": "0123456789",
+ "0123456789": "digit",
+ "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
+ "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
+ "true": true,
+ "false": false,
+ "null": null,
+ "array":[ ],
+ "object":{ },
+ "address": "50 St. James Street",
+ "url": "http://www.JSON.org/",
+ "comment": "// /* <!-- --",
+ "# -- --> */": " ",
+ " s p a c e d " :[1,2 , 3
+
+,
+
+4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7],
+ "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
+ "quotes": "&#34; \u0022 %22 0x22 034 &#x22;",
+ "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
+: "A key can be any string"
+ },
+ 0.5 ,98.6
+,
+99.44
+,
+
+1066,
+1e1,
+0.1e1,
+1e-1,
+1e00,2e+00,2e-00
+,"rosebud"]
+'''
+
+class TestPass1(object):
+ def test_parse(self):
+ # test in/out equivalence and parsing
+ res = self.loads(JSON)
+ out = self.dumps(res)
+ self.assertEqual(res, self.loads(out))
+
+
+class TestPyPass1(TestPass1, PyTest): pass
+class TestCPass1(TestPass1, CTest): pass
diff --git a/lib/python2.7/json/tests/test_pass1.pyc b/lib/python2.7/json/tests/test_pass1.pyc
new file mode 100644
index 0000000..6330a55
--- /dev/null
+++ b/lib/python2.7/json/tests/test_pass1.pyc
Binary files differ
diff --git a/lib/python2.7/json/tests/test_pass1.pyo b/lib/python2.7/json/tests/test_pass1.pyo
new file mode 100644
index 0000000..6330a55
--- /dev/null
+++ b/lib/python2.7/json/tests/test_pass1.pyo
Binary files differ
diff --git a/lib/python2.7/json/tests/test_pass2.py b/lib/python2.7/json/tests/test_pass2.py
new file mode 100644
index 0000000..a2bb6d7
--- /dev/null
+++ b/lib/python2.7/json/tests/test_pass2.py
@@ -0,0 +1,18 @@
+from json.tests import PyTest, CTest
+
+
+# from http://json.org/JSON_checker/test/pass2.json
+JSON = r'''
+[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
+'''
+
+class TestPass2(object):
+ def test_parse(self):
+ # test in/out equivalence and parsing
+ res = self.loads(JSON)
+ out = self.dumps(res)
+ self.assertEqual(res, self.loads(out))
+
+
+class TestPyPass2(TestPass2, PyTest): pass
+class TestCPass2(TestPass2, CTest): pass
diff --git a/lib/python2.7/json/tests/test_pass2.pyc b/lib/python2.7/json/tests/test_pass2.pyc
new file mode 100644
index 0000000..d8c8aaf
--- /dev/null
+++ b/lib/python2.7/json/tests/test_pass2.pyc
Binary files differ
diff --git a/lib/python2.7/json/tests/test_pass2.pyo b/lib/python2.7/json/tests/test_pass2.pyo
new file mode 100644
index 0000000..d8c8aaf
--- /dev/null
+++ b/lib/python2.7/json/tests/test_pass2.pyo
Binary files differ
diff --git a/lib/python2.7/json/tests/test_pass3.py b/lib/python2.7/json/tests/test_pass3.py
new file mode 100644
index 0000000..221f9a0
--- /dev/null
+++ b/lib/python2.7/json/tests/test_pass3.py
@@ -0,0 +1,24 @@
+from json.tests import PyTest, CTest
+
+
+# from http://json.org/JSON_checker/test/pass3.json
+JSON = r'''
+{
+ "JSON Test Pattern pass3": {
+ "The outermost value": "must be an object or array.",
+ "In this test": "It is an object."
+ }
+}
+'''
+
+
+class TestPass3(object):
+ def test_parse(self):
+ # test in/out equivalence and parsing
+ res = self.loads(JSON)
+ out = self.dumps(res)
+ self.assertEqual(res, self.loads(out))
+
+
+class TestPyPass3(TestPass3, PyTest): pass
+class TestCPass3(TestPass3, CTest): pass
diff --git a/lib/python2.7/json/tests/test_pass3.pyc b/lib/python2.7/json/tests/test_pass3.pyc
new file mode 100644
index 0000000..aadb7a7
--- /dev/null
+++ b/lib/python2.7/json/tests/test_pass3.pyc
Binary files differ
diff --git a/lib/python2.7/json/tests/test_pass3.pyo b/lib/python2.7/json/tests/test_pass3.pyo
new file mode 100644
index 0000000..aadb7a7
--- /dev/null
+++ b/lib/python2.7/json/tests/test_pass3.pyo
Binary files differ
diff --git a/lib/python2.7/json/tests/test_recursion.py b/lib/python2.7/json/tests/test_recursion.py
new file mode 100644
index 0000000..b5221e5
--- /dev/null
+++ b/lib/python2.7/json/tests/test_recursion.py
@@ -0,0 +1,108 @@
+from json.tests import PyTest, CTest
+
+
+class JSONTestObject:
+ pass
+
+
+class TestRecursion(object):
+ def test_listrecursion(self):
+ x = []
+ x.append(x)
+ try:
+ self.dumps(x)
+ except ValueError:
+ pass
+ else:
+ self.fail("didn't raise ValueError on list recursion")
+ x = []
+ y = [x]
+ x.append(y)
+ try:
+ self.dumps(x)
+ except ValueError:
+ pass
+ else:
+ self.fail("didn't raise ValueError on alternating list recursion")
+ y = []
+ x = [y, y]
+ # ensure that the marker is cleared
+ self.dumps(x)
+
+ def test_dictrecursion(self):
+ x = {}
+ x["test"] = x
+ try:
+ self.dumps(x)
+ except ValueError:
+ pass
+ else:
+ self.fail("didn't raise ValueError on dict recursion")
+ x = {}
+ y = {"a": x, "b": x}
+ # ensure that the marker is cleared
+ self.dumps(x)
+
+ def test_defaultrecursion(self):
+ class RecursiveJSONEncoder(self.json.JSONEncoder):
+ recurse = False
+ def default(self, o):
+ if o is JSONTestObject:
+ if self.recurse:
+ return [JSONTestObject]
+ else:
+ return 'JSONTestObject'
+ return pyjson.JSONEncoder.default(o)
+
+ enc = RecursiveJSONEncoder()
+ self.assertEqual(enc.encode(JSONTestObject), '"JSONTestObject"')
+ enc.recurse = True
+ try:
+ enc.encode(JSONTestObject)
+ except ValueError:
+ pass
+ else:
+ self.fail("didn't raise ValueError on default recursion")
+
+
+ def test_highly_nested_objects_decoding(self):
+ # test that loading highly-nested objects doesn't segfault when C
+ # accelerations are used. See #12017
+ # str
+ with self.assertRaises(RuntimeError):
+ self.loads('{"a":' * 100000 + '1' + '}' * 100000)
+ with self.assertRaises(RuntimeError):
+ self.loads('{"a":' * 100000 + '[1]' + '}' * 100000)
+ with self.assertRaises(RuntimeError):
+ self.loads('[' * 100000 + '1' + ']' * 100000)
+ # unicode
+ with self.assertRaises(RuntimeError):
+ self.loads(u'{"a":' * 100000 + u'1' + u'}' * 100000)
+ with self.assertRaises(RuntimeError):
+ self.loads(u'{"a":' * 100000 + u'[1]' + u'}' * 100000)
+ with self.assertRaises(RuntimeError):
+ self.loads(u'[' * 100000 + u'1' + u']' * 100000)
+
+ def test_highly_nested_objects_encoding(self):
+ # See #12051
+ l, d = [], {}
+ for x in xrange(100000):
+ l, d = [l], {'k':d}
+ with self.assertRaises(RuntimeError):
+ self.dumps(l)
+ with self.assertRaises(RuntimeError):
+ self.dumps(d)
+
+ def test_endless_recursion(self):
+ # See #12051
+ class EndlessJSONEncoder(self.json.JSONEncoder):
+ def default(self, o):
+ """If check_circular is False, this will keep adding another list."""
+ return [o]
+
+ with self.assertRaises(RuntimeError):
+ EndlessJSONEncoder(check_circular=False).encode(5j)
+
+
+class TestPyRecursion(TestRecursion, PyTest): pass
+class TestCRecursion(TestRecursion, CTest): pass
diff --git a/lib/python2.7/json/tests/test_recursion.pyc b/lib/python2.7/json/tests/test_recursion.pyc
new file mode 100644
index 0000000..b065fbe
--- /dev/null
+++ b/lib/python2.7/json/tests/test_recursion.pyc
Binary files differ
diff --git a/lib/python2.7/json/tests/test_recursion.pyo b/lib/python2.7/json/tests/test_recursion.pyo
new file mode 100644
index 0000000..b065fbe
--- /dev/null
+++ b/lib/python2.7/json/tests/test_recursion.pyo
Binary files differ
diff --git a/lib/python2.7/json/tests/test_scanstring.py b/lib/python2.7/json/tests/test_scanstring.py
new file mode 100644
index 0000000..4fef8cb
--- /dev/null
+++ b/lib/python2.7/json/tests/test_scanstring.py
@@ -0,0 +1,109 @@
+import sys
+from json.tests import PyTest, CTest
+
+
+class TestScanstring(object):
+ def test_scanstring(self):
+ scanstring = self.json.decoder.scanstring
+ self.assertEqual(
+ scanstring('"z\\ud834\\udd20x"', 1, None, True),
+ (u'z\U0001d120x', 16))
+
+ if sys.maxunicode == 65535:
+ self.assertEqual(
+ scanstring(u'"z\U0001d120x"', 1, None, True),
+ (u'z\U0001d120x', 6))
+ else:
+ self.assertEqual(
+ scanstring(u'"z\U0001d120x"', 1, None, True),
+ (u'z\U0001d120x', 5))
+
+ self.assertEqual(
+ scanstring('"\\u007b"', 1, None, True),
+ (u'{', 8))
+
+ self.assertEqual(
+ scanstring('"A JSON payload should be an object or array, not a string."', 1, None, True),
+ (u'A JSON payload should be an object or array, not a string.', 60))
+
+ self.assertEqual(
+ scanstring('["Unclosed array"', 2, None, True),
+ (u'Unclosed array', 17))
+
+ self.assertEqual(
+ scanstring('["extra comma",]', 2, None, True),
+ (u'extra comma', 14))
+
+ self.assertEqual(
+ scanstring('["double extra comma",,]', 2, None, True),
+ (u'double extra comma', 21))
+
+ self.assertEqual(
+ scanstring('["Comma after the close"],', 2, None, True),
+ (u'Comma after the close', 24))
+
+ self.assertEqual(
+ scanstring('["Extra close"]]', 2, None, True),
+ (u'Extra close', 14))
+
+ self.assertEqual(
+ scanstring('{"Extra comma": true,}', 2, None, True),
+ (u'Extra comma', 14))
+
+ self.assertEqual(
+ scanstring('{"Extra value after close": true} "misplaced quoted value"', 2, None, True),
+ (u'Extra value after close', 26))
+
+ self.assertEqual(
+ scanstring('{"Illegal expression": 1 + 2}', 2, None, True),
+ (u'Illegal expression', 21))
+
+ self.assertEqual(
+ scanstring('{"Illegal invocation": alert()}', 2, None, True),
+ (u'Illegal invocation', 21))
+
+ self.assertEqual(
+ scanstring('{"Numbers cannot have leading zeroes": 013}', 2, None, True),
+ (u'Numbers cannot have leading zeroes', 37))
+
+ self.assertEqual(
+ scanstring('{"Numbers cannot be hex": 0x14}', 2, None, True),
+ (u'Numbers cannot be hex', 24))
+
+ self.assertEqual(
+ scanstring('[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]', 21, None, True),
+ (u'Too deep', 30))
+
+ self.assertEqual(
+ scanstring('{"Missing colon" null}', 2, None, True),
+ (u'Missing colon', 16))
+
+ self.assertEqual(
+ scanstring('{"Double colon":: null}', 2, None, True),
+ (u'Double colon', 15))
+
+ self.assertEqual(
+ scanstring('{"Comma instead of colon", null}', 2, None, True),
+ (u'Comma instead of colon', 25))
+
+ self.assertEqual(
+ scanstring('["Colon instead of comma": false]', 2, None, True),
+ (u'Colon instead of comma', 25))
+
+ self.assertEqual(
+ scanstring('["Bad value", truth]', 2, None, True),
+ (u'Bad value', 12))
+
+ def test_issue3623(self):
+ self.assertRaises(ValueError, self.json.decoder.scanstring, b"xxx", 1,
+ "xxx")
+ self.assertRaises(UnicodeDecodeError,
+ self.json.encoder.encode_basestring_ascii, b"xx\xff")
+
+ def test_overflow(self):
+ with self.assertRaises(OverflowError):
+ self.json.decoder.scanstring(b"xxx", sys.maxsize+1)
+
+
+class TestPyScanstring(TestScanstring, PyTest): pass
+class TestCScanstring(TestScanstring, CTest): pass
diff --git a/lib/python2.7/json/tests/test_scanstring.pyc b/lib/python2.7/json/tests/test_scanstring.pyc
new file mode 100644
index 0000000..a33ae45
--- /dev/null
+++ b/lib/python2.7/json/tests/test_scanstring.pyc
Binary files differ
diff --git a/lib/python2.7/json/tests/test_scanstring.pyo b/lib/python2.7/json/tests/test_scanstring.pyo
new file mode 100644
index 0000000..a33ae45
--- /dev/null
+++ b/lib/python2.7/json/tests/test_scanstring.pyo
Binary files differ
diff --git a/lib/python2.7/json/tests/test_separators.py b/lib/python2.7/json/tests/test_separators.py
new file mode 100644
index 0000000..a4246e1
--- /dev/null
+++ b/lib/python2.7/json/tests/test_separators.py
@@ -0,0 +1,44 @@
+import textwrap
+from json.tests import PyTest, CTest
+
+
+class TestSeparators(object):
+ def test_separators(self):
+ h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh', 'i-vhbjkhnth',
+ {'nifty': 87}, {'field': 'yes', 'morefield': False} ]
+
+ expect = textwrap.dedent("""\
+ [
+ [
+ "blorpie"
+ ] ,
+ [
+ "whoops"
+ ] ,
+ [] ,
+ "d-shtaeou" ,
+ "d-nthiouh" ,
+ "i-vhbjkhnth" ,
+ {
+ "nifty" : 87
+ } ,
+ {
+ "field" : "yes" ,
+ "morefield" : false
+ }
+ ]""")
+
+
+ d1 = self.dumps(h)
+ d2 = self.dumps(h, indent=2, sort_keys=True, separators=(' ,', ' : '))
+
+ h1 = self.loads(d1)
+ h2 = self.loads(d2)
+
+ self.assertEqual(h1, h)
+ self.assertEqual(h2, h)
+ self.assertEqual(d2, expect)
+
+
+class TestPySeparators(TestSeparators, PyTest): pass
+class TestCSeparators(TestSeparators, CTest): pass
diff --git a/lib/python2.7/json/tests/test_separators.pyc b/lib/python2.7/json/tests/test_separators.pyc
new file mode 100644
index 0000000..787ebfe
--- /dev/null
+++ b/lib/python2.7/json/tests/test_separators.pyc
Binary files differ
diff --git a/lib/python2.7/json/tests/test_separators.pyo b/lib/python2.7/json/tests/test_separators.pyo
new file mode 100644
index 0000000..787ebfe
--- /dev/null
+++ b/lib/python2.7/json/tests/test_separators.pyo
Binary files differ
diff --git a/lib/python2.7/json/tests/test_speedups.py b/lib/python2.7/json/tests/test_speedups.py
new file mode 100644
index 0000000..7186a40
--- /dev/null
+++ b/lib/python2.7/json/tests/test_speedups.py
@@ -0,0 +1,23 @@
+from json.tests import CTest
+
+
+class TestSpeedups(CTest):
+ def test_scanstring(self):
+ self.assertEqual(self.json.decoder.scanstring.__module__, "_json")
+ self.assertIs(self.json.decoder.scanstring, self.json.decoder.c_scanstring)
+
+ def test_encode_basestring_ascii(self):
+ self.assertEqual(self.json.encoder.encode_basestring_ascii.__module__,
+ "_json")
+ self.assertIs(self.json.encoder.encode_basestring_ascii,
+ self.json.encoder.c_encode_basestring_ascii)
+
+class TestDecode(CTest):
+ def test_make_scanner(self):
+ self.assertRaises(AttributeError, self.json.scanner.c_make_scanner, 1)
+
+ def test_make_encoder(self):
+ self.assertRaises(TypeError, self.json.encoder.c_make_encoder,
+ None,
+ "\xCD\x7D\x3D\x4E\x12\x4C\xF9\x79\xD7\x52\xBA\x82\xF2\x27\x4A\x7D\xA0\xCA\x75",
+ None)
diff --git a/lib/python2.7/json/tests/test_speedups.pyc b/lib/python2.7/json/tests/test_speedups.pyc
new file mode 100644
index 0000000..9f14045
--- /dev/null
+++ b/lib/python2.7/json/tests/test_speedups.pyc
Binary files differ
diff --git a/lib/python2.7/json/tests/test_speedups.pyo b/lib/python2.7/json/tests/test_speedups.pyo
new file mode 100644
index 0000000..9f14045
--- /dev/null
+++ b/lib/python2.7/json/tests/test_speedups.pyo
Binary files differ
diff --git a/lib/python2.7/json/tests/test_tool.py b/lib/python2.7/json/tests/test_tool.py
new file mode 100644
index 0000000..27dfb84
--- /dev/null
+++ b/lib/python2.7/json/tests/test_tool.py
@@ -0,0 +1,69 @@
+import os
+import sys
+import textwrap
+import unittest
+import subprocess
+from test import test_support
+from test.script_helper import assert_python_ok
+
+class TestTool(unittest.TestCase):
+ data = """
+
+ [["blorpie"],[ "whoops" ] , [
+ ],\t"d-shtaeou",\r"d-nthiouh",
+ "i-vhbjkhnth", {"nifty":87}, {"morefield" :\tfalse,"field"
+ :"yes"} ]
+ """
+
+ expect = textwrap.dedent("""\
+ [
+ [
+ "blorpie"
+ ],
+ [
+ "whoops"
+ ],
+ [],
+ "d-shtaeou",
+ "d-nthiouh",
+ "i-vhbjkhnth",
+ {
+ "nifty": 87
+ },
+ {
+ "field": "yes",
+ "morefield": false
+ }
+ ]
+ """)
+
+ def test_stdin_stdout(self):
+ proc = subprocess.Popen(
+ (sys.executable, '-m', 'json.tool'),
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ out, err = proc.communicate(self.data.encode())
+ self.assertEqual(out.splitlines(), self.expect.encode().splitlines())
+ self.assertEqual(err, None)
+
+ def _create_infile(self):
+ infile = test_support.TESTFN
+ with open(infile, "w") as fp:
+ self.addCleanup(os.remove, infile)
+ fp.write(self.data)
+ return infile
+
+ def test_infile_stdout(self):
+ infile = self._create_infile()
+ rc, out, err = assert_python_ok('-m', 'json.tool', infile)
+ self.assertEqual(out.splitlines(), self.expect.encode().splitlines())
+ self.assertEqual(err, b'')
+
+ def test_infile_outfile(self):
+ infile = self._create_infile()
+ outfile = test_support.TESTFN + '.out'
+ rc, out, err = assert_python_ok('-m', 'json.tool', infile, outfile)
+ self.addCleanup(os.remove, outfile)
+ with open(outfile, "r") as fp:
+ self.assertEqual(fp.read(), self.expect)
+ self.assertEqual(out, b'')
+ self.assertEqual(err, b'')
diff --git a/lib/python2.7/json/tests/test_tool.pyc b/lib/python2.7/json/tests/test_tool.pyc
new file mode 100644
index 0000000..c378e39
--- /dev/null
+++ b/lib/python2.7/json/tests/test_tool.pyc
Binary files differ
diff --git a/lib/python2.7/json/tests/test_tool.pyo b/lib/python2.7/json/tests/test_tool.pyo
new file mode 100644
index 0000000..c378e39
--- /dev/null
+++ b/lib/python2.7/json/tests/test_tool.pyo
Binary files differ
diff --git a/lib/python2.7/json/tests/test_unicode.py b/lib/python2.7/json/tests/test_unicode.py
new file mode 100644
index 0000000..e90f158
--- /dev/null
+++ b/lib/python2.7/json/tests/test_unicode.py
@@ -0,0 +1,89 @@
+from collections import OrderedDict
+from json.tests import PyTest, CTest
+
+
+class TestUnicode(object):
+ def test_encoding1(self):
+ encoder = self.json.JSONEncoder(encoding='utf-8')
+ u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
+ s = u.encode('utf-8')
+ ju = encoder.encode(u)
+ js = encoder.encode(s)
+ self.assertEqual(ju, js)
+
+ def test_encoding2(self):
+ u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
+ s = u.encode('utf-8')
+ ju = self.dumps(u, encoding='utf-8')
+ js = self.dumps(s, encoding='utf-8')
+ self.assertEqual(ju, js)
+
+ def test_encoding3(self):
+ u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
+ j = self.dumps(u)
+ self.assertEqual(j, '"\\u03b1\\u03a9"')
+
+ def test_encoding4(self):
+ u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
+ j = self.dumps([u])
+ self.assertEqual(j, '["\\u03b1\\u03a9"]')
+
+ def test_encoding5(self):
+ u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
+ j = self.dumps(u, ensure_ascii=False)
+ self.assertEqual(j, u'"{0}"'.format(u))
+
+ def test_encoding6(self):
+ u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
+ j = self.dumps([u], ensure_ascii=False)
+ self.assertEqual(j, u'["{0}"]'.format(u))
+
+ def test_big_unicode_encode(self):
+ u = u'\U0001d120'
+ self.assertEqual(self.dumps(u), '"\\ud834\\udd20"')
+ self.assertEqual(self.dumps(u, ensure_ascii=False), u'"\U0001d120"')
+
+ def test_big_unicode_decode(self):
+ u = u'z\U0001d120x'
+ self.assertEqual(self.loads('"' + u + '"'), u)
+ self.assertEqual(self.loads('"z\\ud834\\udd20x"'), u)
+
+ def test_unicode_decode(self):
+ for i in range(0, 0xd7ff):
+ u = unichr(i)
+ s = '"\\u{0:04x}"'.format(i)
+ self.assertEqual(self.loads(s), u)
+
+ def test_object_pairs_hook_with_unicode(self):
+ s = u'{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}'
+ p = [(u"xkd", 1), (u"kcw", 2), (u"art", 3), (u"hxm", 4),
+ (u"qrt", 5), (u"pad", 6), (u"hoy", 7)]
+ self.assertEqual(self.loads(s), eval(s))
+ self.assertEqual(self.loads(s, object_pairs_hook = lambda x: x), p)
+ od = self.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(self.loads(s,
+ object_pairs_hook = OrderedDict,
+ object_hook = lambda x: None),
+ OrderedDict(p))
+
+ def test_default_encoding(self):
+ self.assertEqual(self.loads(u'{"a": "\xe9"}'.encode('utf-8')),
+ {'a': u'\xe9'})
+
+ def test_unicode_preservation(self):
+ self.assertEqual(type(self.loads(u'""')), unicode)
+ self.assertEqual(type(self.loads(u'"a"')), unicode)
+ self.assertEqual(type(self.loads(u'["a"]')[0]), unicode)
+ # Issue 10038.
+ self.assertEqual(type(self.loads('"foo"')), unicode)
+
+ def test_bad_encoding(self):
+ self.assertRaises(UnicodeEncodeError, self.loads, '"a"', u"rat\xe9")
+ self.assertRaises(TypeError, self.loads, '"a"', 1)
+
+
+class TestPyUnicode(TestUnicode, PyTest): pass
+class TestCUnicode(TestUnicode, CTest): pass
diff --git a/lib/python2.7/json/tests/test_unicode.pyc b/lib/python2.7/json/tests/test_unicode.pyc
new file mode 100644
index 0000000..10ea509
--- /dev/null
+++ b/lib/python2.7/json/tests/test_unicode.pyc
Binary files differ
diff --git a/lib/python2.7/json/tests/test_unicode.pyo b/lib/python2.7/json/tests/test_unicode.pyo
new file mode 100644
index 0000000..10ea509
--- /dev/null
+++ b/lib/python2.7/json/tests/test_unicode.pyo
Binary files differ