[Python-checkins] cpython (merge 3.3 -> default): #17249: merge with 3.3.

ezio.melotti python-checkins at python.org
Sat Feb 23 04:59:56 CET 2013


http://hg.python.org/cpython/rev/f716a178b4e1
changeset:   82328:f716a178b4e1
parent:      82324:e0f940829eb6
parent:      82327:81f98372f893
user:        Ezio Melotti <ezio.melotti at gmail.com>
date:        Sat Feb 23 05:59:37 2013 +0200
summary:
  #17249: merge with 3.3.

files:
  Lib/test/test_capi.py |  55 +++++++++++++++---------------
  Misc/NEWS             |   2 +
  2 files changed, 29 insertions(+), 28 deletions(-)


diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -326,9 +326,34 @@
         self.assertRaises(ValueError, _testcapi.parse_tuple_and_keywords,
                           (), {}, b'', [42])
 
+ at unittest.skipUnless(threading, 'Threading required for this test.')
+class TestThreadState(unittest.TestCase):
+
+    @support.reap_threads
+    def test_thread_state(self):
+        # some extra thread-state tests driven via _testcapi
+        def target():
+            idents = []
+
+            def callback():
+                idents.append(threading.get_ident())
+
+            _testcapi._test_thread_state(callback)
+            a = b = callback
+            time.sleep(1)
+            # Check our main thread is in the list exactly 3 times.
+            self.assertEqual(idents.count(threading.get_ident()), 3,
+                             "Couldn't find main thread correctly in the list")
+
+        target()
+        t = threading.Thread(target=target)
+        t.start()
+        t.join()
+
+
 def test_main():
-    support.run_unittest(CAPITest, TestPendingCalls,
-                         Test6012, EmbeddingTest, SkipitemTest)
+    support.run_unittest(CAPITest, TestPendingCalls, Test6012,
+                         EmbeddingTest, SkipitemTest, TestThreadState)
 
     for name in dir(_testcapi):
         if name.startswith('test_'):
@@ -337,31 +362,5 @@
                 print("internal", name)
             test()
 
-    # some extra thread-state tests driven via _testcapi
-    def TestThreadState():
-        if support.verbose:
-            print("auto-thread-state")
-
-        idents = []
-
-        def callback():
-            idents.append(threading.get_ident())
-
-        _testcapi._test_thread_state(callback)
-        a = b = callback
-        time.sleep(1)
-        # Check our main thread is in the list exactly 3 times.
-        if idents.count(threading.get_ident()) != 3:
-            raise support.TestFailed(
-                        "Couldn't find main thread correctly in the list")
-
-    if threading:
-        import time
-        TestThreadState()
-        t = threading.Thread(target=TestThreadState)
-        t.start()
-        t.join()
-
-
 if __name__ == "__main__":
     test_main()
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -857,6 +857,8 @@
 Tests
 -----
 
+- Issue #17249: convert a test in test_capi to use unittest and reap threads.
+
 - Issue #17107: Test client-side SNI support in urllib.request thanks to
   the new server-side SNI support in the ssl module.  Initial patch by
   Daniel Black.

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list