summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2017-10-23 13:05:46 (GMT)
committerxdegaye <xdegaye@gmail.com>2017-10-23 13:05:46 (GMT)
commitaaf6a3dbbdb9754f98d480b468adfcae0f66e3a2 (patch)
tree6e84eb0b246b92a6ba950b1c62d89468b2557753 /Lib
parent77af0a3bcab666a356eea2927a8031a7578d60d2 (diff)
downloadcpython-aaf6a3dbbdb9754f98d480b468adfcae0f66e3a2.zip
cpython-aaf6a3dbbdb9754f98d480b468adfcae0f66e3a2.tar.gz
cpython-aaf6a3dbbdb9754f98d480b468adfcae0f66e3a2.tar.bz2
[3.6] bpo-30695: Add set_nomemory(start, stop) to _testcapi (GH-2406) (#4083)
(cherry picked from commit 85f643023fed3d4e2fb8e399f9ad57f3a65ef237)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_capi.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index 216851c..3a29b69 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -13,7 +13,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:
@@ -241,6 +241,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):