diff options
author | Victor Stinner <vstinner@python.org> | 2022-01-28 00:35:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-28 00:35:13 (GMT) |
commit | e7a6285f1be18992191599792524d3aa6aedfa55 (patch) | |
tree | b9589053c722ce2c95b207f6d9011add8288eaee /Lib | |
parent | 18ea973c21ee4a6adc26be41027881043fa498eb (diff) | |
download | cpython-e7a6285f1be18992191599792524d3aa6aedfa55.zip cpython-e7a6285f1be18992191599792524d3aa6aedfa55.tar.gz cpython-e7a6285f1be18992191599792524d3aa6aedfa55.tar.bz2 |
bpo-46542: test_json uses support.infinite_recursion() (GH-30972)
Fix test_json tests checking for RecursionError: modify these tests
to use support.infinite_recursion().
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_json/test_recursion.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/Lib/test/test_json/test_recursion.py b/Lib/test/test_json/test_recursion.py index 543c628..9919d7f 100644 --- a/Lib/test/test_json/test_recursion.py +++ b/Lib/test/test_json/test_recursion.py @@ -1,3 +1,4 @@ +from test import support from test.test_json import PyTest, CTest @@ -69,11 +70,14 @@ class TestRecursion: # 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 @@ -81,9 +85,11 @@ class TestRecursion: 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 @@ -93,7 +99,8 @@ class TestRecursion: 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 |