"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Lib/test/test_exceptions.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_exceptions.py  (Python-3.9.3.tar.xz):test_exceptions.py  (Python-3.9.4.tar.xz)
skipping to change at line 1045 skipping to change at line 1045
generator = gen() generator = gen()
next(generator) next(generator)
recursionlimit = sys.getrecursionlimit() recursionlimit = sys.getrecursionlimit()
depth = get_recursion_depth() depth = get_recursion_depth()
try: try:
# Upon the last recursive invocation of recurse(), # Upon the last recursive invocation of recurse(),
# tstate->recursion_depth is equal to (recursion_limit - 1) # tstate->recursion_depth is equal to (recursion_limit - 1)
# and is equal to recursion_limit when _gen_throw() calls # and is equal to recursion_limit when _gen_throw() calls
# PyErr_NormalizeException(). # PyErr_NormalizeException().
recurse(setrecursionlimit(depth + 2) - depth) recurse(setrecursionlimit(depth + 2) - depth - 1)
finally: finally:
sys.setrecursionlimit(recursionlimit) sys.setrecursionlimit(recursionlimit)
print('Done.') print('Done.')
""" % __file__ """ % __file__
rc, out, err = script_helper.assert_python_failure("-Wd", "-c", code) rc, out, err = script_helper.assert_python_failure("-Wd", "-c", code)
# Check that the program does not fail with SIGABRT. # Check that the program does not fail with SIGABRT.
self.assertEqual(rc, 1) self.assertEqual(rc, 1)
self.assertIn(b'RecursionError', err) self.assertIn(b'RecursionError', err)
self.assertIn(b'ResourceWarning', err) self.assertIn(b'ResourceWarning', err)
self.assertIn(b'Done.', out) self.assertIn(b'Done.', out)
skipping to change at line 1075 skipping to change at line 1075
raise _testcapi.RecursingInfinitelyError raise _testcapi.RecursingInfinitelyError
finally: finally:
print('Done.') print('Done.')
""" """
rc, out, err = script_helper.assert_python_failure("-c", code) rc, out, err = script_helper.assert_python_failure("-c", code)
self.assertEqual(rc, 1) self.assertEqual(rc, 1)
self.assertIn(b'RecursionError: maximum recursion depth exceeded ' self.assertIn(b'RecursionError: maximum recursion depth exceeded '
b'while normalizing an exception', err) b'while normalizing an exception', err)
self.assertIn(b'Done.', out) self.assertIn(b'Done.', out)
def test_recursion_in_except_handler(self):
def set_relative_recursion_limit(n):
depth = 1
while True:
try:
sys.setrecursionlimit(depth)
except RecursionError:
depth += 1
else:
break
sys.setrecursionlimit(depth+n)
def recurse_in_except():
try:
1/0
except:
recurse_in_except()
def recurse_after_except():
try:
1/0
except:
pass
recurse_after_except()
def recurse_in_body_and_except():
try:
recurse_in_body_and_except()
except:
recurse_in_body_and_except()
recursionlimit = sys.getrecursionlimit()
try:
set_relative_recursion_limit(10)
for func in (recurse_in_except, recurse_after_except, recurse_in_bod
y_and_except):
with self.subTest(func=func):
try:
func()
except RecursionError:
pass
else:
self.fail("Should have raised a RecursionError")
finally:
sys.setrecursionlimit(recursionlimit)
@cpython_only @cpython_only
def test_recursion_normalizing_with_no_memory(self): def test_recursion_normalizing_with_no_memory(self):
# Issue #30697. Test that in the abort that occurs when there is no # Issue #30697. Test that in the abort that occurs when there is no
# memory left and the size of the Python frames stack is greater than # memory left and the size of the Python frames stack is greater than
# the size of the list of preallocated MemoryError instances, the # the size of the list of preallocated MemoryError instances, the
# Fatal Python error message mentions MemoryError. # Fatal Python error message mentions MemoryError.
code = """if 1: code = """if 1:
import _testcapi import _testcapi
class C(): pass class C(): pass
def recurse(cnt): def recurse(cnt):
skipping to change at line 1157 skipping to change at line 1111
# PyErr_NoMemory always raises the same exception instance. # PyErr_NoMemory always raises the same exception instance.
# Check that the traceback is not doubled. # Check that the traceback is not doubled.
import traceback import traceback
from _testcapi import raise_memoryerror from _testcapi import raise_memoryerror
def raiseMemError(): def raiseMemError():
try: try:
raise_memoryerror() raise_memoryerror()
except MemoryError as e: except MemoryError as e:
tb = e.__traceback__ tb = e.__traceback__
else: else:
self.fail("Should have raised a MemoryError") self.fail("Should have raises a MemoryError")
return traceback.format_tb(tb) return traceback.format_tb(tb)
tb1 = raiseMemError() tb1 = raiseMemError()
tb2 = raiseMemError() tb2 = raiseMemError()
self.assertEqual(tb1, tb2) self.assertEqual(tb1, tb2)
@cpython_only @cpython_only
def test_exception_with_doc(self): def test_exception_with_doc(self):
import _testcapi import _testcapi
doc2 = "This is a test docstring." doc2 = "This is a test docstring."
 End of changes. 3 change blocks. 
49 lines changed or deleted 2 lines changed or added

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