]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Python/Python-2.7.10/Lib/json/tests/test_recursion.py
1 from json
.tests
import PyTest
, CTest
8 class TestRecursion(object):
9 def test_listrecursion(self
):
17 self
.fail("didn't raise ValueError on list recursion")
26 self
.fail("didn't raise ValueError on alternating list recursion")
29 # ensure that the marker is cleared
32 def test_dictrecursion(self
):
40 self
.fail("didn't raise ValueError on dict recursion")
43 # ensure that the marker is cleared
46 def test_defaultrecursion(self
):
47 class RecursiveJSONEncoder(self
.json
.JSONEncoder
):
50 if o
is JSONTestObject
:
52 return [JSONTestObject
]
54 return 'JSONTestObject'
55 return pyjson
.JSONEncoder
.default(o
)
57 enc
= RecursiveJSONEncoder()
58 self
.assertEqual(enc
.encode(JSONTestObject
), '"JSONTestObject"')
61 enc
.encode(JSONTestObject
)
65 self
.fail("didn't raise ValueError on default recursion")
68 def test_highly_nested_objects_decoding(self
):
69 # test that loading highly-nested objects doesn't segfault when C
70 # accelerations are used. See #12017
72 with self
.assertRaises(RuntimeError):
73 self
.loads('{"a":' * 100000 + '1' + '}' * 100000)
74 with self
.assertRaises(RuntimeError):
75 self
.loads('{"a":' * 100000 + '[1]' + '}' * 100000)
76 with self
.assertRaises(RuntimeError):
77 self
.loads('[' * 100000 + '1' + ']' * 100000)
79 with self
.assertRaises(RuntimeError):
80 self
.loads(u
'{"a":' * 100000 + u
'1' + u
'}' * 100000)
81 with self
.assertRaises(RuntimeError):
82 self
.loads(u
'{"a":' * 100000 + u
'[1]' + u
'}' * 100000)
83 with self
.assertRaises(RuntimeError):
84 self
.loads(u
'[' * 100000 + u
'1' + u
']' * 100000)
86 def test_highly_nested_objects_encoding(self
):
89 for x
in xrange(100000):
91 with self
.assertRaises(RuntimeError):
93 with self
.assertRaises(RuntimeError):
96 def test_endless_recursion(self
):
98 class EndlessJSONEncoder(self
.json
.JSONEncoder
):
100 """If check_circular is False, this will keep adding another list."""
103 with self
.assertRaises(RuntimeError):
104 EndlessJSONEncoder(check_circular
=False).encode(5j
)
107 class TestPyRecursion(TestRecursion
, PyTest
): pass
108 class TestCRecursion(TestRecursion
, CTest
): pass