[PATCH 056 of 179 tests-refactor] run-tests: move usecorrectpython() into TestRunner

Gregory Szorc gregory.szorc at gmail.com
Fri May 2 13:38:13 CDT 2014


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1397975890 25200
#      Sat Apr 19 23:38:10 2014 -0700
# Branch stable
# Node ID 35dd393f44232598842b1e49662b6380de0ae444
# Parent  4d8e2732fbd151f0c1121c02d19b88ab0eec5d58
run-tests: move usecorrectpython() into TestRunner

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -381,50 +381,16 @@ def terminate(proc):
         getattr(proc, 'terminate', lambda : os.kill(proc.pid, signal.SIGTERM))()
     except OSError:
         pass
 
 def killdaemons(pidfile):
     return killmod.killdaemons(pidfile, tryhard=False, remove=True,
                                logfn=vlog)
 
-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(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:
-            try:
-                os.symlink(sys.executable, mypython)
-                createdfiles.append(mypython)
-            except OSError, err:
-                # child processes may race, which is harmless
-                if err.errno != errno.EEXIST:
-                    raise
-    else:
-        exedir, exename = os.path.split(sys.executable)
-        vlog("# Modifying search path to find %s as %s in '%s'" %
-             (exename, pyexename, exedir))
-        path = os.environ['PATH'].split(os.pathsep)
-        while exedir in path:
-            path.remove(exedir)
-        os.environ['PATH'] = os.pathsep.join([exedir] + path)
-        if not findprogram(pyexename):
-            print "WARNING: Cannot find %s in search path" % pyexename
-
 def installhg(runner):
     vlog("# Performing temporary installation of HG")
     installerrs = os.path.join("tests", "install.err")
     compiler = ''
     if runner.options.compiler:
         compiler = '--compiler ' + runner.options.compiler
     pure = runner.options.pure and "--pure" or ""
     py3 = ''
@@ -458,17 +424,17 @@ def installhg(runner):
     else:
         f = open(installerrs)
         for line in f:
             print line,
         f.close()
         sys.exit(1)
     os.chdir(runner.testdir)
 
-    usecorrectpython(runner)
+    runner.usecorrectpython()
 
     if runner.options.py3k_warnings and not runner.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')
@@ -1214,17 +1180,17 @@ def scheduletests(runner, tests):
         abort = True
 
 def runtests(runner, tests):
     try:
         if runner.inst:
             installhg(runner)
             _checkhglib(runner, "Testing")
         else:
-            usecorrectpython(runner)
+            runner.usecorrectpython()
 
         if runner.options.restart:
             orig = list(tests)
             while tests:
                 if os.path.exists(tests[0] + ".err"):
                     break
                 tests.pop(0)
             if not tests:
@@ -1293,16 +1259,50 @@ class TestRunner(object):
         vlog("# Cleaning up HGTMP", self.hgtmp)
         shutil.rmtree(self.hgtmp, True)
         for f in createdfiles:
             try:
                 os.remove(f)
             except OSError:
                 pass
 
+    def usecorrectpython(self):
+        # Some tests run the Python interpreter. They must use the
+        # same interpreter 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(self.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:
+                try:
+                    os.symlink(sys.executable, mypython)
+                    createdfiles.append(mypython)
+                except OSError, err:
+                    # child processes may race, which is harmless
+                    if err.errno != errno.EEXIST:
+                        raise
+        else:
+            exedir, exename = os.path.split(sys.executable)
+            vlog("# Modifying search path to find %s as %s in '%s'" %
+                 (exename, pyexename, exedir))
+            path = os.environ['PATH'].split(os.pathsep)
+            while exedir in path:
+                path.remove(exedir)
+            os.environ['PATH'] = os.pathsep.join([exedir] + path)
+            if not findprogram(pyexename):
+                print "WARNING: Cannot find %s in search path" % pyexename
+
 def main(args, parser=None):
     runner = TestRunner()
 
     parser = parser or getparser()
     (options, args) = parseargs(args, parser)
     runner.options = options
     os.umask(022)
 


More information about the Mercurial-devel mailing list