home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 July / maximum-cd-2011-07.iso / DiscContents / LibO_3.3.2_Win_x86_install_multi.exe / libreoffice1.cab / test_capi.py < prev    next >
Encoding:
Python Source  |  2011-03-15  |  1.5 KB  |  55 lines

  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.  
  4. import sys
  5. from test import test_support
  6. import _testcapi
  7.  
  8. def 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.         if test_support.verbose:
  23.             print "auto-thread-state"
  24.  
  25.         idents = []
  26.  
  27.         def callback():
  28.             idents.append(thread.get_ident())
  29.  
  30.         _testcapi._test_thread_state(callback)
  31.         a = b = 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.  
  38.     try:
  39.         _testcapi._test_thread_state
  40.         have_thread_state = True
  41.     except AttributeError:
  42.         have_thread_state = False
  43.  
  44.     if have_thread_state:
  45.         import thread
  46.         import time
  47.         TestThreadState()
  48.         import threading
  49.         t=threading.Thread(target=TestThreadState)
  50.         t.start()
  51.         t.join()
  52.  
  53. if __name__ == "__main__":
  54.     test_main()
  55.