]> granicus.if.org Git - python/commitdiff
Make some tests more frienly to MemoryError.
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 28 Mar 2015 18:38:37 +0000 (20:38 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 28 Mar 2015 18:38:37 +0000 (20:38 +0200)
Free memory, unlock hanging threads.

Lib/ctypes/test/test_find.py
Lib/ctypes/test/test_pointers.py
Lib/test/lock_tests.py
Lib/test/test_gc.py
Lib/test/test_io.py
Lib/test/test_itertools.py

index d8cd8ad60e90f9aa136f4accaba6f3751756eb2f..e6bc19d7dddf98c64abca05656edaace4bf0cb0e 100644 (file)
@@ -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')
index 4cd3a7a689c8cbd53a18d3e83354e9dc476fc537..e24a520dbe060653229638db812ffe99a641ac90 100644 (file)
@@ -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):
 
@@ -191,9 +189,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__':
index 1cbcea2343968aca703a7f6f5e50de33fa4061b1..42a7d8216352a7351eb7df21a6a474b87f5b1999 100644 (file)
@@ -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:
index c0be53795f0f81363d6df1f300ce845878b5e476..c025512790cd451500698abdfba20a736cb20ec1 100644 (file)
@@ -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:
index 5b2bf46e03b065ca0a23e29bbf73a5771f0744b2..ec19562006f615e069668113f5febf43c3eba6b5 100644 (file)
@@ -3514,11 +3514,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):
@@ -3539,6 +3544,8 @@ class SignalsTest(unittest.TestCase):
             wio.flush()
             write_finished = True
             t.join()
+
+            self.assertIsNone(error)
             self.assertEqual(N, sum(len(x) for x in read_results))
         finally:
             write_finished = True
index eb51be4dbc8e7dbd04205a72ce4edf33fbba08fd..3aed77988e1260ef11b927a5c57407905aa8d1c7 100644 (file)
@@ -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())