Patchwork [015,of,179,tests-refactor] run-tests: remove threadtmp as part of Test.__del__

login
register
mail settings
Submitter Gregory Szorc
Date May 2, 2014, 6:37 p.m.
Message ID <9c0fd7bcc4b7a6bc574b.1399055852@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4510/
State Deferred
Headers show

Comments

Gregory Szorc - May 2, 2014, 6:37 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397944303 25200
#      Sat Apr 19 14:51:43 2014 -0700
# Branch stable
# Node ID 9c0fd7bcc4b7a6bc574bde7d8c76131ab669972c
# Parent  38b41ccded330d28d22458596a9bbfec48177ae5
run-tests: remove threadtmp as part of Test.__del__

threadtmp is an implementation detail. We move the cleanup of this
directory to Test.__del__ and make the variable internal.

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -549,21 +549,25 @@  class Test(object):
     runs cannot be run concurrently.
     """
 
     def __init__(self, path, options, count):
         self._path = path
         self._options = options
         self._count = count
 
-        self.threadtmp = os.path.join(HGTMP, 'child%d' % count)
-        os.mkdir(self.threadtmp)
+        self._threadtmp = os.path.join(HGTMP, 'child%d' % count)
+        os.mkdir(self._threadtmp)
+
+    def __del__(self):
+        if self._threadtmp and not self._options.keep_tmpdir:
+            shutil.rmtree(self._threadtmp, True)
 
     def run(self, result, refpath):
-        testtmp = os.path.join(self.threadtmp, os.path.basename(self._path))
+        testtmp = os.path.join(self._threadtmp, os.path.basename(self._path))
         os.mkdir(testtmp)
         replacements, port = self._getreplacements(testtmp)
         env = self._getenv(testtmp, port)
         createhgrc(env['HGRCPATH'], self._options)
 
         starttime = time.time()
 
         def updateduration():
@@ -620,18 +624,18 @@  class Test(object):
 
     def _getenv(self, testtmp, port):
         env = os.environ.copy()
         env['TESTTMP'] = testtmp
         env['HOME'] = testtmp
         env["HGPORT"] = str(port)
         env["HGPORT1"] = str(port + 1)
         env["HGPORT2"] = str(port + 2)
-        env["HGRCPATH"] = os.path.join(self.threadtmp, '.hgrc')
-        env["DAEMON_PIDS"] = os.path.join(self.threadtmp, 'daemon.pids')
+        env["HGRCPATH"] = os.path.join(self._threadtmp, '.hgrc')
+        env["DAEMON_PIDS"] = os.path.join(self._threadtmp, 'daemon.pids')
         env["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"'
         env["HGMERGE"] = "internal:merge"
         env["HGUSER"]   = "test"
         env["HGENCODING"] = "ascii"
         env["HGENCODINGMODE"] = "strict"
 
         # Reset some environment variables to well-known values so that
         # the tests produce repeatable output.
@@ -1066,16 +1070,17 @@  def runone(options, test, count):
     vlog("# Test", test)
 
     if os.path.exists(err):
         os.remove(err)       # Remove any previous output files
 
     t = runner(testpath, options, count)
     res = TestResult()
     t.run(res, ref)
+    del t # For cleanup side-effects.
 
     if res.interrupted:
         log('INTERRUPTED: %s (after %d seconds)' % (test, res.duration))
         raise KeyboardInterrupt()
 
     if res.exception:
         return fail('Exception during execution: %s' % res.exception, 255)
 
@@ -1132,18 +1137,16 @@  def runone(options, test, count):
         result = success()
 
     if not options.verbose:
         iolock.acquire()
         sys.stdout.write(result[0])
         sys.stdout.flush()
         iolock.release()
 
-    if not options.keep_tmpdir:
-        shutil.rmtree(t.threadtmp, True)
     return result
 
 _hgpath = None
 
 def _gethgpath():
     """Return the path to the mercurial package that is actually found by
     the current Python interpreter."""
     global _hgpath