PyXR

c:\python24\lib \ test \ test_capi.py



0001 # Run the _testcapi module tests (tests for the Python/C API):  by defn,
0002 # these are all functions _testcapi exports whose name begins with 'test_'.
0003 
0004 import sys
0005 from test import test_support
0006 import _testcapi
0007 
0008 for name in dir(_testcapi):
0009     if name.startswith('test_'):
0010         test = getattr(_testcapi, name)
0011         if test_support.verbose:
0012             print "internal", name
0013         try:
0014             test()
0015         except _testcapi.error:
0016             raise test_support.TestFailed, sys.exc_info()[1]
0017 
0018 # some extra thread-state tests driven via _testcapi
0019 def TestThreadState():
0020     import thread
0021     import time
0022 
0023     if test_support.verbose:
0024         print "auto-thread-state"
0025 
0026     idents = []
0027 
0028     def callback():
0029         idents.append(thread.get_ident())
0030 
0031     _testcapi._test_thread_state(callback)
0032     time.sleep(1)
0033     # Check our main thread is in the list exactly 3 times.
0034     if idents.count(thread.get_ident()) != 3:
0035         raise test_support.TestFailed, \
0036               "Couldn't find main thread correctly in the list"
0037 
0038 try:
0039     _testcapi._test_thread_state
0040     have_thread_state = True
0041 except AttributeError:
0042     have_thread_state = False
0043 
0044 if have_thread_state:
0045     TestThreadState()
0046     import threading
0047     t=threading.Thread(target=TestThreadState)
0048     t.start()
0049 

Generated by PyXR 0.9.4
SourceForge.net Logo