Patchwork [048,of,179,tests-refactor] run-tests: move INST out of a global

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

Comments

Gregory Szorc - May 2, 2014, 6:38 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397974842 25200
#      Sat Apr 19 23:20:42 2014 -0700
# Branch stable
# Node ID b74299b5cc81b7ffea4830789b7561041432bcc4
# Parent  da4a9d893aa01690f2b3746286b52a974666d9d1
run-tests: move INST 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,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': INST, 'libdir': PYTHONDIR, 'bindir': BINDIR,
+              'prefix': runner.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)
         for line in f:
@@ -504,17 +504,17 @@  def installhg(runner, options):
     if options.anycoverage:
         custom = os.path.join(runner.testdir, 'sitecustomize.py')
         target = os.path.join(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(INST, '..', '.coverage')
+        fn = os.path.join(runner.inst, '..', '.coverage')
         os.environ['COVERAGE_FILE'] = fn
 
 def outputtimes(options):
     vlog('# Producing time report')
     times.sort(key=lambda t: (t[1], t[0]), reverse=True)
     cols = '%7.3f   %s'
     print '\n%-7s   %s' % ('Time', 'Test')
     for test, timetaken in times:
@@ -1218,17 +1218,17 @@  def scheduletests(runner, options, tests
                 t.start()
                 running += 1
                 count += 1
     except KeyboardInterrupt:
         abort = True
 
 def runtests(runner, options, tests):
     try:
-        if INST:
+        if runner.inst:
             installhg(runner, options)
             _checkhglib("Testing")
         else:
             usecorrectpython()
 
         if options.restart:
             orig = list(tests)
             while tests:
@@ -1280,16 +1280,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
+        self.inst = None
 
 def main(args, parser=None):
     runner = TestRunner()
 
     parser = parser or getparser()
     (options, args) = parseargs(args, parser)
     os.umask(022)
 
@@ -1327,17 +1328,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 INST, BINDIR, TMPBINDIR, PYTHONDIR, COVERAGE_FILE
+    global 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.
@@ -1355,32 +1356,32 @@  def main(args, parser=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)
 
     if options.with_hg:
-        INST = None
+        runner.inst = None
         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
     else:
-        INST = os.path.join(runner.hgtmp, "install")
-        BINDIR = os.environ["BINDIR"] = os.path.join(INST, "bin")
+        runner.inst = os.path.join(runner.hgtmp, "install")
+        BINDIR = os.environ["BINDIR"] = os.path.join(runner.inst, "bin")
         TMPBINDIR = BINDIR
-        PYTHONDIR = os.path.join(INST, "lib", "python")
+        PYTHONDIR = os.path.join(runner.inst, "lib", "python")
 
     os.environ["BINDIR"] = BINDIR
     os.environ["PYTHON"] = PYTHON
 
     path = [BINDIR] + os.environ["PATH"].split(os.pathsep)
     if TMPBINDIR != BINDIR:
         path = [TMPBINDIR] + path
     os.environ["PATH"] = os.pathsep.join(path)