[Zope3-checkins] CVS: Zope3 - test.py:1.35
Tres Seaver
tseaver@zope.com
Wed, 5 Feb 2003 09:15:51 -0500
Update of /cvs-repository/Zope3
In directory cvs.zope.org:/tmp/cvs-serv6439
Modified Files:
test.py
Log Message:
- Add a command-line option, '--libdir', which changes the "prefix"
directory used by the test finder (the prefix will also be forced
into sys.path). This option allows a "product" developer to use the
test framework to run unit tests for product modules which are
outside the Zope3 source tree. Example usage:
$ python2.2 test.py --libdir ../zopeproducts
Running tests from /opt/home/tseaver/projects/Zope3/../zopeproducts
----------------------------------------------------------------------
Ran 26 tests in 0.103s
OK
=== Zope3/test.py 1.34 => 1.35 ===
--- Zope3/test.py:1.34 Wed Dec 25 09:12:09 2002
+++ Zope3/test.py Wed Feb 5 09:15:48 2003
@@ -52,6 +52,11 @@
-h / --help
Print this help text and exit.
+ / --libdir test_root
+ Search for tests starting in the specified start directory
+ (useful for testing components being developed outside the main
+ 'src' or 'build' trees).
+
-L
Keep running the selected tests in a loop. You may experience memory
leakage, but this is a handy option for catching race conditions.
@@ -250,7 +255,7 @@
# setup list of directories to put on the path
class PathInit:
- def __init__(self, build, build_inplace):
+ def __init__(self, build, build_inplace, libdir=None):
self.inplace = None
# Figure out if we should test in-place or test in-build. If the -b
# or -B option was given, test in the place we were told to build in.
@@ -266,6 +271,7 @@
self.inplace = True
# Calculate which directories we're going to add to sys.path, and cd
# to the appropriate working directory
+ org_cwd = os.getcwd()
if self.inplace:
self.libdir = 'src'
else:
@@ -273,8 +279,16 @@
os.chdir('build')
# Hack sys.path
self.cwd = os.getcwd()
- print 'Running tests from', self.cwd
sys.path.insert(0, os.path.join(self.cwd, self.libdir))
+ # Hack again for external products.
+ if libdir:
+ extra = os.path.join(org_cwd, libdir)
+ print 'Running tests from', extra
+ self.libdir = extra
+ sys.path.insert(0, extra)
+ else:
+ print 'Running tests from', self.cwd
+
def match(rx, s):
@@ -425,7 +439,7 @@
os.unlink(fullname)
-def main(module_filter, test_filter):
+def main(module_filter, test_filter, libdir):
global pathinit
os.path.walk(os.curdir, remove_stale_bytecode, None)
@@ -437,7 +451,7 @@
logini = os.path.abspath('log.ini')
# Initialize the path and cwd
- pathinit = PathInit(build, build_inplace)
+ pathinit = PathInit(build, build_inplace, libdir)
# Initialize the logging module.
import logging.config
@@ -480,6 +494,7 @@
global debug
global debugger
global build
+ global libdir
global gcthresh
global progress
global build_inplace
@@ -498,6 +513,7 @@
debugger = False
build = False
build_inplace = False
+ libdir = None
gcthresh = None
gcflags = []
progress = False
@@ -505,7 +521,7 @@
try:
opts, args = getopt.getopt(argv[1:],
'bBcdDg:G:hLumpTv',
- ['help'])
+ ['help', 'libdir='])
except getopt.error, msg:
print msg
print "Try `python %s -h' for more information." % argv[0]
@@ -534,6 +550,8 @@
elif k in ('-h', '--help'):
print __doc__ % globals()
sys.exit(0)
+ elif k == '--libdir':
+ libdir = v
elif k == '-L':
LOOP = True
elif k == '-u':
@@ -582,7 +600,7 @@
test_filter = args[1]
module_filter = args[0]
try:
- bad = main(module_filter, test_filter)
+ bad = main(module_filter, test_filter, libdir)
if bad:
sys.exit(1)
except ImportError, err: