blob: 1dd24616a25ff0e0df896cef589c8282335af77f [file] [log] [blame]
Tim Petersd66595f2001-02-04 03:09:53 +00001# Run the _testcapi module tests (tests for the Python/C API): by defn,
Guido van Rossum361c5352001-04-13 17:03:04 +00002# these are all functions _testcapi exports whose name begins with 'test_'.
Tim Peters9ea17ac2001-02-02 05:57:15 +00003
Martin v. Löwis6ce7ed22005-03-03 12:26:35 +00004import sys
Barry Warsaw04f357c2002-07-23 19:04:11 +00005from test import test_support
Tim Petersd66595f2001-02-04 03:09:53 +00006import _testcapi
Tim Peters9ea17ac2001-02-02 05:57:15 +00007
Tim Petersd66595f2001-02-04 03:09:53 +00008for name in dir(_testcapi):
Tim Peters9ea17ac2001-02-02 05:57:15 +00009 if name.startswith('test_'):
Tim Petersd66595f2001-02-04 03:09:53 +000010 test = getattr(_testcapi, name)
Tim Peters9ea17ac2001-02-02 05:57:15 +000011 if test_support.verbose:
12 print "internal", name
13 try:
14 test()
Tim Petersd66595f2001-02-04 03:09:53 +000015 except _testcapi.error:
Tim Peters9ea17ac2001-02-02 05:57:15 +000016 raise test_support.TestFailed, sys.exc_info()[1]
Mark Hammond8d98d2c2003-04-19 15:41:53 +000017
18# some extra thread-state tests driven via _testcapi
19def TestThreadState():
20 import thread
21 import time
22
23 if test_support.verbose:
24 print "auto-thread-state"
25
26 idents = []
27
28 def callback():
29 idents.append(thread.get_ident())
Tim Peters0eadaac2003-04-24 16:02:54 +000030
Mark Hammond8d98d2c2003-04-19 15:41:53 +000031 _testcapi._test_thread_state(callback)
32 time.sleep(1)
33 # Check our main thread is in the list exactly 3 times.
34 if idents.count(thread.get_ident()) != 3:
35 raise test_support.TestFailed, \
36 "Couldn't find main thread correctly in the list"
37
38try:
39 _testcapi._test_thread_state
40 have_thread_state = True
41except AttributeError:
42 have_thread_state = False
Tim Peters0eadaac2003-04-24 16:02:54 +000043
Mark Hammond8d98d2c2003-04-19 15:41:53 +000044if have_thread_state:
45 TestThreadState()
Mark Hammondeb619bb2004-08-24 22:24:08 +000046 import threading
47 t=threading.Thread(target=TestThreadState)
48 t.start()