]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Make some tests more frienly to MemoryError.
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 28 Mar 2015 18:38:48 +0000 (20:38 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 28 Mar 2015 18:38:48 +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 c5f6ace409a22633c0d078d39c53645fbf46edd0..e7a0a9312ce0aaf8fc0506557e7a669eaca1f61a 100644 (file)
@@ -32,15 +32,24 @@ class Test_OpenGL_libs(unittest.TestCase):
     def setUp(self):
         self.gl = self.glu = self.gle = None
         if lib_gl:
-            self.gl = CDLL(lib_gl, mode=RTLD_GLOBAL)
+            try:
+                self.gl = CDLL(lib_gl, mode=RTLD_GLOBAL)
+            except OSError:
+                pass
         if lib_glu:
-            self.glu = CDLL(lib_glu, RTLD_GLOBAL)
+            try:
+                self.glu = CDLL(lib_glu, RTLD_GLOBAL)
+            except OSError:
+                pass
         if lib_gle:
             try:
                 self.gle = CDLL(lib_gle)
             except OSError:
                 pass
 
+    def tearDown(self):
+        self.gl = self.glu = self.gle = None
+
     @unittest.skipUnless(lib_gl, 'lib_gl not available')
     def test_gl(self):
         if self.gl:
index 3e7479195c45499da0f61d81f1ea645e6be77eb0..5cdde6813ec9677e8a684fd801747648d7636828 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, long,
                 int, long, long, long, 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 966f9bd7ca0b710c7ddf4ff2ac2da793708d3f4e..2ff75c4ade9b863b71eb573a53ea0a725aaf0958 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 fd874c3a2c3500f577f149b91cfd3ac6839af4ee..5746c39a4cc4fddc9ec9a05fc16fda41282262f8 100644 (file)
@@ -357,10 +357,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 a361e4c64e9538af59bd044a528462a0f5e73cb1..fc68e4dbf83058dbb1f872e6ddf59c25149f32de 100644 (file)
@@ -3149,11 +3149,15 @@ 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:
+                error[0] = exc
         t = threading.Thread(target=_read)
         t.daemon = True
         def alarm1(sig, frame):
@@ -3174,6 +3178,8 @@ class SignalsTest(unittest.TestCase):
             wio.flush()
             write_finished = True
             t.join()
+
+            self.assertIsNone(error[0])
             self.assertEqual(N, sum(len(x) for x in read_results))
         finally:
             write_finished = True
index bde7ab6ddea599825025950a293aa270e64cac5f..753aa17afa428e6e952c27274ce9bceaf46ed02a 100644 (file)
@@ -949,8 +949,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, izip().next)