mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
bpo-30695: Add set_nomemory(start, stop) to _testcapi (GH-2406)
This commit is contained in:
parent
49bc743028
commit
85f643023f
3 changed files with 163 additions and 1 deletions
|
|
@ -15,7 +15,7 @@ import time
|
|||
import unittest
|
||||
from test import support
|
||||
from test.support import MISSING_C_DOCSTRINGS
|
||||
from test.support.script_helper import assert_python_failure
|
||||
from test.support.script_helper import assert_python_failure, assert_python_ok
|
||||
try:
|
||||
import _posixsubprocess
|
||||
except ImportError:
|
||||
|
|
@ -243,6 +243,38 @@ class CAPITest(unittest.TestCase):
|
|||
def test_buildvalue_N(self):
|
||||
_testcapi.test_buildvalue_N()
|
||||
|
||||
def test_set_nomemory(self):
|
||||
code = """if 1:
|
||||
import _testcapi
|
||||
|
||||
class C(): pass
|
||||
|
||||
# The first loop tests both functions and that remove_mem_hooks()
|
||||
# can be called twice in a row. The second loop checks a call to
|
||||
# set_nomemory() after a call to remove_mem_hooks(). The third
|
||||
# loop checks the start and stop arguments of set_nomemory().
|
||||
for outer_cnt in range(1, 4):
|
||||
start = 10 * outer_cnt
|
||||
for j in range(100):
|
||||
if j == 0:
|
||||
if outer_cnt != 3:
|
||||
_testcapi.set_nomemory(start)
|
||||
else:
|
||||
_testcapi.set_nomemory(start, start + 1)
|
||||
try:
|
||||
C()
|
||||
except MemoryError as e:
|
||||
if outer_cnt != 3:
|
||||
_testcapi.remove_mem_hooks()
|
||||
print('MemoryError', outer_cnt, j)
|
||||
_testcapi.remove_mem_hooks()
|
||||
break
|
||||
"""
|
||||
rc, out, err = assert_python_ok('-c', code)
|
||||
self.assertIn(b'MemoryError 1 10', out)
|
||||
self.assertIn(b'MemoryError 2 20', out)
|
||||
self.assertIn(b'MemoryError 3 30', out)
|
||||
|
||||
|
||||
@unittest.skipUnless(threading, 'Threading required for this test.')
|
||||
class TestPendingCalls(unittest.TestCase):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue