Commit 2fddfd85 authored by Ezio Melotti's avatar Ezio Melotti

#17249: convert a test in test_capi to use unittest and reap threads.

parent 6a959a12
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
from __future__ import with_statement from __future__ import with_statement
import sys import sys
import time import time
import thread
import random import random
import unittest import unittest
from test import test_support from test import test_support
...@@ -96,23 +97,13 @@ class TestPendingCalls(unittest.TestCase): ...@@ -96,23 +97,13 @@ class TestPendingCalls(unittest.TestCase):
self.pendingcalls_wait(l, n) self.pendingcalls_wait(l, n)
def test_main(): @unittest.skipUnless(threading, 'Threading required for this test.')
class TestThreadState(unittest.TestCase):
for name in dir(_testcapi):
if name.startswith('test_'):
test = getattr(_testcapi, name)
if test_support.verbose:
print "internal", name
try:
test()
except _testcapi.error:
raise test_support.TestFailed, sys.exc_info()[1]
@test_support.reap_threads
def test_thread_state(self):
# some extra thread-state tests driven via _testcapi # some extra thread-state tests driven via _testcapi
def TestThreadState(): def target():
if test_support.verbose:
print "auto-thread-state"
idents = [] idents = []
def callback(): def callback():
...@@ -122,19 +113,27 @@ def test_main(): ...@@ -122,19 +113,27 @@ def test_main():
a = b = callback a = b = callback
time.sleep(1) time.sleep(1)
# Check our main thread is in the list exactly 3 times. # Check our main thread is in the list exactly 3 times.
if idents.count(thread.get_ident()) != 3: self.assertEqual(idents.count(thread.get_ident()), 3,
raise test_support.TestFailed, \ "Couldn't find main thread correctly in the list")
"Couldn't find main thread correctly in the list"
target()
if threading: t = threading.Thread(target=target)
import thread
import time
TestThreadState()
t=threading.Thread(target=TestThreadState)
t.start() t.start()
t.join() t.join()
test_support.run_unittest(TestPendingCalls)
def test_main():
for name in dir(_testcapi):
if name.startswith('test_'):
test = getattr(_testcapi, name)
if test_support.verbose:
print "internal", name
try:
test()
except _testcapi.error:
raise test_support.TestFailed, sys.exc_info()[1]
test_support.run_unittest(TestPendingCalls, TestThreadState)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()
...@@ -798,6 +798,8 @@ Extension Modules ...@@ -798,6 +798,8 @@ Extension Modules
Tests Tests
----- -----
- Issue #17249: convert a test in test_capi to use unittest and reap threads.
- We now run both test_email.py and test_email_renamed.py when running the - We now run both test_email.py and test_email_renamed.py when running the
test_email regression test. test_email_renamed contains some tests that test_email regression test. test_email_renamed contains some tests that
test_email does not. test_email does not.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment