"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Lib/test/test_sys.py" between
Python-3.9.3.tar.xz and Python-3.9.4.tar.xz

About: Python is an interpreted, interactive, object-oriented programming language. It incorporates modules, exceptions, dynamic typing, very high level dynamic data types, and classes. Newest major release.

test_sys.py  (Python-3.9.3.tar.xz):test_sys.py  (Python-3.9.4.tar.xz)
skipping to change at line 218 skipping to change at line 218
sys.setrecursionlimit(oldlimit) sys.setrecursionlimit(oldlimit)
def test_recursionlimit_recovery(self): def test_recursionlimit_recovery(self):
if hasattr(sys, 'gettrace') and sys.gettrace(): if hasattr(sys, 'gettrace') and sys.gettrace():
self.skipTest('fatal error if run with a trace function') self.skipTest('fatal error if run with a trace function')
oldlimit = sys.getrecursionlimit() oldlimit = sys.getrecursionlimit()
def f(): def f():
f() f()
try: try:
for depth in (50, 75, 100, 250, 1000): for depth in (10, 25, 50, 75, 100, 250, 1000):
try: try:
sys.setrecursionlimit(depth) sys.setrecursionlimit(depth)
except RecursionError: except RecursionError:
# Issue #25274: The recursion limit is too low at the # Issue #25274: The recursion limit is too low at the
# current recursion depth # current recursion depth
continue continue
# Issue #5392: test stack overflow after hitting recursion # Issue #5392: test stack overflow after hitting recursion
# limit twice # limit twice
with self.assertRaises(RecursionError): self.assertRaises(RecursionError, f)
f() self.assertRaises(RecursionError, f)
with self.assertRaises(RecursionError):
f()
finally: finally:
sys.setrecursionlimit(oldlimit) sys.setrecursionlimit(oldlimit)
@test.support.cpython_only @test.support.cpython_only
def test_setrecursionlimit_recursion_depth(self): def test_setrecursionlimit_recursion_depth(self):
# Issue #25274: Setting a low recursion limit must be blocked if the # Issue #25274: Setting a low recursion limit must be blocked if the
# current recursion depth is already higher than limit. # current recursion depth is already higher than the "lower-water
# mark". Otherwise, it may not be possible anymore to
# reset the overflowed flag to 0.
from _testinternalcapi import get_recursion_depth from _testinternalcapi import get_recursion_depth
def set_recursion_limit_at_depth(depth, limit): def set_recursion_limit_at_depth(depth, limit):
recursion_depth = get_recursion_depth() recursion_depth = get_recursion_depth()
if recursion_depth >= depth: if recursion_depth >= depth:
with self.assertRaises(RecursionError) as cm: with self.assertRaises(RecursionError) as cm:
sys.setrecursionlimit(limit) sys.setrecursionlimit(limit)
self.assertRegex(str(cm.exception), self.assertRegex(str(cm.exception),
"cannot set the recursion limit to [0-9]+ " "cannot set the recursion limit to [0-9]+ "
"at the recursion depth [0-9]+: " "at the recursion depth [0-9]+: "
"the limit is too low") "the limit is too low")
else: else:
set_recursion_limit_at_depth(depth, limit) set_recursion_limit_at_depth(depth, limit)
oldlimit = sys.getrecursionlimit() oldlimit = sys.getrecursionlimit()
try: try:
sys.setrecursionlimit(1000) sys.setrecursionlimit(1000)
for limit in (10, 25, 50, 75, 100, 150, 200): for limit in (10, 25, 50, 75, 100, 150, 200):
set_recursion_limit_at_depth(limit, limit) # formula extracted from _Py_RecursionLimitLowerWaterMark()
if limit > 200:
depth = limit - 50
else:
depth = limit * 3 // 4
set_recursion_limit_at_depth(depth, limit)
finally: finally:
sys.setrecursionlimit(oldlimit) sys.setrecursionlimit(oldlimit)
# The error message is specific to CPython
@test.support.cpython_only
def test_recursionlimit_fatalerror(self):
# A fatal error occurs if a second recursion limit is hit when recoverin
g
# from a first one.
code = textwrap.dedent("""
import sys
def f():
try:
f()
except RecursionError:
f()
sys.setrecursionlimit(%d)
f()""")
with test.support.SuppressCrashReport():
for i in (50, 1000):
sub = subprocess.Popen([sys.executable, '-c', code % i],
stderr=subprocess.PIPE)
err = sub.communicate()[1]
self.assertTrue(sub.returncode, sub.returncode)
self.assertIn(
b"Fatal Python error: _Py_CheckRecursiveCall: "
b"Cannot recover from stack overflow",
err)
def test_getwindowsversion(self): def test_getwindowsversion(self):
# Raise SkipTest if sys doesn't have getwindowsversion attribute # Raise SkipTest if sys doesn't have getwindowsversion attribute
test.support.get_attribute(sys, "getwindowsversion") test.support.get_attribute(sys, "getwindowsversion")
v = sys.getwindowsversion() v = sys.getwindowsversion()
self.assertEqual(len(v), 5) self.assertEqual(len(v), 5)
self.assertIsInstance(v[0], int) self.assertIsInstance(v[0], int)
self.assertIsInstance(v[1], int) self.assertIsInstance(v[1], int)
self.assertIsInstance(v[2], int) self.assertIsInstance(v[2], int)
self.assertIsInstance(v[3], int) self.assertIsInstance(v[3], int)
self.assertIsInstance(v[4], str) self.assertIsInstance(v[4], str)
 End of changes. 5 change blocks. 
7 lines changed or deleted 40 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)