source: vendor/python/2.5/Lib/test/test_capi.py

Last change on this file was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 1.5 KB
Line 
1# Run the _testcapi module tests (tests for the Python/C API): by defn,
2# these are all functions _testcapi exports whose name begins with 'test_'.
3
4import sys
5from test import test_support
6import _testcapi
7
8def test_main():
9
10 for name in dir(_testcapi):
11 if name.startswith('test_'):
12 test = getattr(_testcapi, name)
13 if test_support.verbose:
14 print "internal", name
15 try:
16 test()
17 except _testcapi.error:
18 raise test_support.TestFailed, sys.exc_info()[1]
19
20 # some extra thread-state tests driven via _testcapi
21 def TestThreadState():
22 import thread
23 import time
24
25 if test_support.verbose:
26 print "auto-thread-state"
27
28 idents = []
29
30 def callback():
31 idents.append(thread.get_ident())
32
33 _testcapi._test_thread_state(callback)
34 a = b = callback
35 time.sleep(1)
36 # Check our main thread is in the list exactly 3 times.
37 if idents.count(thread.get_ident()) != 3:
38 raise test_support.TestFailed, \
39 "Couldn't find main thread correctly in the list"
40
41 try:
42 _testcapi._test_thread_state
43 have_thread_state = True
44 except AttributeError:
45 have_thread_state = False
46
47 if have_thread_state:
48 TestThreadState()
49 import threading
50 t=threading.Thread(target=TestThreadState)
51 t.start()
52 t.join()
53
54if __name__ == "__main__":
55 test_main()
Note: See TracBrowser for help on using the repository browser.