Patchwork [049,of,179,tests-refactor] run-tests: move BINDIR out of a global

login
register
mail settings
Submitter Gregory Szorc
Date May 2, 2014, 6:38 p.m.
Message ID <038c6e6568b02bd8de94.1399055886@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4544/
State Accepted
Commit 2e1aa8c1ee37e9df9a589c600f609245a73134c0
Headers show

Comments

Gregory Szorc - May 2, 2014, 6:38 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397974967 25200
#      Sat Apr 19 23:22:47 2014 -0700
# Branch stable
# Node ID 038c6e6568b02bd8de94d199e783bf9a8a4906f7
# Parent  b74299b5cc81b7ffea4830789b7561041432bcc4
run-tests: move BINDIR 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
@@ -453,17 +453,18 @@  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, 'bindir': BINDIR,
+              'prefix': runner.inst, 'libdir': 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)
         for line in f:
@@ -471,26 +472,26 @@  def installhg(runner, options):
         f.close()
         sys.exit(1)
     os.chdir(runner.testdir)
 
     usecorrectpython()
 
     if options.py3k_warnings and not options.anycoverage:
         vlog("# Updating hg command to enable Py3k Warnings switch")
-        f = open(os.path.join(BINDIR, 'hg'), 'r')
+        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(BINDIR, 'hg'), 'w')
+        f = open(os.path.join(runner.bindir, 'hg'), 'w')
         for line in lines:
             f.write(line + '\n')
         f.close()
 
-    hgbat = os.path.join(BINDIR, 'hg.bat')
+    hgbat = os.path.join(runner.bindir, 'hg.bat')
     if os.path.isfile(hgbat):
         # hg.bat expects to be put in bin/scripts while run-tests.py
         # installation layout put it in bin/ directly. Fix it
         f = open(hgbat, 'rb')
         data = f.read()
         f.close()
         if '"%~dp0..\python" "%~dp0hg" %*' in data:
             data = data.replace('"%~dp0..\python" "%~dp0hg" %*',
@@ -526,17 +527,18 @@  def outputcoverage(runner, options):
     os.chdir(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 [BINDIR, runner.testdir])
+    omit = ','.join(os.path.join(x, '*') for x in
+                    [runner.bindir, runner.testdir])
     covrun('-i', '-r', '"--omit=%s"' % omit) # report
     if options.htmlcov:
         htmldir = os.path.join(runner.testdir, 'htmlcov')
         covrun('-i', '-b', '"--directory=%s"' % htmldir, '"--omit=%s"' % omit)
     if options.annotate:
         adir = os.path.join(runner.testdir, 'annotated')
         if not os.path.isdir(adir):
             os.mkdir(adir)
@@ -1281,16 +1283,17 @@  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
         self.inst = None
+        self.bindir = None
 
 def main(args, parser=None):
     runner = TestRunner()
 
     parser = parser or getparser()
     (options, args) = parseargs(args, parser)
     os.umask(022)
 
@@ -1328,17 +1331,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 BINDIR, TMPBINDIR, PYTHONDIR, COVERAGE_FILE
+    global 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.
@@ -1357,37 +1360,38 @@  def main(args, parser=None):
             # 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)
 
     if options.with_hg:
         runner.inst = None
-        BINDIR = os.path.dirname(os.path.realpath(options.with_hg))
+        runner.bindir = os.path.dirname(os.path.realpath(options.with_hg))
         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
+        PYTHONDIR = runner.bindir
     else:
         runner.inst = os.path.join(runner.hgtmp, "install")
-        BINDIR = os.environ["BINDIR"] = os.path.join(runner.inst, "bin")
-        TMPBINDIR = BINDIR
+        runner.bindir = os.environ["BINDIR"] = os.path.join(runner.inst,
+                                                            "bin")
+        TMPBINDIR = runner.bindir
         PYTHONDIR = os.path.join(runner.inst, "lib", "python")
 
-    os.environ["BINDIR"] = BINDIR
+    os.environ["BINDIR"] = runner.bindir
     os.environ["PYTHON"] = PYTHON
 
-    path = [BINDIR] + os.environ["PATH"].split(os.pathsep)
-    if TMPBINDIR != BINDIR:
+    path = [runner.bindir] + os.environ["PATH"].split(os.pathsep)
+    if TMPBINDIR != runner.bindir:
         path = [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,