mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-07 02:10:27 +00:00
add test_json
and also skip pure-python tests for some packages that have C implementations available.
This commit is contained in:
parent
77b70ba193
commit
f29f5a3887
9 changed files with 28 additions and 29 deletions
4
third_party/python/Lib/test/test_bisect.py
vendored
4
third_party/python/Lib/test/test_bisect.py
vendored
|
@ -199,6 +199,7 @@ class TestBisect:
|
|||
self.module.insort(a=data, x=25, lo=1, hi=3)
|
||||
self.assertEqual(data, [10, 20, 25, 25, 25, 30, 40, 50])
|
||||
|
||||
@unittest.skipIf(c_bisect, "skip pure-python test if C impl is present")
|
||||
class TestBisectPython(TestBisect, unittest.TestCase):
|
||||
module = py_bisect
|
||||
|
||||
|
@ -234,6 +235,7 @@ class TestInsort:
|
|||
self.module.insort_right(lst, 5)
|
||||
self.assertEqual([5, 10], lst.data)
|
||||
|
||||
@unittest.skipIf(c_bisect, "skip pure-python test if C impl is present")
|
||||
class TestInsortPython(TestInsort, unittest.TestCase):
|
||||
module = py_bisect
|
||||
|
||||
|
@ -289,6 +291,7 @@ class TestErrorHandling:
|
|||
self.module.insort_left, self.module.insort_right):
|
||||
self.assertRaises(TypeError, f, 10)
|
||||
|
||||
@unittest.skipIf(c_bisect, "skip pure-python test if C impl is present")
|
||||
class TestErrorHandlingPython(TestErrorHandling, unittest.TestCase):
|
||||
module = py_bisect
|
||||
|
||||
|
@ -316,6 +319,7 @@ class TestDocExample:
|
|||
self.assertEqual(data[bisect_left(keys, 5)], ('red', 5))
|
||||
self.assertEqual(data[bisect_left(keys, 8)], ('yellow', 8))
|
||||
|
||||
@unittest.skipIf(c_bisect, "skip pure-python test if C impl is present")
|
||||
class TestDocExamplePython(TestDocExample, unittest.TestCase):
|
||||
module = py_bisect
|
||||
|
||||
|
|
|
@ -431,7 +431,7 @@ class TestPartialC(TestPartial, unittest.TestCase):
|
|||
self.assertIn('astr', r)
|
||||
self.assertIn("['sth']", r)
|
||||
|
||||
|
||||
@unittest.skipIf(c_functools, "skip pure-python test if C impl is present")
|
||||
class TestPartialPy(TestPartial, unittest.TestCase):
|
||||
partial = py_functools.partial
|
||||
|
||||
|
@ -458,6 +458,7 @@ class TestPartialCSubclass(TestPartialC):
|
|||
# partial subclasses are not optimized for nested calls
|
||||
test_nested_optimization = None
|
||||
|
||||
@unittest.skipIf(c_functools, "skip pure-python test if C impl is present")
|
||||
class TestPartialPySubclass(TestPartialPy):
|
||||
partial = PyPartialSubclass
|
||||
|
||||
|
@ -928,6 +929,7 @@ class TestCmpToKeyC(TestCmpToKey, unittest.TestCase):
|
|||
cmp_to_key = c_functools.cmp_to_key
|
||||
|
||||
|
||||
@unittest.skipIf(c_functools, "skip pure-python test if C impl is present")
|
||||
class TestCmpToKeyPy(TestCmpToKey, unittest.TestCase):
|
||||
cmp_to_key = staticmethod(py_functools.cmp_to_key)
|
||||
|
||||
|
@ -1565,6 +1567,7 @@ def c_cached_func(x, y):
|
|||
return 3 * x + y
|
||||
|
||||
|
||||
@unittest.skipIf(c_functools, "skip pure-python test if C impl is present")
|
||||
class TestLRUPy(TestLRU, unittest.TestCase):
|
||||
module = py_functools
|
||||
cached_func = py_cached_func,
|
||||
|
|
|
@ -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 = """
|
||||
|
|
1
third_party/python/Lib/test/test_operator.py
vendored
1
third_party/python/Lib/test/test_operator.py
vendored
|
@ -496,6 +496,7 @@ class OperatorTestCase:
|
|||
if dunder:
|
||||
self.assertIs(dunder, orig)
|
||||
|
||||
@unittest.skipIf(c_operator, "skip pure-python test if C impl is present")
|
||||
class PyOperatorTestCase(OperatorTestCase, unittest.TestCase):
|
||||
module = py_operator
|
||||
|
||||
|
|
|
@ -651,6 +651,7 @@ class OrderedDictTests:
|
|||
support.check_free_after_iterating(self, lambda d: iter(d.items()), self.OrderedDict)
|
||||
|
||||
|
||||
@unittest.skipIf(c_coll, "skip pure-python test if C impl is present")
|
||||
class PurePythonOrderedDictTests(OrderedDictTests, unittest.TestCase):
|
||||
|
||||
module = py_coll
|
||||
|
@ -750,6 +751,7 @@ class CPythonOrderedDictTests(OrderedDictTests, unittest.TestCase):
|
|||
self.assertEqual(list(it), expected)
|
||||
|
||||
|
||||
@unittest.skipIf(c_coll, "skip pure-python test if C impl is present")
|
||||
class PurePythonOrderedDictSubclassTests(PurePythonOrderedDictTests):
|
||||
|
||||
module = py_coll
|
||||
|
@ -764,6 +766,7 @@ class CPythonOrderedDictSubclassTests(CPythonOrderedDictTests):
|
|||
pass
|
||||
|
||||
|
||||
@unittest.skipIf(c_coll, "skip pure-python test if C impl is present")
|
||||
class PurePythonGeneralMappingTests(mapping_tests.BasicTestMappingProtocol):
|
||||
|
||||
@classmethod
|
||||
|
@ -787,6 +790,7 @@ class CPythonGeneralMappingTests(mapping_tests.BasicTestMappingProtocol):
|
|||
self.assertRaises(KeyError, d.popitem)
|
||||
|
||||
|
||||
@unittest.skipIf(c_coll, "skip pure-python test if C impl is present")
|
||||
class PurePythonSubclassMappingTests(mapping_tests.BasicTestMappingProtocol):
|
||||
|
||||
@classmethod
|
||||
|
|
6
third_party/python/Lib/test/test_pickle.py
vendored
6
third_party/python/Lib/test/test_pickle.py
vendored
|
@ -502,15 +502,11 @@ def test_main():
|
|||
tests.extend([CPickleTests, CUnpicklerTests])
|
||||
support.run_unittest(*tests)
|
||||
else:
|
||||
tests = [PyPickleTests, PyUnpicklerTests, PyPicklerTests,
|
||||
PyPersPicklerTests, PyIdPersPicklerTests,
|
||||
PyDispatchTableTests, PyChainDispatchTableTests,
|
||||
CompatPickleTests]
|
||||
tests = []
|
||||
if has_c_implementation:
|
||||
tests.extend([CPickleTests, CUnpicklerTests, CPicklerTests,
|
||||
CPersPicklerTests, CIdPersPicklerTests,
|
||||
CDumpPickle_LoadPickle, DumpPickle_CLoadPickle,
|
||||
PyPicklerUnpicklerObjectTests,
|
||||
CPicklerUnpicklerObjectTests,
|
||||
CDispatchTableTests, CChainDispatchTableTests,
|
||||
InMemoryPickleTests, SizeofTests])
|
||||
|
|
22
third_party/python/python.mk
vendored
22
third_party/python/python.mk
vendored
|
@ -1285,23 +1285,6 @@ THIRD_PARTY_PYTHON_PYTEST_A_PYS = \
|
|||
third_party/python/Lib/test/support/script_helper.py \
|
||||
third_party/python/Lib/test/support/testresult.py \
|
||||
third_party/python/Lib/test/test_dummy_thread.py \
|
||||
third_party/python/Lib/test/test_json/test_decode.py \
|
||||
third_party/python/Lib/test/test_json/test_default.py \
|
||||
third_party/python/Lib/test/test_json/test_dump.py \
|
||||
third_party/python/Lib/test/test_json/test_encode_basestring_ascii.py \
|
||||
third_party/python/Lib/test/test_json/test_enum.py \
|
||||
third_party/python/Lib/test/test_json/test_fail.py \
|
||||
third_party/python/Lib/test/test_json/test_float.py \
|
||||
third_party/python/Lib/test/test_json/test_indent.py \
|
||||
third_party/python/Lib/test/test_json/test_pass1.py \
|
||||
third_party/python/Lib/test/test_json/test_pass2.py \
|
||||
third_party/python/Lib/test/test_json/test_pass3.py \
|
||||
third_party/python/Lib/test/test_json/test_recursion.py \
|
||||
third_party/python/Lib/test/test_json/test_scanstring.py \
|
||||
third_party/python/Lib/test/test_json/test_separators.py \
|
||||
third_party/python/Lib/test/test_json/test_speedups.py \
|
||||
third_party/python/Lib/test/test_json/test_tool.py \
|
||||
third_party/python/Lib/test/test_json/test_unicode.py \
|
||||
third_party/python/Lib/test/test_warnings/data/import_warning.py \
|
||||
third_party/python/Lib/test/test_warnings/data/stacklevel.py \
|
||||
third_party/python/Lib/test/testcodec.py \
|
||||
|
@ -1872,6 +1855,7 @@ THIRD_PARTY_PYTHON_PYTEST_PYMAINS = \
|
|||
third_party/python/Lib/test/test_iter.py \
|
||||
third_party/python/Lib/test/test_iterlen.py \
|
||||
third_party/python/Lib/test/test_itertools.py \
|
||||
third_party/python/Lib/test/test_json/__main__.py \
|
||||
third_party/python/Lib/test/test_kdf.py \
|
||||
third_party/python/Lib/test/test_keyword.py \
|
||||
third_party/python/Lib/test/test_keywordonlyarg.py \
|
||||
|
@ -2537,6 +2521,10 @@ o/$(MODE)/third_party/python/Lib/test/test_iter.py.runs: \
|
|||
o/$(MODE)/third_party/python/pythontester.com.dbg
|
||||
@$(COMPILE) -ACHECK -tT$@ $(PYHARNESSARGS) $< -m test.test_iter $(PYTESTARGS)
|
||||
|
||||
o/$(MODE)/third_party/python/Lib/test/test_json/__main__.py.runs: \
|
||||
o/$(MODE)/third_party/python/pythontester.com.dbg
|
||||
@$(COMPILE) -ACHECK -tT$@ $(PYHARNESSARGS) $< -m test.test_json $(PYTESTARGS)
|
||||
|
||||
o/$(MODE)/third_party/python/Lib/test/test_tarfile.py.runs: \
|
||||
o/$(MODE)/third_party/python/pythontester.com.dbg
|
||||
@$(COMPILE) -ACHECK -tT$@ $(PYHARNESSARGS) $< -m test.test_tarfile $(PYTESTARGS)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue