mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
Add Python JSON tests (#407)
This commit is contained in:
parent
d25a67f4eb
commit
f6df29cc3d
24 changed files with 536 additions and 345 deletions
|
@ -12,6 +12,7 @@ pyjson = support.import_fresh_module('json', blocked=['_json'])
|
|||
cjson.JSONDecodeError = cjson.decoder.JSONDecodeError = json.JSONDecodeError
|
||||
|
||||
# create two base classes that will be used by the other tests
|
||||
@unittest.skipIf(cjson, '_json is available, no need for pure-python tests')
|
||||
class PyTest(unittest.TestCase):
|
||||
json = pyjson
|
||||
loads = staticmethod(pyjson.loads)
|
||||
|
|
|
@ -70,11 +70,11 @@ class TestRecursion:
|
|||
def test_highly_nested_objects_decoding(self):
|
||||
# test that loading highly-nested objects doesn't segfault when C
|
||||
# accelerations are used. See #12017
|
||||
with self.assertRaises(RecursionError):
|
||||
with self.assertRaises((RecursionError, MemoryError)):
|
||||
self.loads('{"a":' * 100000 + '1' + '}' * 100000)
|
||||
with self.assertRaises(RecursionError):
|
||||
with self.assertRaises((RecursionError, MemoryError)):
|
||||
self.loads('{"a":' * 100000 + '[1]' + '}' * 100000)
|
||||
with self.assertRaises(RecursionError):
|
||||
with self.assertRaises((RecursionError, MemoryError)):
|
||||
self.loads('[' * 100000 + '1' + ']' * 100000)
|
||||
|
||||
def test_highly_nested_objects_encoding(self):
|
||||
|
@ -82,9 +82,9 @@ class TestRecursion:
|
|||
l, d = [], {}
|
||||
for x in range(100000):
|
||||
l, d = [l], {'k':d}
|
||||
with self.assertRaises(RecursionError):
|
||||
with self.assertRaises((RecursionError, MemoryError)):
|
||||
self.dumps(l)
|
||||
with self.assertRaises(RecursionError):
|
||||
with self.assertRaises((RecursionError, MemoryError)):
|
||||
self.dumps(d)
|
||||
|
||||
def test_endless_recursion(self):
|
||||
|
@ -94,7 +94,7 @@ class TestRecursion:
|
|||
"""If check_circular is False, this will keep adding another list."""
|
||||
return [o]
|
||||
|
||||
with self.assertRaises(RecursionError):
|
||||
with self.assertRaises((RecursionError, MemoryError)):
|
||||
EndlessJSONEncoder(check_circular=False).encode(5j)
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@ from subprocess import Popen, PIPE
|
|||
from test import support
|
||||
from test.support.script_helper import assert_python_ok
|
||||
|
||||
if __name__ == "PYOBJ.COM":
|
||||
import json.tool
|
||||
|
||||
class TestTool(unittest.TestCase):
|
||||
data = """
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue