mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
add _testcapi.raise_memoryerror to make test_exceptions.test_MemoryError simpler
This commit is contained in:
parent
72dc1eadd9
commit
0067bd68c9
2 changed files with 13 additions and 1 deletions
|
@ -593,9 +593,10 @@ class ExceptionTests(unittest.TestCase):
|
||||||
# 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
|
||||||
def raiseMemError():
|
def raiseMemError():
|
||||||
try:
|
try:
|
||||||
"a" * (sys.maxsize // 2)
|
raise_memoryerror()
|
||||||
except MemoryError as e:
|
except MemoryError as e:
|
||||||
tb = e.__traceback__
|
tb = e.__traceback__
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -971,8 +971,19 @@ exception_print(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* reliably raise a MemoryError */
|
||||||
|
static PyObject *
|
||||||
|
raise_memoryerror(PyObject *self)
|
||||||
|
{
|
||||||
|
PyErr_NoMemory();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static PyMethodDef TestMethods[] = {
|
static PyMethodDef TestMethods[] = {
|
||||||
{"raise_exception", raise_exception, METH_VARARGS},
|
{"raise_exception", raise_exception, METH_VARARGS},
|
||||||
|
{"raise_memoryerror", (PyCFunction)raise_memoryerror, METH_NOARGS},
|
||||||
{"test_config", (PyCFunction)test_config, METH_NOARGS},
|
{"test_config", (PyCFunction)test_config, METH_NOARGS},
|
||||||
{"test_list_api", (PyCFunction)test_list_api, METH_NOARGS},
|
{"test_list_api", (PyCFunction)test_list_api, METH_NOARGS},
|
||||||
{"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS},
|
{"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue