Patchwork [050,of,179,tests-refactor] run-tests: move TMPBINDIR out of a global

login
register
mail settings
Submitter Gregory Szorc
Date May 2, 2014, 6:38 p.m.
Message ID <98f122246d2f70f62b6f.1399055887@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4545/
State Accepted
Commit 8e7b0f4d6ac73b133e9a1eeb8976550e1b2bb49d
Headers show

Comments

Gregory Szorc - May 2, 2014, 6:38 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397975079 25200
#      Sat Apr 19 23:24:39 2014 -0700
# Branch stable
# Node ID 98f122246d2f70f62b6fe9d46890690bfcafa399
# Parent  038c6e6568b02bd8de94d199e783bf9a8a4906f7
run-tests: move TMPBINDIR out of a global

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -391,24 +391,24 @@  def cleanup(runner, options):
         vlog("# Cleaning up HGTMP", runner.hgtmp)
         shutil.rmtree(runner.hgtmp, True)
         for f in createdfiles:
             try:
                 os.remove(f)
             except OSError:
                 pass
 
-def usecorrectpython():
+def usecorrectpython(runner):
     # some tests run python interpreter. they must use same
     # interpreter we use or bad things will happen.
     pyexename = sys.platform == 'win32' and 'python.exe' or 'python'
     if getattr(os, 'symlink', None):
         vlog("# Making python executable in test path a symlink to '%s'" %
              sys.executable)
-        mypython = os.path.join(TMPBINDIR, pyexename)
+        mypython = os.path.join(runner.tmpbindir, pyexename)
         try:
             if os.readlink(mypython) == sys.executable:
                 return
             os.unlink(mypython)
         except OSError, err:
             if err.errno != errno.ENOENT:
                 raise
         if findprogram(pyexename) != sys.executable:
@@ -468,17 +468,17 @@  def installhg(runner, options):
     else:
         f = open(installerrs)
         for line in f:
             print line,
         f.close()
         sys.exit(1)
     os.chdir(runner.testdir)
 
-    usecorrectpython()
+    usecorrectpython(runner)
 
     if options.py3k_warnings and not options.anycoverage:
         vlog("# Updating hg command to enable Py3k Warnings switch")
         f = open(os.path.join(runner.bindir, 'hg'), 'r')
         lines = [line.rstrip() for line in f]
         lines[0] += ' -3'
         f.close()
         f = open(os.path.join(runner.bindir, 'hg'), 'w')
@@ -1224,17 +1224,17 @@  def scheduletests(runner, options, tests
         abort = True
 
 def runtests(runner, options, tests):
     try:
         if runner.inst:
             installhg(runner, options)
             _checkhglib("Testing")
         else:
-            usecorrectpython()
+            usecorrectpython(runner)
 
         if options.restart:
             orig = list(tests)
             while tests:
                 if os.path.exists(tests[0] + ".err"):
                     break
                 tests.pop(0)
             if not tests:
@@ -1284,16 +1284,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
 
 def main(args, parser=None):
     runner = TestRunner()
 
     parser = parser or getparser()
     (options, args) = parseargs(args, parser)
     os.umask(022)
 
@@ -1331,17 +1332,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 TMPBINDIR, PYTHONDIR, COVERAGE_FILE
+    global 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.
@@ -1361,38 +1362,38 @@  def main(args, parser=None):
             # 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)
 
     if options.with_hg:
         runner.inst = None
         runner.bindir = os.path.dirname(os.path.realpath(options.with_hg))
-        TMPBINDIR = os.path.join(runner.hgtmp, 'install', 'bin')
-        os.makedirs(TMPBINDIR)
+        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
     else:
         runner.inst = os.path.join(runner.hgtmp, "install")
         runner.bindir = os.environ["BINDIR"] = os.path.join(runner.inst,
                                                             "bin")
-        TMPBINDIR = runner.bindir
+        runner.tmpbindir = runner.bindir
         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 TMPBINDIR != runner.bindir:
-        path = [TMPBINDIR] + path
+    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,
               os.path.abspath(os.path.dirname(__file__))]