Update of /cvsroot/pywin32/pywin32/win32/test
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv3949/win32/test
Modified Files:
testall.py
Log Message:
Rationalize win32com test utilities into new pywin32_testutil module.
Includes support for tests being "skipped" rather than failing due to
something out of our control, and some helpers for dealing with bytes
and buffers on py3k.
Index: testall.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/test/testall.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** testall.py 19 Dec 2008 05:09:27 -0000 1.11
--- testall.py 7 Jan 2009 05:59:56 -0000 1.12
***************
*** 1,5 ****
--- 1,7 ----
import sys, os
+ import re
import unittest
import traceback
+ import pywin32_testutil
# A list of demos that depend on user-interface of *any* kind. Tests listed
***************
*** 19,25 ****
}
! ok_exceptions = {
! "RegCreateKeyTransacted": ("NotImplementedError"),
! }
class TestRunner:
--- 21,72 ----
}
! # re to pull apart an exception line into the exception type and the args.
! re_exception = re.compile("([a-zA-Z0-9_.]*): (.*)$")
! def find_exception_in_output(data):
! have_traceback = False
! for line in data.splitlines():
! line = line.decode('ascii') # not sure what the correct encoding is...
! if line.startswith("Traceback ("):
! have_traceback = True
! continue
! if line.startswith(" "):
! continue
! if have_traceback:
! # first line not starting with a space since the traceback.
! # must be the exception!
! m = re_exception.match(line)
! if m:
! exc_type, args = m.groups()
! # get hacky - get the *real* exception object from the name.
! bits = exc_type.split(".", 1)
! if len(bits) > 1:
! mod = __import__(bits[0])
! exc = getattr(mod, bits[1])
! else:
! # probably builtin
! exc = eval(bits[0])
! else:
! # hrm - probably just an exception with no args
! try:
! exc = eval(line.strip())
! args = "()"
! except:
! return None
! # try and turn the args into real args.
! try:
! args = eval(args)
! except:
! pass
! if not isinstance(args, tuple):
! args = (args,)
! # try and instantiate the exception.
! try:
! ret = exc(*args)
! except:
! ret = None
! return ret
! # apparently not - keep looking...
! have_traceback = False
!
class TestRunner:
***************
*** 43,46 ****
--- 90,97 ----
if rc:
base = os.path.basename(self.argv[1])
+ # See if we can detect and reconstruct an exception in the output.
+ reconstituted = find_exception_in_output(output)
+ if reconstituted is not None:
+ raise reconstituted
raise AssertionError("%s failed with exit code %s. Output is:\n%s" % (base, rc, output))
***************
*** 54,60 ****
if ext != ".py" or base in ui_demos or base in bad_demos:
continue
- if base in ok_exceptions:
- print "Ack - can't handle test %s - can't catch specific exceptions" % (base,)
- continue
argv = (sys.executable, os.path.join(demo_dir, base+".py")) + \
argvs.get(base, ())
--- 105,108 ----
***************
*** 114,121 ****
return suite
! class CustomLoader(unittest.TestLoader):
def loadTestsFromModule(self, module):
! return suite()
if __name__=='__main__':
! unittest.TestProgram(testLoader=CustomLoader())(argv=sys.argv)
--- 162,169 ----
return suite
! class CustomLoader(pywin32_testutil.TestLoader):
def loadTestsFromModule(self, module):
! return self.fixupTestsForLeakTests(suite())
if __name__=='__main__':
! pywin32_testutil.testmain(testLoader=CustomLoader())
|