]> granicus.if.org Git - python/commitdiff
add _testcapi.raise_memoryerror to make test_exceptions.test_MemoryError simpler
authorBenjamin Peterson <benjamin@python.org>
Sat, 16 Aug 2008 16:11:03 +0000 (16:11 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 16 Aug 2008 16:11:03 +0000 (16:11 +0000)
Lib/test/test_exceptions.py
Modules/_testcapimodule.c

index 95c2dd143b318f7fceb1782bf3124718436d7518..5ce76f1190e3ebff7cd61c10f80f5fd8f956d7d4 100644 (file)
@@ -593,9 +593,10 @@ class ExceptionTests(unittest.TestCase):
         # PyErr_NoMemory always raises the same exception instance.
         # Check that the traceback is not doubled.
         import traceback
+        from _testcapi import raise_memoryerror
         def raiseMemError():
             try:
-                "a" * (sys.maxsize // 2)
+                raise_memoryerror()
             except MemoryError as e:
                 tb = e.__traceback__
             else:
index 3ee3bf4d01f81592850f11bf65c0f77e3ae25bb6..494937aa4e17f9a93904dc8d6f9d930a9e3e3fff 100644 (file)
@@ -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[] = {
        {"raise_exception",     raise_exception,                 METH_VARARGS},
+       {"raise_memoryerror",   (PyCFunction)raise_memoryerror,  METH_NOARGS},
        {"test_config",         (PyCFunction)test_config,        METH_NOARGS},
        {"test_list_api",       (PyCFunction)test_list_api,      METH_NOARGS},
        {"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS},