diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-03-28 18:39:51 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-03-28 18:39:51 (GMT) |
commit | 1770fde94cb2bbcd05f4e3e72e2b78074566f522 (patch) | |
tree | 310c03e2b8096fff4c9fbdd8db9ff3ae7ba9b63b | |
parent | cb0c60258b9c11b7742b6e1e6d65e33a6c9a3332 (diff) | |
parent | 9db55004a1bc0c0b3efca69dcd577ff58a86ea16 (diff) | |
download | cpython-1770fde94cb2bbcd05f4e3e72e2b78074566f522.zip cpython-1770fde94cb2bbcd05f4e3e72e2b78074566f522.tar.gz cpython-1770fde94cb2bbcd05f4e3e72e2b78074566f522.tar.bz2 |
Make some tests more frienly to MemoryError.
Free memory, unlock hanging threads.
-rw-r--r-- | Lib/ctypes/test/test_find.py | 14 | ||||
-rw-r--r-- | Lib/ctypes/test/test_pointers.py | 4 | ||||
-rw-r--r-- | Lib/test/lock_tests.py | 8 | ||||
-rw-r--r-- | Lib/test/test_gc.py | 10 | ||||
-rw-r--r-- | Lib/test/test_io.py | 14 | ||||
-rw-r--r-- | Lib/test/test_itertools.py | 8 |
6 files changed, 42 insertions, 16 deletions
diff --git a/Lib/ctypes/test/test_find.py b/Lib/ctypes/test/test_find.py index d8cd8ad..e6bc19d 100644 --- a/Lib/ctypes/test/test_find.py +++ b/Lib/ctypes/test/test_find.py @@ -30,15 +30,25 @@ class Test_OpenGL_libs(unittest.TestCase): cls.gl = cls.glu = cls.gle = None if lib_gl: - cls.gl = CDLL(lib_gl, mode=RTLD_GLOBAL) + try: + cls.gl = CDLL(lib_gl, mode=RTLD_GLOBAL) + except OSError: + pass if lib_glu: - cls.glu = CDLL(lib_glu, RTLD_GLOBAL) + try: + cls.glu = CDLL(lib_glu, RTLD_GLOBAL) + except OSError: + pass if lib_gle: try: cls.gle = CDLL(lib_gle) except OSError: pass + @classmethod + def tearDownClass(cls): + cls.gl = cls.glu = cls.gle = None + def test_gl(self): if self.gl is None: self.skipTest('lib_gl not available') diff --git a/Lib/ctypes/test/test_pointers.py b/Lib/ctypes/test/test_pointers.py index 78e3357..40738f7 100644 --- a/Lib/ctypes/test/test_pointers.py +++ b/Lib/ctypes/test/test_pointers.py @@ -7,8 +7,6 @@ ctype_types = [c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint, c_long, c_ulong, c_longlong, c_ulonglong, c_double, c_float] python_types = [int, int, int, int, int, int, int, int, int, int, float, float] -LargeNamedType = type('T' * 2 ** 25, (Structure,), {}) -large_string = 'T' * 2 ** 25 class PointersTestCase(unittest.TestCase): @@ -194,9 +192,11 @@ class PointersTestCase(unittest.TestCase): self.assertEqual(bool(mth), True) def test_pointer_type_name(self): + LargeNamedType = type('T' * 2 ** 25, (Structure,), {}) self.assertTrue(POINTER(LargeNamedType)) def test_pointer_type_str_name(self): + large_string = 'T' * 2 ** 25 self.assertTrue(POINTER(large_string)) if __name__ == '__main__': diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py index 136f1c3..b325bce 100644 --- a/Lib/test/lock_tests.py +++ b/Lib/test/lock_tests.py @@ -39,8 +39,12 @@ class Bunch(object): self.finished.append(tid) while not self._can_exit: _wait() - for i in range(n): - start_new_thread(task, ()) + try: + for i in range(n): + start_new_thread(task, ()) + except: + self._can_exit = True + raise def wait_for_started(self): while len(self.started) < self.n: diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py index c0be537..c025512 100644 --- a/Lib/test/test_gc.py +++ b/Lib/test/test_gc.py @@ -402,10 +402,12 @@ class GCTests(unittest.TestCase): for i in range(N_THREADS): t = threading.Thread(target=run_thread) threads.append(t) - for t in threads: - t.start() - time.sleep(1.0) - exit = True + try: + for t in threads: + t.start() + finally: + time.sleep(1.0) + exit = True for t in threads: t.join() finally: diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 6a41ae6..8754779 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -3603,11 +3603,16 @@ class SignalsTest(unittest.TestCase): # received (forcing a first EINTR in write()). read_results = [] write_finished = False + error = None def _read(): - while not write_finished: - while r in select.select([r], [], [], 1.0)[0]: - s = os.read(r, 1024) - read_results.append(s) + try: + while not write_finished: + while r in select.select([r], [], [], 1.0)[0]: + s = os.read(r, 1024) + read_results.append(s) + except BaseException as exc: + nonlocal error + error = exc t = threading.Thread(target=_read) t.daemon = True def alarm1(sig, frame): @@ -3633,6 +3638,7 @@ class SignalsTest(unittest.TestCase): write_finished = True t.join() + self.assertIsNone(error) self.assertEqual(N, sum(len(x) for x in read_results)) finally: write_finished = True diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index 7bbee5a..fcd8869 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -1338,8 +1338,12 @@ class TestBasicOps(unittest.TestCase): # Issue 13454: Crash when deleting backward iterator from tee() def test_tee_del_backward(self): forward, backward = tee(repeat(None, 20000000)) - any(forward) # exhaust the iterator - del backward + try: + any(forward) # exhaust the iterator + del backward + except: + del forward, backward + raise def test_StopIteration(self): self.assertRaises(StopIteration, next, zip()) |