Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Python test set -- part 5, built-in exceptions

import copy
import ctypes
import os
import sys
import unittest
Expand Down Expand Up @@ -318,11 +319,18 @@ def baz():
check('(yield i) = 2', 1, 2)
check('def f(*):\n pass', 1, 7)

@unittest.skipIf(ctypes.sizeof(ctypes.c_int) >= ctypes.sizeof(ctypes.c_ssize_t),
"INT_MAX is bigger than Py_ssize_t, so this is unreachable")
@support.requires_resource('cpu')
@support.bigmemtest(support._2G, memuse=1.5)
def testMemoryErrorBigSource(self, _size):
with self.assertRaises(OverflowError):
exec(f"if True:\n {' ' * 2**31}print('hello world')")
# the line length needs to be more than INT_MAX, but we can't
# multiple a sequence by a number that doesn't fit Py_ssize_t,
# otherwise we will get an OverflowError (see PySequence_Repeat)
INT_MAX = 2 ** (ctypes.sizeof(ctypes.c_int) * 8)
padding = ' ' * (INT_MAX // 8)
with self.assertRaisesRegex(OverflowError, "column offset overflow"):
exec(f"if True:\n {padding}print('hello world')")

@cpython_only
def testSettingException(self):
Expand Down