Patchwork [059,of,179,tests-refactor] run-tests: move checkhglib into TestRunner

login
register
mail settings
Submitter Gregory Szorc
Date May 2, 2014, 6:38 p.m.
Message ID <123095a56a70bec3dc00.1399055896@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4554/
State Accepted
Commit 29629ef43d39a69cd2a6869ba7772c98cac95cf0
Headers show

Comments

Gregory Szorc - May 2, 2014, 6:38 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397976296 25200
#      Sat Apr 19 23:44:56 2014 -0700
# Branch stable
# Node ID 123095a56a70bec3dc0076e96ebccf51ba6db377
# Parent  01085a508313bf77e574200afcecec43e8acfe72
run-tests: move checkhglib 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
@@ -1034,26 +1034,16 @@  def _gethgpath():
     cmd = '%s -c "import mercurial; print (mercurial.__path__[0])"'
     pipe = os.popen(cmd % PYTHON)
     try:
         _hgpath = pipe.read().strip()
     finally:
         pipe.close()
     return _hgpath
 
-def _checkhglib(runner, verb):
-    """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(runner.pythondir, 'mercurial')
-    actualhg = _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))
-
 results = {'.':[], '!':[], '~': [], 's':[], 'i':[]}
 times = []
 iolock = threading.Lock()
 abort = False
 
 def scheduletests(runner, tests):
     jobs = runner.options.jobs
     done = queue.Queue()
@@ -1093,17 +1083,17 @@  def scheduletests(runner, tests):
                 count += 1
     except KeyboardInterrupt:
         abort = True
 
 def runtests(runner, tests):
     try:
         if runner.inst:
             runner.installhg()
-            _checkhglib(runner, "Testing")
+            runner.checkhglib("Testing")
         else:
             runner.usecorrectpython()
 
         if runner.options.restart:
             orig = list(tests)
             while tests:
                 if os.path.exists(tests[0] + ".err"):
                     break
@@ -1123,17 +1113,17 @@  def runtests(runner, tests):
         print
         if not runner.options.noskips:
             for s in results['s']:
                 print "Skipped %s: %s" % s
         for s in results['~']:
             print "Warned %s: %s" % s
         for s in results['!']:
             print "Failed %s: %s" % s
-        _checkhglib(runner, "Tested")
+        runner.checkhglib("Tested")
         print "# Ran %d tests, %d skipped, %d warned, %d failed." % (
             tested, skipped + ignored, warned, failed)
         if results['!']:
             print 'python hash seed:', os.environ['PYTHONHASHSEED']
         if runner.options.time:
             outputtimes(runner.options)
 
         if runner.options.anycoverage:
@@ -1294,16 +1284,26 @@  class TestRunner(object):
             vlog('# Installing coverage trigger to %s' % target)
             shutil.copyfile(custom, target)
             rc = os.path.join(self.testdir, '.coveragerc')
             vlog('# Installing coverage rc to %s' % rc)
             os.environ['COVERAGE_PROCESS_START'] = rc
             fn = os.path.join(self.inst, '..', '.coverage')
             os.environ['COVERAGE_FILE'] = fn
 
+    def checkhglib(self, verb):
+        """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()
+        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 main(args, parser=None):
     runner = TestRunner()
 
     parser = parser or getparser()
     (options, args) = parseargs(args, parser)
     runner.options = options
     os.umask(022)