summaryrefslogtreecommitdiff
path: root/lib/python2.7/json/tests
diff options
context:
space:
mode:
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/test_check_circular.py34
-rw-r--r--lib/python2.7/json/tests/test_decode.py64
-rw-r--r--lib/python2.7/json/tests/test_default.py12
-rw-r--r--lib/python2.7/json/tests/test_dump.py32
-rw-r--r--lib/python2.7/json/tests/test_encode_basestring_ascii.py41
-rw-r--r--lib/python2.7/json/tests/test_fail.py105
-rw-r--r--lib/python2.7/json/tests/test_float.py37
-rw-r--r--lib/python2.7/json/tests/test_indent.py60
-rw-r--r--lib/python2.7/json/tests/test_pass1.py75
-rw-r--r--lib/python2.7/json/tests/test_pass2.py18
-rw-r--r--lib/python2.7/json/tests/test_pass3.py24
-rw-r--r--lib/python2.7/json/tests/test_recursion.py108
-rw-r--r--lib/python2.7/json/tests/test_scanstring.py109
-rw-r--r--lib/python2.7/json/tests/test_separators.py44
-rw-r--r--lib/python2.7/json/tests/test_speedups.py23
-rw-r--r--lib/python2.7/json/tests/test_tool.py69
-rw-r--r--lib/python2.7/json/tests/test_unicode.py89
18 files changed, 0 insertions, 1017 deletions
diff --git a/lib/python2.7/json/tests/__init__.py b/lib/python2.7/json/tests/__init__.py
deleted file mode 100644
index 90cb2b7..0000000
--- a/lib/python2.7/json/tests/__init__.py
+++ /dev/null
@@ -1,73 +0,0 @@
-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/test_check_circular.py b/lib/python2.7/json/tests/test_check_circular.py
deleted file mode 100644
index 3ad3d24..0000000
--- a/lib/python2.7/json/tests/test_check_circular.py
+++ /dev/null
@@ -1,34 +0,0 @@
-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_decode.py b/lib/python2.7/json/tests/test_decode.py
deleted file mode 100644
index ffd1aa4..0000000
--- a/lib/python2.7/json/tests/test_decode.py
+++ /dev/null
@@ -1,64 +0,0 @@
-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_default.py b/lib/python2.7/json/tests/test_default.py
deleted file mode 100644
index c2a07f6..0000000
--- a/lib/python2.7/json/tests/test_default.py
+++ /dev/null
@@ -1,12 +0,0 @@
-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_dump.py b/lib/python2.7/json/tests/test_dump.py
deleted file mode 100644
index cd92569..0000000
--- a/lib/python2.7/json/tests/test_dump.py
+++ /dev/null
@@ -1,32 +0,0 @@
-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_encode_basestring_ascii.py b/lib/python2.7/json/tests/test_encode_basestring_ascii.py
deleted file mode 100644
index 9f9d5a5..0000000
--- a/lib/python2.7/json/tests/test_encode_basestring_ascii.py
+++ /dev/null
@@ -1,41 +0,0 @@
-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_fail.py b/lib/python2.7/json/tests/test_fail.py
deleted file mode 100644
index e31b379..0000000
--- a/lib/python2.7/json/tests/test_fail.py
+++ /dev/null
@@ -1,105 +0,0 @@
-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_float.py b/lib/python2.7/json/tests/test_float.py
deleted file mode 100644
index 049f9ae..0000000
--- a/lib/python2.7/json/tests/test_float.py
+++ /dev/null
@@ -1,37 +0,0 @@
-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_indent.py b/lib/python2.7/json/tests/test_indent.py
deleted file mode 100644
index 9b18761..0000000
--- a/lib/python2.7/json/tests/test_indent.py
+++ /dev/null
@@ -1,60 +0,0 @@
-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_pass1.py b/lib/python2.7/json/tests/test_pass1.py
deleted file mode 100644
index df8259b..0000000
--- a/lib/python2.7/json/tests/test_pass1.py
+++ /dev/null
@@ -1,75 +0,0 @@
-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_pass2.py b/lib/python2.7/json/tests/test_pass2.py
deleted file mode 100644
index a2bb6d7..0000000
--- a/lib/python2.7/json/tests/test_pass2.py
+++ /dev/null
@@ -1,18 +0,0 @@
-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_pass3.py b/lib/python2.7/json/tests/test_pass3.py
deleted file mode 100644
index 221f9a0..0000000
--- a/lib/python2.7/json/tests/test_pass3.py
+++ /dev/null
@@ -1,24 +0,0 @@
-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_recursion.py b/lib/python2.7/json/tests/test_recursion.py
deleted file mode 100644
index b5221e5..0000000
--- a/lib/python2.7/json/tests/test_recursion.py
+++ /dev/null
@@ -1,108 +0,0 @@
-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_scanstring.py b/lib/python2.7/json/tests/test_scanstring.py
deleted file mode 100644
index 4fef8cb..0000000
--- a/lib/python2.7/json/tests/test_scanstring.py
+++ /dev/null
@@ -1,109 +0,0 @@
-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_separators.py b/lib/python2.7/json/tests/test_separators.py
deleted file mode 100644
index a4246e1..0000000
--- a/lib/python2.7/json/tests/test_separators.py
+++ /dev/null
@@ -1,44 +0,0 @@
-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_speedups.py b/lib/python2.7/json/tests/test_speedups.py
deleted file mode 100644
index 7186a40..0000000
--- a/lib/python2.7/json/tests/test_speedups.py
+++ /dev/null
@@ -1,23 +0,0 @@
-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_tool.py b/lib/python2.7/json/tests/test_tool.py
deleted file mode 100644
index 27dfb84..0000000
--- a/lib/python2.7/json/tests/test_tool.py
+++ /dev/null
@@ -1,69 +0,0 @@
-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_unicode.py b/lib/python2.7/json/tests/test_unicode.py
deleted file mode 100644
index e90f158..0000000
--- a/lib/python2.7/json/tests/test_unicode.py
+++ /dev/null
@@ -1,89 +0,0 @@
-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