[PATCH 074 of 179 tests-refactor] run-tests: move tmpdir calculations into TestRunner
Gregory Szorc
gregory.szorc at gmail.com
Fri May 2 13:38:31 CDT 2014
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1398013106 25200
# Sun Apr 20 09:58:26 2014 -0700
# Branch stable
# Node ID 294b4e4d280cdedb9a01b4887272d39fe0c848f4
# Parent 9c53769a80a109414541088512bea3894b908e70
run-tests: move tmpdir calculations into TestRunner
diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1019,16 +1019,41 @@ class TestRunner(object):
oldenv = dict(os.environ)
try:
return self._run(tests)
finally:
os.environ.clear()
os.environ.update(oldenv)
def _run(self, tests):
+ if self.options.tmpdir:
+ self.options.keep_tmpdir = True
+ tmpdir = self.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.
+ print "error: temp dir %r already exists" % tmpdir
+ return 1
+
+ # Automatically removing tmpdir sounds convenient, but could
+ # really annoy anyone in the habit of using "--tmpdir=/tmp"
+ # or "--tmpdir=$HOME".
+ #vlog("# Removing temp dir", tmpdir)
+ #shutil.rmtree(tmpdir)
+ 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)
+ self.hgtmp = os.environ['HGTMP'] = os.path.realpath(tmpdir)
+
if self.options.with_hg:
self.inst = None
self.bindir = os.path.dirname(os.path.realpath(
self.options.with_hg))
self.tmpbindir = os.path.join(self.hgtmp, 'install', 'bin')
os.makedirs(self.tmpbindir)
# This looks redundant with how Python initializes sys.path from
@@ -1437,37 +1462,13 @@ def main(args, runner=None, parser=None)
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))
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.
- print "error: temp dir %r already exists" % tmpdir
- return 1
-
- # Automatically removing tmpdir sounds convenient, but could
- # really annoy anyone in the habit of using "--tmpdir=/tmp"
- # or "--tmpdir=$HOME".
- #vlog("# Removing temp dir", tmpdir)
- #shutil.rmtree(tmpdir)
- 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)
- runner.hgtmp = os.environ['HGTMP'] = os.path.realpath(tmpdir)
return runner.run(tests)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
More information about the Mercurial-devel
mailing list