[Python-checkins] bpo-46542: test_json uses support.infinite_recursion() (GH-30972)
miss-islington
webhook-mailer at python.org
Thu Jan 27 19:57:22 EST 2022
https://github.com/python/cpython/commit/20f53136679e260466a765de5befa3b9db396c9e
commit: 20f53136679e260466a765de5befa3b9db396c9e
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-01-27T16:57:07-08:00
summary:
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().
(cherry picked from commit e7a6285f1be18992191599792524d3aa6aedfa55)
Co-authored-by: Victor Stinner <vstinner at python.org>
files:
A Misc/NEWS.d/next/Tests/2022-01-28-01-17-10.bpo-46542.xRLTdj.rst
M Lib/test/test_json/test_recursion.py
diff --git a/Lib/test/test_json/test_recursion.py b/Lib/test/test_json/test_recursion.py
index 543c62839b2cd..9919d7fbe54ef 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 @@ 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
@@ -81,9 +85,11 @@ def test_highly_nested_objects_encoding(self):
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 @@ 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
diff --git a/Misc/NEWS.d/next/Tests/2022-01-28-01-17-10.bpo-46542.xRLTdj.rst b/Misc/NEWS.d/next/Tests/2022-01-28-01-17-10.bpo-46542.xRLTdj.rst
new file mode 100644
index 0000000000000..c6b64ce017b6c
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2022-01-28-01-17-10.bpo-46542.xRLTdj.rst
@@ -0,0 +1,2 @@
+Fix ``test_json`` tests checking for :exc:`RecursionError`: modify these tests
+to use ``support.infinite_recursion()``. Patch by Victor Stinner.
More information about the Python-checkins
mailing list