home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 May / PCWorld_2002-05_cd.bin / Software / TemaCD / activepython / ActivePython-2.1.1.msi / Python21_win32com_test_testall.py < prev    next >
Encoding:
Python Source  |  2001-07-26  |  3.5 KB  |  143 lines

  1. import sys, os, string
  2. import pythoncom
  3. import win32com.client
  4. from util import CheckClean
  5.  
  6. def GenerateAndRunOldStyle():
  7.     import GenTestScripts
  8.     GenTestScripts.GenerateAll()
  9.     try:
  10.         pass #
  11.     finally:
  12.         GenTestScripts.CleanAll()
  13.  
  14. def Prepare():
  15.     import win32com, shutil
  16.     if os.path.isdir(win32com.__gen_path__):
  17.         print "Deleting files from %s" % (win32com.__gen_path__)
  18.         shutil.rmtree(win32com.__gen_path__)
  19.     import win32com.client.gencache
  20.     win32com.client.gencache.__init__() # Reset
  21.  
  22.     
  23. if __name__=='__main__':
  24.     # default to "quick" test.  2==medium, 3==full
  25.     testLevel = 1
  26.  
  27.     try:
  28.         if len(sys.argv)>1:
  29.             testLevel = int(sys.argv[1])
  30.     except ValueError:
  31.         print "Usage: testall [level], where level is 1, 2 or 3 (default 1, fulltest=3)"
  32.  
  33.     Prepare()
  34.  
  35.     import win32com.test.util
  36.     capture = win32com.test.util.CaptureWriter()
  37.  
  38.     if testLevel>1:
  39.  
  40.         import testMSOffice
  41.         testMSOffice.TestAll()
  42.  
  43.         import testMSOfficeEvents
  44.         testMSOfficeEvents.test()
  45.  
  46.         capture.capture()
  47.         try:
  48.             import testAccess
  49.             testAccess.test()
  50.             capture.release()
  51.             print "MSAccess test generated %d lines of output" % capture.get_num_lines_captured()
  52.         finally:
  53.             capture.release()
  54.  
  55.     try:
  56.         import testExchange
  57.     except (ImportError, pythoncom.com_error):
  58.         print "The Exchange Server tests can not be run..."
  59.         testExchange = None
  60.     if testExchange is not None:
  61.         capture.capture()
  62.         testExchange.test()
  63.         capture.release()
  64.         print "testExchange test generated %d lines of output" % capture.get_num_lines_captured()
  65.  
  66.     import testExplorer
  67.     testExplorer.TestAll()
  68.  
  69.  
  70.     capture.capture()
  71.     try:
  72.         import testStreams
  73.         testStreams.test()
  74.         capture.release()
  75.         print "testStreams test generated %d lines of output" % capture.get_num_lines_captured()
  76.     finally:
  77.         capture.release()
  78.  
  79.     # Execute testPyComTest in its own process so it can play
  80.     # with the Python thread state
  81.     import win32pipe
  82.     data = win32pipe.popen(sys.executable + " testPyComTest.py -q").read() 
  83.     data = string.strip(data)
  84.     # lf -> cr/lf
  85.     print string.join(string.split(data, "\n"), "\r\n")
  86.  
  87.     import errorSemantics
  88.     errorSemantics.test()
  89.  
  90.     import policySemantics
  91.     policySemantics.TestAll()
  92.  
  93.     try:
  94.         import testvb
  95.         testvb.TestAll()
  96.     except RuntimeError, why:
  97.         print why
  98.  
  99.  
  100.     import testAXScript
  101.     testAXScript.RegisterEngine()
  102.     testAXScript.TestAll()
  103.  
  104.     import testCollections
  105.     testCollections.TestEnum(1)
  106.  
  107.     import testDictionary
  108.     testDictionary.TestDict(1)
  109.  
  110.     import testServers
  111.     testServers.TestAll()
  112.  
  113.     # Test VBScript and JScript which call back into Python
  114.     cscript_tests = string.split("testInterp.vbs testDictionary.vbs")
  115.  
  116.     # Note that this test assumes 'Testpys.sct' has been previously registered.
  117.     # To register this test, simply run 'regsvr32.exe Testpys.sct'
  118.     try:
  119.         # First check our test object has actually been installed.
  120.         win32com.client.Dispatch("TestPys.Scriptlet")
  121.         # If it worked, append it to the tests.
  122.         cscript_tests.append("testPyScriptlet.js")
  123.     except pythoncom.error:
  124.         print "Can not test 'Scriptlets' - has Scriptlets been installed and 'Testpys.sct' been registered???"
  125.  
  126.     for test in cscript_tests:
  127.         cmd_line = "cscript.exe " + test
  128.         print "Running:", cmd_line
  129.         rc = os.system(cmd_line)
  130.         if rc:
  131.             print "***** Test Failed:", cmd_line
  132.  
  133.     if testLevel>2:
  134.  
  135.         import testmakepy
  136.         print "Running makepy over every registered typelib..."
  137.         testmakepy.TestAll(0)
  138.  
  139.     print "Tests completed."
  140.     CheckClean()
  141.     pythoncom.CoUninitialize()
  142.  
  143.