[PATCH 047 of 179 tests-refactor] run-tests: move HGTMP out of a global
Gregory Szorc
gregory.szorc at gmail.com
Fri May 2 13:38:04 CDT 2014
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1397974763 25200
# Sat Apr 19 23:19:23 2014 -0700
# Branch stable
# Node ID da4a9d893aa01690f2b3746286b52a974666d9d1
# Parent e45a84e5b9eb089060cfbe21b9470fd72fdaff95
run-tests: move HGTMP 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
@@ -381,20 +381,20 @@ def terminate(proc):
getattr(proc, 'terminate', lambda : os.kill(proc.pid, signal.SIGTERM))()
except OSError:
pass
def killdaemons(pidfile):
return killmod.killdaemons(pidfile, tryhard=False, remove=True,
logfn=vlog)
-def cleanup(options):
+def cleanup(runner, options):
if not options.keep_tmpdir:
- vlog("# Cleaning up HGTMP", HGTMP)
- shutil.rmtree(HGTMP, True)
+ vlog("# Cleaning up HGTMP", runner.hgtmp)
+ shutil.rmtree(runner.hgtmp, True)
for f in createdfiles:
try:
os.remove(f)
except OSError:
pass
def usecorrectpython():
# some tests run python interpreter. they must use same
@@ -452,17 +452,17 @@ def installhg(runner, options):
# least on Windows for now, deal with .pydistutils.cfg bugs
# 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(HGTMP, "build"),
+ 'compiler': compiler, 'base': os.path.join(runner.hgtmp, "build"),
'prefix': INST, 'libdir': PYTHONDIR, 'bindir': BINDIR,
'nohome': nohome, 'logfile': installerrs})
vlog("# Running", cmd)
if os.system(cmd) == 0:
if not options.verbose:
os.remove(installerrs)
else:
f = open(installerrs)
@@ -544,21 +544,21 @@ def outputcoverage(runner, options):
class Test(object):
"""Encapsulates a single, runnable test.
Test instances can be run multiple times via run(). However, multiple
runs cannot be run concurrently.
"""
- def __init__(self, testdir, test, options, count, refpath):
- path = os.path.join(testdir, test)
- errpath = os.path.join(testdir, '%s.err' % test)
+ def __init__(self, runner, test, options, count, refpath):
+ path = os.path.join(runner.testdir, test)
+ errpath = os.path.join(runner.testdir, '%s.err' % test)
- self._testdir = testdir
+ self._testdir = runner.testdir
self._test = test
self._path = path
self._options = options
self._count = count
self._daemonpids = []
self._refpath = refpath
self._errpath = errpath
@@ -568,17 +568,17 @@ class Test(object):
self._refout = None # to match "out is None"
elif os.path.exists(refpath):
f = open(refpath, 'r')
self._refout = f.read().splitlines(True)
f.close()
else:
self._refout = []
- self._threadtmp = os.path.join(HGTMP, 'child%d' % count)
+ self._threadtmp = os.path.join(runner.hgtmp, 'child%d' % count)
os.mkdir(self._threadtmp)
def __del__(self):
for entry in self._daemonpids:
killdaemons(entry)
if self._threadtmp and not self._options.keep_tmpdir:
shutil.rmtree(self._threadtmp, True)
@@ -1096,17 +1096,17 @@ def gettest(runner, test, options, count
testcls = Test
for ext, cls, out in testtypes:
if lctest.endswith(ext):
testcls = cls
refpath = os.path.join(runner.testdir, test + out)
break
- return testcls(runner.testdir, test, options, count, refpath)
+ return testcls(runner, test, options, count, refpath)
wifexited = getattr(os, "WIFEXITED", lambda x: False)
def run(cmd, wd, options, replacements, env):
"""Run command in a sub-process, capturing the output (stdout and stderr).
Return a tuple (exitcode, output). output is None in debug mode."""
# TODO: Use subprocess.Popen if we're running on Python 2.4
if options.debug:
proc = subprocess.Popen(cmd, shell=True, cwd=wd, env=env)
@@ -1279,16 +1279,17 @@ testtypes = [('.py', PythonTest, '.out')
class TestRunner(object):
"""Holds context for executing tests.
Tests rely on a lot of state. This object holds it for them.
"""
def __init__(self):
self.testdir = None
+ self.hgtmp = None
def main(args, parser=None):
runner = TestRunner()
parser = parser or getparser()
(options, args) = parseargs(args, parser)
os.umask(022)
@@ -1326,17 +1327,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 HGTMP, INST, BINDIR, TMPBINDIR, PYTHONDIR, COVERAGE_FILE
+ global INST, BINDIR, TMPBINDIR, PYTHONDIR, 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.
@@ -1351,32 +1352,32 @@ def main(args, parser=None):
os.makedirs(tmpdir)
else:
d = None
if os.name == 'nt':
# without this, we get the default temp dir location, but
# in all lowercase, which causes troubles with paths (issue3490)
d = os.getenv('TMP')
tmpdir = tempfile.mkdtemp('', 'hgtests.', d)
- HGTMP = os.environ['HGTMP'] = os.path.realpath(tmpdir)
+ runner.hgtmp = os.environ['HGTMP'] = os.path.realpath(tmpdir)
if options.with_hg:
INST = None
BINDIR = os.path.dirname(os.path.realpath(options.with_hg))
- TMPBINDIR = os.path.join(HGTMP, 'install', 'bin')
+ TMPBINDIR = os.path.join(runner.hgtmp, 'install', 'bin')
os.makedirs(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 = BINDIR
else:
- INST = os.path.join(HGTMP, "install")
+ INST = os.path.join(runner.hgtmp, "install")
BINDIR = os.environ["BINDIR"] = os.path.join(INST, "bin")
TMPBINDIR = BINDIR
PYTHONDIR = os.path.join(INST, "lib", "python")
os.environ["BINDIR"] = BINDIR
os.environ["PYTHON"] = PYTHON
path = [BINDIR] + os.environ["PATH"].split(os.pathsep)
@@ -1397,20 +1398,20 @@ def main(args, parser=None):
oldpypath = os.environ.get(IMPL_PATH)
if oldpypath:
pypath.append(oldpypath)
os.environ[IMPL_PATH] = os.pathsep.join(pypath)
COVERAGE_FILE = os.path.join(runner.testdir, ".coverage")
vlog("# Using TESTDIR", runner.testdir)
- vlog("# Using HGTMP", HGTMP)
+ vlog("# Using HGTMP", runner.hgtmp)
vlog("# Using PATH", os.environ["PATH"])
vlog("# Using", IMPL_PATH, os.environ[IMPL_PATH])
try:
return runtests(runner, options, tests) or 0
finally:
time.sleep(.1)
- cleanup(options)
+ cleanup(runner, options)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
More information about the Mercurial-devel
mailing list