diff options
author | xdegaye <xdegaye@gmail.com> | 2017-10-24 14:42:33 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-24 14:42:33 (GMT) |
commit | d5d79545b73110b2f4c2b66d150409514e2ca8e0 (patch) | |
tree | da81cc88b7d37daca21b3c993f64eda0c3c2fa01 /Lib/test | |
parent | d8f78a1fbc0a34224289d436ad67f608fa553f0c (diff) | |
download | cpython-d5d79545b73110b2f4c2b66d150409514e2ca8e0.zip cpython-d5d79545b73110b2f4c2b66d150409514e2ca8e0.tar.gz cpython-d5d79545b73110b2f4c2b66d150409514e2ca8e0.tar.bz2 |
[3.6] bpo-30817: Fix PyErr_PrintEx() when no memory (GH-2526). (#4107)
(cherry picked from commit 66caacf2f0d6213b049a3097556e28e30440b900)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_exceptions.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 53851cb..7eb08b7 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -10,7 +10,7 @@ import errno from test.support import (TESTFN, captured_stderr, check_impl_detail, check_warnings, cpython_only, gc_collect, run_unittest, - no_tracing, unlink, import_module) + no_tracing, unlink, import_module, script_helper) class NaiveException(Exception): def __init__(self, x): @@ -1104,6 +1104,23 @@ class ExceptionTests(unittest.TestCase): self.assertIn("test message", report) self.assertTrue(report.endswith("\n")) + @cpython_only + def test_memory_error_in_PyErr_PrintEx(self): + code = """if 1: + import _testcapi + class C(): pass + _testcapi.set_nomemory(0, %d) + C() + """ + + # Issue #30817: Abort in PyErr_PrintEx() when no memory. + # Span a large range of tests as the CPython code always evolves with + # changes that add or remove memory allocations. + for i in range(1, 20): + rc, out, err = script_helper.assert_python_failure("-c", code % i) + self.assertIn(rc, (1, 120)) + self.assertIn(b'MemoryError', err) + class ImportErrorTests(unittest.TestCase): |