Update of /cvsroot/pywin32/pywin32/com/win32com/test
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv13930
Modified Files:
testDictionary.py testExplorer.py testMSOffice.py
testPyComTest.py testShell.py testall.py testvb.py util.py
Log Message:
Improvements to the test registration process and add the concept of
a test being "skipped" due to the lack of testable COM object - vastly
reduces test noise due to non-existing test objects.
Index: testPyComTest.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testPyComTest.py,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** testPyComTest.py 24 Nov 2008 22:21:48 -0000 1.33
--- testPyComTest.py 26 Nov 2008 01:27:40 -0000 1.34
***************
*** 16,20 ****
# This test uses a Python implemented COM server - ensure correctly registered.
RegisterPythonServer(os.path.join(os.path.dirname(__file__), '..', "servers", "test_pycomtest.py"),
! "PyCOMTest.PyCOMTest")
from win32com.client import gencache
--- 16,20 ----
# This test uses a Python implemented COM server - ensure correctly registered.
RegisterPythonServer(os.path.join(os.path.dirname(__file__), '..', "servers", "test_pycomtest.py"),
! "Python.Test.PyCOMTest")
from win32com.client import gencache
Index: util.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/util.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** util.py 24 Nov 2008 22:21:48 -0000 1.11
--- util.py 26 Nov 2008 01:27:40 -0000 1.12
***************
*** 15,19 ****
# Ensure no lingering exceptions - Python should have zero outstanding
# COM objects
! sys.exc_clear()
c = _GetInterfaceCount()
if c:
--- 15,22 ----
# Ensure no lingering exceptions - Python should have zero outstanding
# COM objects
! try:
! sys.exc_clear()
! except AttributeError:
! pass # py3k
c = _GetInterfaceCount()
if c:
***************
*** 39,43 ****
# have a CLSID - open it.
try:
! hk = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, "CLSID\\%s" % clsid)
dll = _winreg.QueryValue(hk, "InprocServer32")
except WindowsError:
--- 42,47 ----
# have a CLSID - open it.
try:
! HKCR = _winreg.HKEY_CLASSES_ROOT
! hk = _winreg.OpenKey(HKCR, "CLSID\\%s" % clsid)
dll = _winreg.QueryValue(hk, "InprocServer32")
except WindowsError:
***************
*** 66,70 ****
if why_not:
msg += "\n(registration check failed as %s)" % why_not
! raise RuntimeError(msg)
# so theoretically we are able to register it.
cmd = '%s "%s" --unattended > nul 2>&1' % (win32api.GetModuleFileName(0), filename)
--- 70,76 ----
if why_not:
msg += "\n(registration check failed as %s)" % why_not
! # throw a normal "class not registered" exception - we don't report
! # them the same way as "real" errors.
! raise pythoncom.com_error(winerror.CO_E_CLASSSTRING, msg, None, -1)
# so theoretically we are able to register it.
cmd = '%s "%s" --unattended > nul 2>&1' % (win32api.GetModuleFileName(0), filename)
***************
*** 109,113 ****
func(*args, **kw)
except pythoncom.com_error, details:
! if details[0]==hresult:
return
testcase.fail("Excepected COM exception with HRESULT 0x%x" % hresult)
--- 115,119 ----
func(*args, **kw)
except pythoncom.com_error, details:
! if details.hresult==hresult:
return
testcase.fail("Excepected COM exception with HRESULT 0x%x" % hresult)
***************
*** 221,224 ****
--- 227,260 ----
return test
+ class TestResult(unittest._TextTestResult):
+ def __init__(self, *args, **kw):
+ super(TestResult, self).__init__(*args, **kw)
+ self.num_invalid_clsid = 0
+
+ def addError(self, test, err):
+ """Called when an error has occurred. 'err' is a tuple of values as
+ returned by sys.exc_info().
+ """
+ if isinstance(err[1], pythoncom.com_error) and \
+ err[1].hresult==winerror.CO_E_CLASSSTRING:
+ self.num_invalid_clsid += 1
+ if self.showAll:
+ self.stream.writeln("SKIP")
+ elif self.dots:
+ self.stream.write('S')
+ self.stream.flush()
+ return
+ super(TestResult, self).addError(test, err)
+
+ def printErrors(self):
+ super(TestResult, self).printErrors()
+ if self.num_invalid_clsid:
+ self.stream.writeln("SKIPPED: %d tests due to missing COM objects used for testing" %
+ self.num_invalid_clsid)
+
+ class TestRunner(unittest.TextTestRunner):
+ def _makeResult(self):
+ return TestResult(self.stream, self.descriptions, self.verbosity)
+
# Utilities to set the win32com logger to something what just captures
# records written and doesn't print them.
***************
*** 289,294 ****
def testmain(*args, **kw):
new_kw = kw.copy()
! if not new_kw.has_key('testLoader'):
new_kw['testLoader'] = TestLoader()
unittest.main(*args, **new_kw)
CheckClean()
--- 325,332 ----
def testmain(*args, **kw):
new_kw = kw.copy()
! if 'testLoader' not in new_kw:
new_kw['testLoader'] = TestLoader()
+ if 'testRunner' not in new_kw:
+ new_kw['testRunner'] = TestRunner()
unittest.main(*args, **new_kw)
CheckClean()
Index: testShell.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testShell.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** testShell.py 14 Nov 2008 00:22:25 -0000 1.11
--- testShell.py 26 Nov 2008 01:27:40 -0000 1.12
***************
*** 23,28 ****
shellLink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
persistFile = shellLink.QueryInterface(pythoncom.IID_IPersistFile)
! for base_name in os.listdir(desktop):
! name = os.path.join(desktop, base_name)
try:
persistFile.Load(name,STGM_READ)
--- 23,30 ----
shellLink = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
persistFile = shellLink.QueryInterface(pythoncom.IID_IPersistFile)
! names = [os.path.join(desktop, n) for n in os.listdir(desktop)]
! programs = str(shell.SHGetSpecialFolderPath(0, CSIDL_PROGRAMS))
! names.extend([os.path.join(programs, n) for n in os.listdir(programs)])
! for name in names:
try:
persistFile.Load(name,STGM_READ)
***************
*** 36,40 ****
if num == 0:
# This isn't a fatal error, but is unlikely.
! print "Could not find any links on your desktop, which is unusual"
def testShellFolder(self):
--- 38,42 ----
if num == 0:
# This isn't a fatal error, but is unlikely.
! print "Could not find any links on your desktop or programs dir, which is unusual"
def testShellFolder(self):
Index: testMSOffice.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testMSOffice.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** testMSOffice.py 18 Nov 2002 11:20:06 -0000 1.7
--- testMSOffice.py 26 Nov 2008 01:27:40 -0000 1.8
***************
*** 135,166 ****
def TestAll():
! try:
! TestWord()
!
! print "Starting Excel for Dynamic test..."
! xl = win32com.client.dynamic.Dispatch("Excel.Application")
! TextExcel(xl)
! try:
! print "Starting Excel 8 for generated excel8.py test..."
! mod = gencache.EnsureModule("{00020813-0000-0000-C000-000000000046}", 0, 1, 2, bForDemand=1)
! xl = win32com.client.Dispatch("Excel.Application")
! TextExcel(xl)
! except ImportError:
! print "Could not import the generated Excel 97 wrapper"
! try:
! import xl5en32
! mod = gencache.EnsureModule("{00020813-0000-0000-C000-000000000046}", 9, 1, 0)
! xl = win32com.client.Dispatch("Excel.Application.5")
! print "Starting Excel 95 for makepy test..."
! TextExcel(xl)
! except ImportError:
! print "Could not import the generated Excel 95 wrapper"
! except KeyboardInterrupt:
! print "*** Interrupted MSOffice test ***"
! except:
! traceback.print_exc()
if __name__=='__main__':
--- 135,160 ----
def TestAll():
! TestWord()
! print "Starting Excel for Dynamic test..."
! xl = win32com.client.dynamic.Dispatch("Excel.Application")
! TextExcel(xl)
! try:
! print "Starting Excel 8 for generated excel8.py test..."
! mod = gencache.EnsureModule("{00020813-0000-0000-C000-000000000046}", 0, 1, 2, bForDemand=1)
! xl = win32com.client.Dispatch("Excel.Application")
! TextExcel(xl)
! except ImportError:
! print "Could not import the generated Excel 97 wrapper"
! try:
! import xl5en32
! mod = gencache.EnsureModule("{00020813-0000-0000-C000-000000000046}", 9, 1, 0)
! xl = win32com.client.Dispatch("Excel.Application.5")
! print "Starting Excel 95 for makepy test..."
! TextExcel(xl)
! except ImportError:
! print "Could not import the generated Excel 95 wrapper"
if __name__=='__main__':
Index: testvb.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testvb.py,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** testvb.py 21 Nov 2006 06:56:04 -0000 1.20
--- testvb.py 26 Nov 2008 01:27:40 -0000 1.21
***************
*** 8,29 ****
from win32com.server.util import NewCollection, wrap
import string
! import util
!
! importMsg = """\
! **** VB Test harness is not installed ***
! This test requires a VB test program to be built and installed
! on this PC.
! """
!
! ### NOTE: VB SUCKS!
! ### If you delete the DLL built by VB, then reopen VB
! ### to rebuild the DLL, it loses the IID of the object!!!
! ### So I will try to avoid this in the future :-)
!
! # Import the type library for the test module.
! try:
! win32com.client.gencache.EnsureDispatch("PyCOMVBTest.Tester")
! except pythoncom.com_error:
! raise RuntimeError, importMsg
import traceback
--- 8,12 ----
from win32com.server.util import NewCollection, wrap
import string
! from win32com.test import util
import traceback
***************
*** 440,443 ****
--- 423,430 ----
def TestAll():
+ # Import the type library for the test module. Let the 'invalid clsid'
+ # exception filter up, where the test runner will treat it as 'skipped'
+ win32com.client.gencache.EnsureDispatch("PyCOMVBTest.Tester")
+
if not __debug__:
raise RuntimeError, "This must be run in debug mode - we use assert!"
***************
*** 446,451 ****
--- 433,440 ----
print "All tests appear to have worked!"
except:
+ # ?????
print "TestAll() failed!!"
traceback.print_exc()
+ raise
# Make this test run under our test suite to leak tests etc work
Index: testall.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testall.py,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** testall.py 11 Nov 2008 01:01:44 -0000 1.28
--- testall.py 26 Nov 2008 01:27:40 -0000 1.29
***************
*** 2,7 ****
import pythoncom
import win32com.client
! from util import CheckClean, TestCase, CapturingFunctionTestCase, TestLoader
! import win32com.test.util
import traceback
import getopt
--- 2,8 ----
import pythoncom
import win32com.client
! from win32com.test.util import (CheckClean, TestCase,
! CapturingFunctionTestCase, ShellTestCase,
! TestLoader, TestRunner, RegisterPythonServer)
import traceback
import getopt
***************
*** 58,61 ****
--- 59,68 ----
no_leak_tests = True # done by the test itself
def testit(self):
+ # Check that the item is registered, so we get the correct
+ # 'skipped' behaviour (and recorded as such) rather than either
+ # error or silence due to non-registration.
+ RegisterPythonServer(os.path.join(os.path.dirname(__file__), '..', "servers", "test_pycomtest.py"),
+ "Python.Test.PyCOMTest")
+
# Execute testPyComTest in its own process so it can play
# with the Python thread state
***************
*** 66,69 ****
--- 73,80 ----
class PippoTest(TestCase):
def testit(self):
+ # Check we are registered before spawning the process.
+ from win32com.test import pippo_server
+ RegisterPythonServer(pippo_server.__file__, "Python.Test.Pippo")
+
python = sys.executable
fname = os.path.join(os.path.dirname(this_file), "testPippo.py")
***************
*** 123,128 ****
mod_name = test_name
func_name = None
try:
! mod = __import__(mod_name)
except:
import_failures.append((mod_name, sys.exc_info()[:2]))
--- 134,141 ----
mod_name = test_name
func_name = None
+ fq_mod_name = "win32com.test." + mod_name
try:
! __import__(fq_mod_name)
! mod = sys.modules[fq_mod_name]
except:
import_failures.append((mod_name, sys.exc_info()[:2]))
***************
*** 145,150 ****
continue
if func is not None:
! test = win32com.test.util.CapturingFunctionTestCase(func,
! description=mod_name)
else:
if hasattr(mod, "suite"):
--- 158,162 ----
continue
if func is not None:
! test = CapturingFunctionTestCase(func, description=mod_name)
else:
if hasattr(mod, "suite"):
***************
*** 155,159 ****
suite.addTest(test)
for cmd, output in output_checked_programs[i]:
! suite.addTest(win32com.test.util.ShellTestCase(cmd, output))
for test_class in custom_test_cases[i]:
--- 167,171 ----
suite.addTest(test)
for cmd, output in output_checked_programs[i]:
! suite.addTest(ShellTestCase(cmd, output))
for test_class in custom_test_cases[i]:
***************
*** 202,206 ****
# A little row of markers so the dots show how close to finished
print '|' * suite.countTestCases()
! testRunner = unittest.TextTestRunner(verbosity=verbosity)
testResult = testRunner.run(suite)
if import_failures:
--- 214,218 ----
# A little row of markers so the dots show how close to finished
print '|' * suite.countTestCases()
! testRunner = TestRunner(verbosity=verbosity)
testResult = testRunner.run(suite)
if import_failures:
Index: testExplorer.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testExplorer.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** testExplorer.py 19 Jul 2008 06:23:40 -0000 1.7
--- testExplorer.py 26 Nov 2008 01:27:40 -0000 1.8
***************
*** 9,16 ****
import win32gui
import win32con
import glob
import pythoncom
import time
! from util import CheckClean
bVisibleEventFired = 0
--- 9,17 ----
import win32gui
import win32con
+ import winerror
import glob
import pythoncom
import time
! from win32com.test.util import CheckClean
bVisibleEventFired = 0
***************
*** 48,52 ****
'Internet Explorer_Server']:
hwnd = win32gui.FindWindowEx(hwnd, 0, child_class, None)
! assert hwnd, "Couldn't find '%s" % (child_class,)
# But here is the point - once you have an 'Internet Explorer_Server',
# you can send a message and use ObjectFromLresult to get it back.
--- 49,53 ----
'Internet Explorer_Server']:
hwnd = win32gui.FindWindowEx(hwnd, 0, child_class, None)
! assert hwnd, "Couldn't find '%s'" % (child_class,)
# But here is the point - once you have an 'Internet Explorer_Server',
# you can send a message and use ObjectFromLresult to get it back.
***************
*** 74,96 ****
def TestAll():
try:
! iexplore = win32com.client.dynamic.Dispatch("InternetExplorer.Application")
! TestExplorer(iexplore)
!
! win32api.Sleep(1000)
! iexplore = None
! # Test IE events.
! TestExplorerEvents()
! # Give IE a chance to shutdown, else it can get upset on fast machines.
! time.sleep(2)
! # Note that the TextExplorerEvents will force makepy - hence
! # this gencache is really no longer needed.
! from win32com.client import gencache
! gencache.EnsureModule("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1)
! iexplore = win32com.client.Dispatch("InternetExplorer.Application")
! TestExplorer(iexplore)
finally:
iexplore = None
--- 75,100 ----
def TestAll():
try:
! try:
! iexplore = win32com.client.dynamic.Dispatch("InternetExplorer.Application")
! TestExplorer(iexplore)
! win32api.Sleep(1000)
! iexplore = None
! # Test IE events.
! TestExplorerEvents()
! # Give IE a chance to shutdown, else it can get upset on fast machines.
! time.sleep(2)
! # Note that the TextExplorerEvents will force makepy - hence
! # this gencache is really no longer needed.
+ from win32com.client import gencache
+ gencache.EnsureModule("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1)
+ iexplore = win32com.client.Dispatch("InternetExplorer.Application")
+ TestExplorer(iexplore)
+ except pythoncom.com_error, exc:
+ if exc.hresult!=winerror.RPC_E_DISCONNECTED: # user closed the app!
+ raise
finally:
iexplore = None
Index: testDictionary.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/test/testDictionary.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** testDictionary.py 10 Nov 2003 00:49:29 -0000 1.6
--- testDictionary.py 26 Nov 2008 01:27:40 -0000 1.7
***************
*** 9,13 ****
import pywintypes
import winerror
- L=pywintypes.Unicode
import unittest
--- 9,12 ----
***************
*** 25,31 ****
# Ensure we have the correct version registered.
def Register(quiet):
! import win32com.server.register
! from win32com.servers.dictionary import DictionaryPolicy
! win32com.server.register.RegisterClasses(DictionaryPolicy, quiet=quiet)
def TestDict(quiet=None):
--- 24,30 ----
# Ensure we have the correct version registered.
def Register(quiet):
! import win32com.servers.dictionary
! from win32com.test.util import RegisterPythonServer
! RegisterPythonServer(win32com.servers.dictionary.__file__, 'Python.Dictionary')
def TestDict(quiet=None):
|