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

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

Comments

Gregory Szorc - May 2, 2014, 6:38 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397975727 25200
#      Sat Apr 19 23:35:27 2014 -0700
# Branch stable
# Node ID 4d8e2732fbd151f0c1121c02d19b88ab0eec5d58
# Parent  0e44bd11854a7a0842de2649cf83a2443ac062d4
run-tests: move cleanup() 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
@@ -381,28 +381,16 @@  def terminate(proc):
         getattr(proc, 'terminate', lambda : os.kill(proc.pid, signal.SIGTERM))()
     except OSError:
         pass
 
 def killdaemons(pidfile):
     return killmod.killdaemons(pidfile, tryhard=False, remove=True,
                                logfn=vlog)
 
-def cleanup(runner):
-    if runner.options.keep_tmpdir:
-        return
-
-    vlog("# Cleaning up HGTMP", runner.hgtmp)
-    shutil.rmtree(runner.hgtmp, True)
-    for f in createdfiles:
-        try:
-            os.remove(f)
-        except OSError:
-            pass
-
 def usecorrectpython(runner):
     # some tests run python interpreter. they must use same
     # interpreter we use or bad things will happen.
     pyexename = sys.platform == 'win32' and 'python.exe' or 'python'
     if getattr(os, 'symlink', None):
         vlog("# Making python executable in test path a symlink to '%s'" %
              sys.executable)
         mypython = os.path.join(runner.tmpbindir, pyexename)
@@ -1291,16 +1279,30 @@  class TestRunner(object):
         self.testdir = None
         self.hgtmp = None
         self.inst = None
         self.bindir = None
         self.tmpbinddir = None
         self.pythondir = None
         self.coveragefile = None
 
+    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 createdfiles:
+            try:
+                os.remove(f)
+            except OSError:
+                pass
+
 def main(args, parser=None):
     runner = TestRunner()
 
     parser = parser or getparser()
     (options, args) = parseargs(args, parser)
     runner.options = options
     os.umask(022)
 
@@ -1417,12 +1419,12 @@  def main(args, parser=None):
     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
     finally:
         time.sleep(.1)
-        cleanup(runner)
+        runner.cleanup()
 
 if __name__ == '__main__':
     sys.exit(main(sys.argv[1:]))