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

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

Comments

Gregory Szorc - May 2, 2014, 6:38 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397977590 25200
#      Sun Apr 20 00:06:30 2014 -0700
# Branch stable
# Node ID 4ed3b10a45b77805429d826fcf1bae6e12311afd
# Parent  aa233a3973841c46e914fffdba3f21101f237d5f
run-tests: move runtests() 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
@@ -1027,69 +1027,16 @@  def scheduletests(runner, tests):
                     tests.append(test)
                 t = threading.Thread(target=job, name=test, args=(test, count))
                 t.start()
                 running += 1
                 count += 1
     except KeyboardInterrupt:
         abort = True
 
-def runtests(runner, tests):
-    try:
-        if runner.inst:
-            runner.installhg()
-            runner.checkhglib("Testing")
-        else:
-            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:
-                print "running all tests"
-                tests = orig
-
-        scheduletests(runner, tests)
-
-        failed = len(runner.results['!'])
-        warned = len(runner.results['~'])
-        tested = len(runner.results['.']) + failed + warned
-        skipped = len(runner.results['s'])
-        ignored = len(runner.results['i'])
-
-        print
-        if not runner.options.noskips:
-            for s in runner.results['s']:
-                print "Skipped %s: %s" % s
-        for s in runner.results['~']:
-            print "Warned %s: %s" % s
-        for s in runner.results['!']:
-            print "Failed %s: %s" % s
-        runner.checkhglib("Tested")
-        print "# Ran %d tests, %d skipped, %d warned, %d failed." % (
-            tested, skipped + ignored, warned, failed)
-        if runner.results['!']:
-            print 'python hash seed:', os.environ['PYTHONHASHSEED']
-        if runner.options.time:
-            runner.outputtimes()
-
-        if runner.options.anycoverage:
-            runner.outputcoverage()
-    except KeyboardInterrupt:
-        failed = True
-        print "\ninterrupted!"
-
-    if failed:
-        return 1
-    if warned:
-        return 80
-
 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'),
@@ -1110,16 +1057,69 @@  class TestRunner(object):
             '.': [],
             '!': [],
             '~': [],
             's': [],
             'i': [],
         }
         self._createdfiles = []
 
+    def runtests(self, tests):
+        try:
+            if self.inst:
+                self.installhg()
+                self.checkhglib("Testing")
+            else:
+                self.usecorrectpython()
+
+            if self.options.restart:
+                orig = list(tests)
+                while tests:
+                    if os.path.exists(tests[0] + ".err"):
+                        break
+                    tests.pop(0)
+                if not tests:
+                    print "running all tests"
+                    tests = orig
+
+            scheduletests(self, tests)
+
+            failed = len(self.results['!'])
+            warned = len(self.results['~'])
+            tested = len(self.results['.']) + failed + warned
+            skipped = len(self.results['s'])
+            ignored = len(self.results['i'])
+
+            print
+            if not self.options.noskips:
+                for s in self.results['s']:
+                    print "Skipped %s: %s" % s
+            for s in self.results['~']:
+                print "Warned %s: %s" % s
+            for s in self.results['!']:
+                print "Failed %s: %s" % s
+            self.checkhglib("Tested")
+            print "# Ran %d tests, %d skipped, %d warned, %d failed." % (
+                tested, skipped + ignored, warned, failed)
+            if self.results['!']:
+                print 'python hash seed:', os.environ['PYTHONHASHSEED']
+            if self.options.time:
+                self.outputtimes()
+
+            if self.options.anycoverage:
+                self.outputcoverage()
+        except KeyboardInterrupt:
+            failed = True
+            print "\ninterrupted!"
+
+        if failed:
+            return 1
+        if warned:
+            return 80
+
     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)
@@ -1426,15 +1426,15 @@  def main(args, parser=None):
     runner.coveragefile = os.path.join(runner.testdir, ".coverage")
 
     vlog("# Using TESTDIR", runner.testdir)
     vlog("# Using HGTMP", runner.hgtmp)
     vlog("# Using PATH", os.environ["PATH"])
     vlog("# Using", IMPL_PATH, os.environ[IMPL_PATH])
 
     try:
-        return runtests(runner, tests) or 0
+        return runner.runtests(tests) or 0
     finally:
         time.sleep(.1)
         runner.cleanup()
 
 if __name__ == '__main__':
     sys.exit(main(sys.argv[1:]))