[PATCH 051 of 179 tests-refactor] run-tests: move PYTHONDIR out of a global
Gregory Szorc
gregory.szorc at gmail.com
Fri May 2 13:38:08 CDT 2014
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1397975175 25200
# Sat Apr 19 23:26:15 2014 -0700
# Branch stable
# Node ID ac0350f0cee1c2e23bab3aa275e5bb7560500040
# Parent 98f122246d2f70f62b6fe9d46890690bfcafa399
run-tests: move PYTHONDIR out of a global
diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -453,17 +453,17 @@ def installhg(runner, options):
# when they happen.
nohome = ''
cmd = ('%(exe)s setup.py %(py3)s %(pure)s clean --all'
' build %(compiler)s --build-base="%(base)s"'
' install --force --prefix="%(prefix)s" --install-lib="%(libdir)s"'
' --install-scripts="%(bindir)s" %(nohome)s >%(logfile)s 2>&1'
% {'exe': sys.executable, 'py3': py3, 'pure': pure,
'compiler': compiler, 'base': os.path.join(runner.hgtmp, "build"),
- 'prefix': runner.inst, 'libdir': PYTHONDIR,
+ 'prefix': runner.inst, 'libdir': runner.pythondir,
'bindir': runner.bindir,
'nohome': nohome, 'logfile': installerrs})
vlog("# Running", cmd)
if os.system(cmd) == 0:
if not options.verbose:
os.remove(installerrs)
else:
f = open(installerrs)
@@ -499,17 +499,17 @@ def installhg(runner, options):
f = open(hgbat, 'wb')
f.write(data)
f.close()
else:
print 'WARNING: cannot fix hg.bat reference to python.exe'
if options.anycoverage:
custom = os.path.join(runner.testdir, 'sitecustomize.py')
- target = os.path.join(PYTHONDIR, 'sitecustomize.py')
+ target = os.path.join(runner.pythondir, 'sitecustomize.py')
vlog('# Installing coverage trigger to %s' % target)
shutil.copyfile(custom, target)
rc = os.path.join(runner.testdir, '.coveragerc')
vlog('# Installing coverage rc to %s' % rc)
os.environ['COVERAGE_PROCESS_START'] = rc
fn = os.path.join(runner.inst, '..', '.coverage')
os.environ['COVERAGE_FILE'] = fn
@@ -519,17 +519,17 @@ def outputtimes(options):
cols = '%7.3f %s'
print '\n%-7s %s' % ('Time', 'Test')
for test, timetaken in times:
print cols % (timetaken, test)
def outputcoverage(runner, options):
vlog('# Producing coverage report')
- os.chdir(PYTHONDIR)
+ os.chdir(runner.pythondir)
def covrun(*args):
cmd = 'coverage %s' % ' '.join(args)
vlog('# Running: %s' % cmd)
os.system(cmd)
covrun('-c')
omit = ','.join(os.path.join(x, '*') for x in
@@ -1163,20 +1163,20 @@ def _gethgpath():
cmd = '%s -c "import mercurial; print (mercurial.__path__[0])"'
pipe = os.popen(cmd % PYTHON)
try:
_hgpath = pipe.read().strip()
finally:
pipe.close()
return _hgpath
-def _checkhglib(verb):
+def _checkhglib(runner, verb):
"""Ensure that the 'mercurial' package imported by python is
the one we expect it to be. If not, print a warning to stderr."""
- expecthg = os.path.join(PYTHONDIR, 'mercurial')
+ expecthg = os.path.join(runner.pythondir, 'mercurial')
actualhg = _gethgpath()
if os.path.abspath(actualhg) != os.path.abspath(expecthg):
sys.stderr.write('warning: %s with unexpected mercurial lib: %s\n'
' (expected %s)\n'
% (verb, actualhg, expecthg))
results = {'.':[], '!':[], '~': [], 's':[], 'i':[]}
times = []
@@ -1222,17 +1222,17 @@ def scheduletests(runner, options, tests
count += 1
except KeyboardInterrupt:
abort = True
def runtests(runner, options, tests):
try:
if runner.inst:
installhg(runner, options)
- _checkhglib("Testing")
+ _checkhglib(runner, "Testing")
else:
usecorrectpython(runner)
if options.restart:
orig = list(tests)
while tests:
if os.path.exists(tests[0] + ".err"):
break
@@ -1252,17 +1252,17 @@ def runtests(runner, options, tests):
print
if not options.noskips:
for s in results['s']:
print "Skipped %s: %s" % s
for s in results['~']:
print "Warned %s: %s" % s
for s in results['!']:
print "Failed %s: %s" % s
- _checkhglib("Tested")
+ _checkhglib(runner, "Tested")
print "# Ran %d tests, %d skipped, %d warned, %d failed." % (
tested, skipped + ignored, warned, failed)
if results['!']:
print 'python hash seed:', os.environ['PYTHONHASHSEED']
if options.time:
outputtimes(options)
if options.anycoverage:
@@ -1285,16 +1285,17 @@ class TestRunner(object):
Tests rely on a lot of state. This object holds it for them.
"""
def __init__(self):
self.testdir = None
self.hgtmp = None
self.inst = None
self.bindir = None
self.tmpbinddir = None
+ self.pythondir = None
def main(args, parser=None):
runner = TestRunner()
parser = parser or getparser()
(options, args) = parseargs(args, parser)
os.umask(022)
@@ -1332,17 +1333,17 @@ def main(args, parser=None):
return val
tests.sort(key=sortkey)
if 'PYTHONHASHSEED' not in os.environ:
# use a random python hash seed all the time
# we do the randomness ourself to know what seed is used
os.environ['PYTHONHASHSEED'] = str(random.getrandbits(32))
- global PYTHONDIR, COVERAGE_FILE
+ global COVERAGE_FILE
runner.testdir = os.environ['TESTDIR'] = os.getcwd()
if options.tmpdir:
options.keep_tmpdir = True
tmpdir = options.tmpdir
if os.path.exists(tmpdir):
# Meaning of tmpdir has changed since 1.3: we used to create
# HGTMP inside tmpdir; now HGTMP is tmpdir. So fail if
# tmpdir already exists.
@@ -1370,37 +1371,37 @@ def main(args, parser=None):
runner.tmpbindir = os.path.join(runner.hgtmp, 'install', 'bin')
os.makedirs(runner.tmpbindir)
# This looks redundant with how Python initializes sys.path from
# the location of the script being executed. Needed because the
# "hg" specified by --with-hg is not the only Python script
# executed in the test suite that needs to import 'mercurial'
# ... which means it's not really redundant at all.
- PYTHONDIR = runner.bindir
+ runner.pythondir = runner.bindir
else:
runner.inst = os.path.join(runner.hgtmp, "install")
runner.bindir = os.environ["BINDIR"] = os.path.join(runner.inst,
"bin")
runner.tmpbindir = runner.bindir
- PYTHONDIR = os.path.join(runner.inst, "lib", "python")
+ runner.pythondir = os.path.join(runner.inst, "lib", "python")
os.environ["BINDIR"] = runner.bindir
os.environ["PYTHON"] = PYTHON
path = [runner.bindir] + os.environ["PATH"].split(os.pathsep)
if runner.tmpbindir != runner.bindir:
path = [runner.tmpbindir] + path
os.environ["PATH"] = os.pathsep.join(path)
# Include TESTDIR in PYTHONPATH so that out-of-tree extensions
# can run .../tests/run-tests.py test-foo where test-foo
# adds an extension to HGRC. Also include run-test.py directory to import
# modules like heredoctest.
- pypath = [PYTHONDIR, runner.testdir,
+ pypath = [runner.pythondir, runner.testdir,
os.path.abspath(os.path.dirname(__file__))]
# We have to augment PYTHONPATH, rather than simply replacing
# it, in case external libraries are only available via current
# PYTHONPATH. (In particular, the Subversion bindings on OS X
# are in /opt/subversion.)
oldpypath = os.environ.get(IMPL_PATH)
if oldpypath:
pypath.append(oldpypath)
More information about the Mercurial-devel
mailing list