Patchwork [071,of,179,tests-refactor] run-tests: establish TestRunner.run()

login
register
mail settings
Submitter Gregory Szorc
Date May 2, 2014, 6:38 p.m.
Message ID <567c0c494aee7ce33ed3.1399055908@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4566/
State Accepted
Commit 5047248536c5f8225cf919ec3a8e3226e30e3b9f
Headers show

Comments

Gregory Szorc - May 2, 2014, 6:38 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1398012573 25200
#      Sun Apr 20 09:49:33 2014 -0700
# Branch stable
# Node ID 567c0c494aee7ce33ed3b82127ed84854e7b9216
# Parent  03c84727362c8b0e94d0bb127953cbc7bcf0657f
run-tests: establish TestRunner.run()

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1007,16 +1007,39 @@  class TestRunner(object):
             '!': [],
             '~': [],
             's': [],
             'i': [],
         }
         self.abort = [False]
         self._createdfiles = []
 
+    def run(self, tests):
+        """Run the test suite."""
+
+        # Be kind and try to clean up after ourselves.
+        oldenv = dict(os.environ)
+        try:
+            return self._run(tests)
+        finally:
+            os.environ.clear()
+            os.environ.update(oldenv)
+
+    def _run(self, tests):
+        vlog("# Using TESTDIR", self.testdir)
+        vlog("# Using HGTMP", self.hgtmp)
+        vlog("# Using PATH", os.environ["PATH"])
+        vlog("# Using", IMPL_PATH, os.environ[IMPL_PATH])
+
+        try:
+            return self._runtests(tests) or 0
+        finally:
+            time.sleep(.1)
+            self._cleanup()
+
     def findtests(self, args):
         """Finds possible test files from arguments.
 
         If you wish to inject custom tests into the test harness, this would
         be a good function to monkeypatch or override in a derived class.
         """
         if not args:
             if self.options.changed:
@@ -1026,17 +1049,17 @@  class TestRunner(object):
                 args = stdout.strip('\0').split('\0')
             else:
                 args = os.listdir('.')
 
         return [t for t in args
                 if os.path.basename(t).startswith('test-')
                     and (t.endswith('.py') or t.endswith('.t'))]
 
-    def runtests(self, tests):
+    def _runtests(self, tests):
         try:
             if self.inst:
                 self.installhg()
                 self.checkhglib("Testing")
             else:
                 self.usecorrectpython()
 
             if self.options.restart:
@@ -1098,17 +1121,17 @@  class TestRunner(object):
         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):
+    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)
         for f in self._createdfiles:
@@ -1438,21 +1461,12 @@  def main(args, runner=None, parser=None)
     # are in /opt/subversion.)
     oldpypath = os.environ.get(IMPL_PATH)
     if oldpypath:
         pypath.append(oldpypath)
     os.environ[IMPL_PATH] = os.pathsep.join(pypath)
 
     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 runner.runtests(tests) or 0
-    finally:
-        time.sleep(.1)
-        runner.cleanup()
+    return runner.run(tests)
 
 if __name__ == '__main__':
     sys.exit(main(sys.argv[1:]))