Skip to content

Commit e7a6285

Browse files
authored
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().
1 parent 18ea973 commit e7a6285

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

Lib/test/test_json/test_recursion.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from test import support
12
from test.test_json import PyTest, CTest
23

34

@@ -69,21 +70,26 @@ def test_highly_nested_objects_decoding(self):
6970
# test that loading highly-nested objects doesn't segfault when C
7071
# accelerations are used. See #12017
7172
with self.assertRaises(RecursionError):
72-
self.loads('{"a":' * 100000 + '1' + '}' * 100000)
73+
with support.infinite_recursion():
74+
self.loads('{"a":' * 100000 + '1' + '}' * 100000)
7375
with self.assertRaises(RecursionError):
74-
self.loads('{"a":' * 100000 + '[1]' + '}' * 100000)
76+
with support.infinite_recursion():
77+
self.loads('{"a":' * 100000 + '[1]' + '}' * 100000)
7578
with self.assertRaises(RecursionError):
76-
self.loads('[' * 100000 + '1' + ']' * 100000)
79+
with support.infinite_recursion():
80+
self.loads('[' * 100000 + '1' + ']' * 100000)
7781

7882
def test_highly_nested_objects_encoding(self):
7983
# See #12051
8084
l, d = [], {}
8185
for x in range(100000):
8286
l, d = [l], {'k':d}
8387
with self.assertRaises(RecursionError):
84-
self.dumps(l)
88+
with support.infinite_recursion():
89+
self.dumps(l)
8590
with self.assertRaises(RecursionError):
86-
self.dumps(d)
91+
with support.infinite_recursion():
92+
self.dumps(d)
8793

8894
def test_endless_recursion(self):
8995
# See #12051
@@ -93,7 +99,8 @@ def default(self, o):
9399
return [o]
94100

95101
with self.assertRaises(RecursionError):
96-
EndlessJSONEncoder(check_circular=False).encode(5j)
102+
with support.infinite_recursion():
103+
EndlessJSONEncoder(check_circular=False).encode(5j)
97104

98105

99106
class TestPyRecursion(TestRecursion, PyTest): pass
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``test_json`` tests checking for :exc:`RecursionError`: modify these tests
2+
to use ``support.infinite_recursion()``. Patch by Victor Stinner.

0 commit comments

Comments
 (0)