[PATCH 1 of 3] run-tests: factor out _checkhglib(); move _hgpath() next to it
Greg Ward
greg-hg at gerg.ca
Mon May 18 21:55:18 CDT 2009
# HG changeset patch
# User Greg Ward <greg-hg at gerg.ca>
# Date 1242700441 14400
# Node ID bb8131fcd7232b09192a9cba159c22ee7cec3f98
# Parent f38ec158a7c087c5e8c6352fbdd093e4e658b9fb
run-tests: factor out _checkhglib(); move _hgpath() next to it.
diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -234,8 +234,6 @@
os.environ["PYTHONPATH"] = pythonpath
usecorrectpython()
- global hgpkg
- hgpkg = _hgpath()
vlog("# Installing dummy diffstat")
f = open(os.path.join(BINDIR, 'diffstat'), 'w')
@@ -267,13 +265,6 @@
PYTHON = '"%s" "%s" -x' % (sys.executable,
os.path.join(TESTDIR,'coverage.py'))
-def _hgpath():
- cmd = '%s -c "import mercurial; print mercurial.__path__[0]"'
- hgpath = os.popen(cmd % PYTHON)
- path = hgpath.read().strip()
- hgpath.close()
- return path
-
def outputcoverage(options):
vlog("# Producing coverage report")
omit = [BINDIR, TESTDIR, PYTHONDIR]
@@ -488,11 +479,31 @@
return None
return ret == 0
-def runchildren(options, expecthg, tests):
+_actualhg = None
+
+def _hgpath():
+ """Return the path to the mercurial package that is actually found by
+ the current Python interpreter."""
+ cmd = '%s -c "import mercurial; print mercurial.__path__[0]"'
+ hgpath = os.popen(cmd % PYTHON)
+ path = hgpath.read().strip()
+ hgpath.close()
+ return path
+
+def _checkhglib(verb):
+ """Ensure that the 'mercurial' package imported by python is
+ the one we expect it to be. If not, print a message to stdout."""
+ expecthg = os.path.join(HGTMP, 'install', 'lib', 'python', 'mercurial')
+ global _actualhg
+ if _actualhg is None:
+ _actualhg = _hgpath()
+ if _actualhg != expecthg:
+ print '# %s unexpected mercurial: %s' % (verb, _actualhg)
+
+def runchildren(options, tests):
if not options.with_hg:
installhg(options)
- if hgpkg != expecthg:
- print '# Testing unexpected mercurial: %s' % hgpkg
+ _checkhglib("Testing")
optcopy = dict(options.__dict__)
optcopy['jobs'] = 1
@@ -546,13 +557,12 @@
for s in fails:
print "Failed %s: %s" % (s[0], s[1])
- if hgpkg != expecthg:
- print '# Tested unexpected mercurial: %s' % hgpkg
+ _checkhglib("Tested")
print "# Ran %d tests, %d skipped, %d failed." % (
tested, skipped, failed)
sys.exit(failures != 0)
-def runtests(options, expecthg, tests):
+def runtests(options, tests):
global DAEMON_PIDS, HGRCPATH
DAEMON_PIDS = os.environ["DAEMON_PIDS"] = os.path.join(HGTMP, 'daemon.pids')
HGRCPATH = os.environ["HGRCPATH"] = os.path.join(HGTMP, '.hgrc')
@@ -560,9 +570,7 @@
try:
if not options.with_hg:
installhg(options)
-
- if hgpkg != expecthg:
- print '# Testing unexpected mercurial: %s' % hgpkg
+ _checkhglib("Testing")
if options.timeout > 0:
try:
@@ -624,8 +632,7 @@
print "Skipped %s: %s" % s
for s in fails:
print "Failed %s: %s" % s
- if hgpkg != expecthg:
- print '# Tested unexpected mercurial: %s' % hgpkg
+ _checkhglib("Tested")
print "# Ran %d tests, %d skipped, %d failed." % (
tested, skipped, failed)
@@ -676,8 +683,6 @@
PYTHONDIR = os.path.join(INST, "lib", "python")
COVERAGE_FILE = os.path.join(TESTDIR, ".coverage")
- expecthg = os.path.join(HGTMP, 'install', 'lib', 'python', 'mercurial')
-
if len(args) == 0:
args = os.listdir(".")
args.sort()
@@ -694,9 +699,9 @@
try:
if len(tests) > 1 and options.jobs > 1:
- runchildren(options, expecthg, tests)
+ runchildren(options, tests)
else:
- runtests(options, expecthg, tests)
+ runtests(options, tests)
finally:
cleanup(options)
More information about the Mercurial-devel
mailing list