Patchwork [045,of,179,tests-refactor] run-tests: establish a class to hold testing state

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

Comments

Gregory Szorc - May 2, 2014, 6:38 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397974037 25200
#      Sat Apr 19 23:07:17 2014 -0700
# Branch stable
# Node ID 5717b806b4e8d500931b0143ce4c598c341e6a88
# Parent  f254b3678507045ba5656ed4fbead44a6425b9ff
run-tests: establish a class to hold testing state

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1175,17 +1175,17 @@  def _checkhglib(verb):
                          '         (expected %s)\n'
                          % (verb, actualhg, expecthg))
 
 results = {'.':[], '!':[], '~': [], 's':[], 'i':[]}
 times = []
 iolock = threading.Lock()
 abort = False
 
-def scheduletests(options, tests):
+def scheduletests(runner, options, tests):
     jobs = options.jobs
     done = queue.Queue()
     running = 0
     count = 0
     global abort
 
     def job(test, count):
         try:
@@ -1215,17 +1215,17 @@  def scheduletests(options, 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(options, tests):
+def runtests(runner, options, tests):
     try:
         if INST:
             installhg(options)
             _checkhglib("Testing")
         else:
             usecorrectpython()
 
         if options.restart:
@@ -1233,17 +1233,17 @@  def runtests(options, tests):
             while tests:
                 if os.path.exists(tests[0] + ".err"):
                     break
                 tests.pop(0)
             if not tests:
                 print "running all tests"
                 tests = orig
 
-        scheduletests(options, tests)
+        scheduletests(runner, options, tests)
 
         failed = len(results['!'])
         warned = len(results['~'])
         tested = len(results['.']) + failed + warned
         skipped = len(results['s'])
         ignored = len(results['i'])
 
         print
@@ -1271,17 +1271,25 @@  def runtests(options, tests):
     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.
+    """
+
 def main(args, parser=None):
+    runner = TestRunner()
+
     parser = parser or getparser()
     (options, args) = parseargs(args, parser)
     os.umask(022)
 
     checktools()
 
     if not args:
         if options.changed:
@@ -1390,15 +1398,15 @@  def main(args, parser=None):
     COVERAGE_FILE = os.path.join(TESTDIR, ".coverage")
 
     vlog("# Using TESTDIR", TESTDIR)
     vlog("# Using HGTMP", HGTMP)
     vlog("# Using PATH", os.environ["PATH"])
     vlog("# Using", IMPL_PATH, os.environ[IMPL_PATH])
 
     try:
-        return runtests(options, tests) or 0
+        return runtests(runner, options, tests) or 0
     finally:
         time.sleep(.1)
         cleanup(options)
 
 if __name__ == '__main__':
     sys.exit(main(sys.argv[1:]))