Patchwork [062,of,179,tests-refactor] run-tests: move gettest() into TestRunner

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

Comments

Gregory Szorc - May 2, 2014, 6:38 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397976803 25200
#      Sat Apr 19 23:53:23 2014 -0700
# Branch stable
# Node ID af393a79440d034e45e54921cbff4be164d7aa33
# Parent  c44452f2c5830bd8fee88ffa65b898f62571d490
run-tests: move gettest() 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
@@ -920,36 +920,16 @@  class TTest(Test):
             if el.endswith(" (re)\n"):
                 return TTest.rematch(el[:-6], l)
             if el.endswith(" (glob)\n"):
                 return TTest.globmatch(el[:-8], l)
             if os.altsep and l.replace('\\', '/') == el:
                 return '+glob'
         return False
 
-def gettest(runner, test, count):
-    """Obtain a Test by looking at its filename.
-
-    Returns a Test instance. The Test may not be runnable if it doesn't map
-    to a known type.
-    """
-
-    lctest = test.lower()
-    refpath = os.path.join(runner.testdir, test)
-
-    testcls = Test
-
-    for ext, cls, out in testtypes:
-        if lctest.endswith(ext):
-            testcls = cls
-            refpath = os.path.join(runner.testdir, test + out)
-            break
-
-    return testcls(runner, test, count, refpath)
-
 wifexited = getattr(os, "WIFEXITED", lambda x: False)
 def run(cmd, wd, options, replacements, env):
     """Run command in a sub-process, capturing the output (stdout and stderr).
     Return a tuple (exitcode, output).  output is None in debug mode."""
     # TODO: Use subprocess.Popen if we're running on Python 2.4
     if options.debug:
         proc = subprocess.Popen(cmd, shell=True, cwd=wd, env=env)
         ret = proc.wait()
@@ -1017,17 +997,17 @@  def scheduletests(runner, tests):
     jobs = runner.options.jobs
     done = queue.Queue()
     running = 0
     count = 0
     global abort
 
     def job(test, count):
         try:
-            t = gettest(runner, test, count)
+            t = runner.gettest(test, count)
             done.put(t.run())
             del t # For side-effects.
         except KeyboardInterrupt:
             pass
         except: # re-raises
             done.put(('!', test, 'run-test raised an error, see traceback'))
             raise
 
@@ -1101,35 +1081,57 @@  def runtests(runner, tests):
         failed = True
         print "\ninterrupted!"
 
     if failed:
         return 1
     if warned:
         return 80
 
-testtypes = [('.py', PythonTest, '.out'),
-             ('.t', TTest, '')]
-
 class TestRunner(object):
     """Holds context for executing tests.
 
     Tests rely on a lot of state. This object holds it for them.
     """
+
+    TESTTYPES = [
+        ('.py', PythonTest, '.out'),
+        ('.t', TTest, ''),
+    ]
+
     def __init__(self):
         self.options = None
         self.testdir = None
         self.hgtmp = None
         self.inst = None
         self.bindir = None
         self.tmpbinddir = None
         self.pythondir = None
         self.coveragefile = None
         self._createdfiles = []
 
+    def gettest(self, test, count):
+        """Obtain a Test by looking at its filename.
+
+        Returns a Test instance. The Test may not be runnable if it doesn't
+        map to a known type.
+        """
+        lctest = test.lower()
+        refpath = os.path.join(self.testdir, test)
+
+        testcls = Test
+
+        for ext, cls, out in self.TESTTYPES:
+            if lctest.endswith(ext):
+                testcls = cls
+                refpath = os.path.join(self.testdir, test + out)
+                break
+
+        return testcls(self, test, count, refpath)
+
     def cleanup(self):
         """Clean up state from this test invocation."""
 
         if self.options.keep_tmpdir:
             return
 
         vlog("# Cleaning up HGTMP", self.hgtmp)
         shutil.rmtree(self.hgtmp, True)