changeset: 82327:81f98372f893 branch: 3.3 parent: 82323:a305901366a6 parent: 82326:329732a1572f user: Ezio Melotti date: Sat Feb 23 05:58:38 2013 +0200 files: Lib/test/test_capi.py Misc/NEWS description: #17249: merge with 3.2. diff -r a305901366a6 -r 81f98372f893 Lib/test/test_capi.py --- a/Lib/test/test_capi.py Sat Feb 23 04:55:24 2013 +0200 +++ b/Lib/test/test_capi.py Sat Feb 23 05:58:38 2013 +0200 @@ -326,9 +326,34 @@ self.assertRaises(ValueError, _testcapi.parse_tuple_and_keywords, (), {}, b'', [42]) +@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 -r a305901366a6 -r 81f98372f893 Misc/NEWS --- a/Misc/NEWS Sat Feb 23 04:55:24 2013 +0200 +++ b/Misc/NEWS Sat Feb 23 05:58:38 2013 +0200 @@ -620,6 +620,8 @@ Tests ----- +- Issue #17249: convert a test in test_capi to use unittest and reap threads. + - Issue #17041: Fix testing when Python is configured with the --without-doc-strings.