[Zodb-checkins] CVS: StandaloneZODB - test.py:1.12
Jeremy Hylton
jeremy@zope.com
Fri, 25 Jan 2002 15:17:10 -0500
Update of /cvs-repository/StandaloneZODB
In directory cvs.zope.org:/tmp/cvs-serv31637
Modified Files:
test.py
Log Message:
Revised test script based on one used for StandbyStorage.
=== StandaloneZODB/test.py 1.11 => 1.12 ===
+"""Test harness for StandaloneZODB"""
-The test harness was written for Python 2.1 and requires some
-hand-holding to use with Python 1.5.2. The tests require:
-
- 1) a recent version of unittest, which can be downloaded from
- pyunit.sourceforge.net;
-
- 2) distutils, which can be downloaded from
- www.python.org/sigs/distutils-sig/;
-
- and, if the ZEO tests are to be run,
-
- 3) a built version of Zope 2.3, which provides up-to-date versions
- of asyncore and cPickle.
-
-There are some complications, however, because the StandaloneZODB
-includes code from Zope 2.4, which requires Python 2.1. If the Zope
-top-level directory and lib/python directories are added to the path,
-the BTrees tests will fail, because they pick up an old version of the
-Interface module. But the ZEO tests won't run *without* Zope on the
-path. So it's one or the other.
-"""
-
-import gc
import os
import re
-import string
import sys
+import traceback
import unittest
+
from distutils.util import get_platform
+class ImmediateTestResult(unittest._TextTestResult):
+
+ def _print_traceback(self, msg, err, test, errlist):
+ if self.showAll or self.dots:
+ self.stream.writeln("\n")
+
+ tb = ''.join(traceback.format_exception(*err))
+ self.stream.writeln(msg)
+ self.stream.writeln(tb)
+ errlist.append((test, tb))
+
+ def addError(self, test, err):
+ self._print_traceback("Error in test %s" % test, err,
+ test, self.errors)
+
+ def addFailure(self, test, err):
+ self._print_traceback("Failure in test %s" % test, err,
+ test, self.failures)
+
+ def printErrorList(self, flavor, errors):
+ for test, err in errors:
+ self.stream.writeln(self.separator1)
+ self.stream.writeln("%s: %s" % (flavor, self.getDescription(test)))
+ self.stream.writeln(self.separator2)
+ self.stream.writeln(err)
+
+
+class ImmediateTestRunner(unittest.TextTestRunner):
+
+ def _makeResult(self):
+ return ImmediateTestResult(self.stream, self.descriptions,
+ self.verbosity)
+
# setup list of directories to put on the path
+PLAT_SPEC = "%s-%s" % (get_platform(), sys.version[0:3])
+
def setup_path():
- PLAT_SPEC = "%s-%s" % (get_platform(), sys.version[0:3])
DIRS = ["lib",
"lib.%s" % PLAT_SPEC,
- "../ExtensionClass/build/lib.%s" % PLAT_SPEC,
]
for d in DIRS:
sys.path.insert(0, d)
-# find test files
+
+# Find test files.
+# They live under either a lib.PLAT_SPEC or plain "lib" directory.
+_sep = re.escape(os.sep)
+_pat = "%s(%s|lib)%s" % (_sep, re.escape("lib." + PLAT_SPEC), _sep)
+hasgooddir = re.compile(_pat).search
+del _sep, _pat
+
class TestFileFinder:
def __init__(self):
self.files = []
@@ -56,6 +74,9 @@
for file in files:
if file[:4] == "test" and file[-3:] == ".py":
path = os.path.join(dir, file)
+ if not hasgooddir(path):
+ # built for a different version
+ continue
if rx is not None:
if rx.search(path):
self.files.append(path)
@@ -73,7 +94,7 @@
def package_import(modname):
mod = __import__(modname)
- for part in string.split(modname, ".")[1:]:
+ for part in modname.split(".")[1:]:
mod = getattr(mod, part)
return mod
@@ -90,34 +111,7 @@
dirs.insert(0, end)
assert dirs[0] == "build"
assert dirs[1][:3] == "lib"
- return string.join(dirs[2:], '.')
-
-if sys.platform == "linux2":
- _pid = os.getpid()
-
- def check_mem():
- vm = {}
- order = []
- f = open("/proc/%d/status" % _pid)
- for line in f.readlines():
- if line[:2] == 'Vm':
- field, val = string.split(line, ':', 2)
- val = string.strip(val)
- vm[field] = val
- order.append((field, max(len(field), len(val))))
- f.close()
- for field, size in order:
- fmt = "%%%ds " % size
- print fmt % field,
- print
- for field, size in order:
- fmt = "%%%ds " % size
- print fmt % vm[field],
- print
-else:
- # not sure what to do on any other platform
- def check_mem():
- pass
+ return ".".join(dirs[2:])
def get_suite(file):
assert file[:5] == "build"
@@ -129,64 +123,31 @@
except AttributeError:
return None
-import traceback
-
-class ImmediateTestResult(unittest._TextTestResult):
-
- def _print_traceback(self, msg, err):
- if self.showAll or self.dots:
- self.stream.writeln("\n")
-
- self.stream.writeln(msg)
- self.stream.writeln(''.join(traceback.format_exception(*err)))
-
-
- def addError(self, test, err):
- self._print_traceback("Error in test %s" % test, err)
-
- def addFailure(self, test, err):
- self._print_traceback("Failure in test %s" % test, err)
-
-class ImmediateTestRunner(unittest.TextTestRunner):
-
- def _makeResult(self):
- return ImmediateTestResult(self.stream, self.descriptions, self.verbosity)
+def runner(files, debug):
+ runner = ImmediateTestRunner(verbosity=VERBOSE)
+ suite = unittest.TestSuite()
+ for file in files:
+ s = get_suite(file)
+ if s is not None:
+ suite.addTest(s)
+ if debug:
+ suite.debug()
+ return 0
+ r = runner.run(suite)
+ return len(r.errors) + len(r.failures)
def main(filter=None):
setup_path()
files = find_tests(filter)
+ files.sort()
os.chdir("build")
if LOOP:
- suites = []
- for file in files:
- suite = get_suite(file)
- if suite is None:
- continue
- suites.append(suite)
- if suites:
- runner = ImmediateTestRunner(verbosity=VERBOSE)
- while 1:
- for suite in suites:
- runner.run(suite)
- gc.collect()
- check_mem()
+ while 1:
+ runner(files, debug)
else:
- runner = ImmediateTestRunner(verbosity=VERBOSE)
- if MERGE_SUITES:
- suite = unittest.TestSuite()
- for file in files:
- s = get_suite(file)
- if s is not None:
- suite.addTest(s)
- runner.run(suite)
- else:
- for file in files:
- suite = get_suite(file)
- if suite is None:
- continue
- runner.run(suite)
+ runner(files, debug)
if __name__ == "__main__":
import getopt
@@ -194,20 +155,35 @@
filter = None
VERBOSE = 0
LOOP = 0
- MERGE_SUITES = 1
+ debug = 0 # Don't collect test results; simply let tests crash
+ build = 0
- opts, args = getopt.getopt(sys.argv[1:], 'vLi')
+ opts, args = getopt.getopt(sys.argv[1:], 'vdLb')
for k, v in opts:
if k == '-v':
VERBOSE = VERBOSE + 1
+ elif k == '-d':
+ debug = 1
elif k == '-L':
LOOP = 1
- elif k == '-i':
- MERGE_SUITES = 0
+ elif k == '-b':
+ build = 1
+
+ if build:
+ cmd = sys.executable + " setup.py -q build"
+ if VERBOSE:
+ print cmd
+ sts = os.system(cmd)
+ if sts:
+ print "Build failed", hex(sts)
+ sys.exit(1)
+
if args:
filter = args[0]
try:
- main(filter)
+ bad = main(filter)
+ if bad:
+ sys.exit(1)
except ImportError, err:
print err
print sys.path