changeset 21385:28414e5ac9ec

run-tests: move _gethgpath() into TestRunner
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 20 Apr 2014 11:04:25 -0700
parents a36cc85a5b7b
children 3b0c522f04aa
files tests/run-tests.py
diffstat 1 files changed, 16 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Sun Apr 20 10:34:52 2014 -0700
+++ b/tests/run-tests.py	Sun Apr 20 11:04:25 2014 -0700
@@ -969,23 +969,6 @@
         output = re.sub(s, r, output)
     return ret, output.splitlines(True)
 
-_hgpath = None
-
-def _gethgpath():
-    """Return the path to the mercurial package that is actually found by
-    the current Python interpreter."""
-    global _hgpath
-    if _hgpath is not None:
-        return _hgpath
-
-    cmd = '%s -c "import mercurial; print (mercurial.__path__[0])"'
-    pipe = os.popen(cmd % PYTHON)
-    try:
-        _hgpath = pipe.read().strip()
-    finally:
-        pipe.close()
-    return _hgpath
-
 iolock = threading.Lock()
 
 class TestRunner(object):
@@ -1028,6 +1011,7 @@
         }
         self.abort = [False]
         self._createdfiles = []
+        self._hgpath = None
 
     def run(self, args, parser=None):
         """Run the test suite."""
@@ -1379,11 +1363,25 @@
         """Ensure that the 'mercurial' package imported by python is
         the one we expect it to be.  If not, print a warning to stderr."""
         expecthg = os.path.join(self.pythondir, 'mercurial')
-        actualhg = _gethgpath()
+        actualhg = self._gethgpath()
         if os.path.abspath(actualhg) != os.path.abspath(expecthg):
             sys.stderr.write('warning: %s with unexpected mercurial lib: %s\n'
                              '         (expected %s)\n'
                              % (verb, actualhg, expecthg))
+    def _gethgpath(self):
+        """Return the path to the mercurial package that is actually found by
+        the current Python interpreter."""
+        if self._hgpath is not None:
+            return self._hgpath
+
+        cmd = '%s -c "import mercurial; print (mercurial.__path__[0])"'
+        pipe = os.popen(cmd % PYTHON)
+        try:
+            self._hgpath = pipe.read().strip()
+        finally:
+            pipe.close()
+
+        return self._hgpath
 
     def _outputtimes(self):
         vlog('# Producing time report')