diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2013-02-23 03:58:38 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2013-02-23 03:58:38 (GMT) |
commit | 35246bd5b18b4b7bd67afb543418a705682c5d15 (patch) | |
tree | 0cd98270bae4afe25801300cce7cbc17ff59c50f /Lib/test/test_capi.py | |
parent | cc5ea62e48afa0faf6b3aa0014245622b313b887 (diff) | |
parent | 29267c81ce2bca421f1ba044491200b41ed5cfd2 (diff) | |
download | cpython-35246bd5b18b4b7bd67afb543418a705682c5d15.zip cpython-35246bd5b18b4b7bd67afb543418a705682c5d15.tar.gz cpython-35246bd5b18b4b7bd67afb543418a705682c5d15.tar.bz2 |
#17249: merge with 3.2.
Diffstat (limited to 'Lib/test/test_capi.py')
-rw-r--r-- | Lib/test/test_capi.py | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index 5002c77..65778be 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -326,9 +326,34 @@ class SkipitemTest(unittest.TestCase): 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 @@ def test_main(): 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() |