Skip to content

Commit 857a7bb

Browse files
committed
Make tests more robust to low stacks
1 parent 9e0cc67 commit 857a7bb

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

Lib/test/pythoninfo.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,6 @@ def collect_testcapi(info_add):
684684
for name in (
685685
'LONG_MAX', # always 32-bit on Windows, 64-bit on 64-bit Unix
686686
'PY_SSIZE_T_MAX',
687-
'Py_C_RECURSION_LIMIT',
688687
'SIZEOF_TIME_T', # 32-bit or 64-bit depending on the platform
689688
'SIZEOF_WCHAR_T', # 16-bit or 32-bit depending on the platform
690689
):

Lib/test/test_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,7 @@ def test_recursion_normalizing_infinite_exception(self):
14791479
"""
14801480
rc, out, err = script_helper.assert_python_failure("-c", code)
14811481
self.assertEqual(rc, 1)
1482-
expected = b'RecursionError: maximum recursion depth exceeded'
1482+
expected = b'RecursionError'
14831483
self.assertTrue(expected in err, msg=f"{expected!r} not found in {err[:3_000]!r}... (truncated)")
14841484
self.assertIn(b'Done.', out)
14851485

Lib/test/test_fstring.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -627,23 +627,33 @@ def test_mismatched_parens(self):
627627
r"does not match opening parenthesis '\('",
628628
["f'{a(4}'",
629629
])
630-
self.assertRaises(SyntaxError, eval, "f'{" + "("*100 + "}'")
630+
self.assertRaises(SyntaxError, eval, "f'{" + "("*20 + "}'")
631631

632632
@unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
633633
def test_fstring_nested_too_deeply(self):
634-
self.assertAllRaise(SyntaxError,
635-
"f-string: expressions nested too deeply",
636-
['f"{1+2:{1+2:{1+1:{1}}}}"'])
634+
def raises_syntax_or_memory_error(txt):
635+
try:
636+
eval(txt)
637+
self.fail("No exception raised")
638+
except SyntaxError:
639+
pass
640+
except MemoryError:
641+
pass
642+
except Exception as ex:
643+
self.fail(f"Should raise SyntaxError or MemoryError, not {type(ex)}")
644+
645+
raises_syntax_or_memory_error('f"{1+2:{1+2:{1+1:{1}}}}"')
637646

638647
def create_nested_fstring(n):
639648
if n == 0:
640649
return "1+1"
641650
prev = create_nested_fstring(n-1)
642651
return f'f"{{{prev}}}"'
643652

644-
self.assertAllRaise(SyntaxError,
645-
"too many nested f-strings",
646-
[create_nested_fstring(160)])
653+
raises_syntax_or_memory_error(create_nested_fstring(160))
654+
raises_syntax_or_memory_error("f'{" + "("*100 + "}'")
655+
raises_syntax_or_memory_error("f'{" + "("*1000 + "}'")
656+
raises_syntax_or_memory_error("f'{" + "("*10_000 + "}'")
647657

648658
def test_syntax_error_in_nested_fstring(self):
649659
# See gh-104016 for more information on this crash

0 commit comments

Comments
 (0)