Patchwork [073,of,179,tests-refactor] run-tests: move more path calculations into TestRunner

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

Comments

Gregory Szorc - May 2, 2014, 6:38 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1398013022 25200
#      Sun Apr 20 09:57:02 2014 -0700
# Branch stable
# Node ID 9c53769a80a109414541088512bea3894b908e70
# Parent  37dced6af8bec7f3957ba90fa7245c97224b3412
run-tests: move more path calculations into TestRunner

Patch

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,44 @@  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.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
+            # 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.
+            self.pythondir = self.bindir
+        else:
+            self.inst = os.path.join(self.hgtmp, "install")
+            self.bindir = os.environ["BINDIR"] = os.path.join(self.inst,
+                                                              "bin")
+            self.tmpbindir = self.bindir
+            self.pythondir = os.path.join(self.inst, "lib", "python")
+
+        os.environ["BINDIR"] = self.bindir
+        os.environ["PYTHON"] = PYTHON
+
+        path = [self.bindir] + os.environ["PATH"].split(os.pathsep)
+        if self.tmpbindir != self.bindir:
+            path = [self.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 = [self.pythondir, self.testdir,
                   os.path.abspath(os.path.dirname(__file__))]
         # We have to augment PYTHONPATH, rather than simply replacing
         # it, in case external libraries are only available via current
@@ -1434,39 +1462,12 @@  def main(args, runner=None, parser=None)
         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)
 
-    if options.with_hg:
-        runner.inst = None
-        runner.bindir = os.path.dirname(os.path.realpath(options.with_hg))
-        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.
-        runner.pythondir = runner.bindir
-    else:
-        runner.inst = os.path.join(runner.hgtmp, "install")
-        runner.bindir = os.environ["BINDIR"] = os.path.join(runner.inst,
-                                                            "bin")
-        runner.tmpbindir = runner.bindir
-        runner.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 runner.tmpbindir != runner.bindir:
-        path = [runner.tmpbindir] + path
-    os.environ["PATH"] = os.pathsep.join(path)
-
     return runner.run(tests)
 
 if __name__ == '__main__':
     sys.exit(main(sys.argv[1:]))