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_testServers.py < prev    next >
Encoding:
Python Source  |  2001-07-26  |  1.3 KB  |  49 lines

  1. import pythoncom, win32com.client.dynamic, sys
  2. from util import CheckClean
  3.  
  4. def TestInterp(interp):
  5.     if interp.Eval("1+1") <> 2:
  6.         raise ValueError, "The interpreter returned the wrong result."
  7.     try:
  8.         interp.Eval(1+1)
  9.         raise ValueError, "The interpreter did not raise an exception"
  10.     except pythoncom.com_error, details:
  11.         import winerror
  12.         if details[0]!=winerror.DISP_E_TYPEMISMATCH:
  13.             raise ValueError, "The interpreter exception was not winerror.DISP_E_TYPEMISMATCH."
  14.  
  15. def TestConnections():
  16.     import win32com.demos.connect
  17.     win32com.demos.connect.test()
  18.  
  19. def TestAllInterps():
  20.     numInterps = 0
  21.     try:
  22.         interp = win32com.client.dynamic.Dispatch("Python.Interpreter")
  23.     except pythoncom.com_error:
  24.         print "**** - The Python.Interpreter DLL test server is not available"
  25.         interp = None
  26.     if interp:
  27.         numInterps = numInterps + 1
  28.         TestInterp(interp)
  29.     
  30.     try:
  31.         interp = win32com.client.dynamic.Dispatch("Python.Interpreter", clsctx = pythoncom.CLSCTX_LOCAL_SERVER)
  32.     except pythoncom.com_error:
  33.         print "**** - The Python.Interpreter EXE test server is not available"
  34.         interp = None
  35.     if interp:
  36.         numInterps = numInterps + 1
  37.         TestInterp(interp)
  38.  
  39.     print "The %d available Python.Interpreter objects worked OK." % (numInterps)
  40.  
  41. def TestAll():
  42.     TestAllInterps()
  43.     TestConnections()
  44.     
  45. if __name__=='__main__':
  46.     TestAll()
  47.     CheckClean()
  48.  
  49.