◐ Shell
clean mode source ↗

[3.10] bpo-46542: test_json uses support.infinite_recursion() (GH-30972) by miss-islington · Pull Request #30973 · python/cpython

@@ -1,3 +1,4 @@ from test import support from test.test_json import PyTest, CTest

Expand Down Expand Up @@ -69,21 +70,26 @@ 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): self.loads('{"a":' * 100000 + '1' + '}' * 100000) with support.infinite_recursion(): self.loads('{"a":' * 100000 + '1' + '}' * 100000) with self.assertRaises(RecursionError): self.loads('{"a":' * 100000 + '[1]' + '}' * 100000) with support.infinite_recursion(): self.loads('{"a":' * 100000 + '[1]' + '}' * 100000) with self.assertRaises(RecursionError): self.loads('[' * 100000 + '1' + ']' * 100000) with support.infinite_recursion(): self.loads('[' * 100000 + '1' + ']' * 100000)
def test_highly_nested_objects_encoding(self): # See #12051 l, d = [], {} for x in range(100000): l, d = [l], {'k':d} with self.assertRaises(RecursionError): self.dumps(l) with support.infinite_recursion(): self.dumps(l) with self.assertRaises(RecursionError): self.dumps(d) with support.infinite_recursion(): self.dumps(d)
def test_endless_recursion(self): # See #12051 Expand All @@ -93,7 +99,8 @@ def default(self, o): return [o]
with self.assertRaises(RecursionError): EndlessJSONEncoder(check_circular=False).encode(5j) with support.infinite_recursion(): EndlessJSONEncoder(check_circular=False).encode(5j)

class TestPyRecursion(TestRecursion, PyTest): pass Expand Down