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

Gregory Szorc gregory.szorc at gmail.com
Fri May 2 13:38:28 CDT 2014


# HG changeset patch
# User Gregory Szorc <gregory.szorc at 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()

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:]))


More information about the Mercurial-devel mailing list