Patchwork [008,of,179,tests-refactor] run-tests: move env into Test

login
register
mail settings
Submitter Gregory Szorc
Date May 2, 2014, 6:37 p.m.
Message ID <e81ce4bb968105a0e6ac.1399055845@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4502/
State Accepted
Commit 21a706020dd64be83d91760124d4248c3a13e2c1
Headers show

Comments

Gregory Szorc - May 2, 2014, 6:37 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397939172 25200
#      Sat Apr 19 13:26:12 2014 -0700
# Branch stable
# Node ID e81ce4bb968105a0e6acafb28e770f5447b840bb
# Parent  ecc28a7efcb0ae480d29443990753eaee98ffd58
run-tests: move env into Test

Environment variables are an implementation detail of how tests are
executed. This patch moves environment variable logic into Test and
completely hides it from the outside.

With this patch, a Test can be executed with two lines: init + run().
Tests are still single-use and take a more arguments to the constructor
than likely necessary. These will get addressed in subsequent patches.

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -550,17 +550,18 @@  class Test(object):
         self._options = options
         self._threadtmp = threadtmp
 
         self.testtmp = os.path.join(threadtmp, os.path.basename(path))
         os.mkdir(self.testtmp)
 
         self._setreplacements(count)
 
-    def run(self, env):
+    def run(self):
+        env = self._getenv()
         createhgrc(env['HGRCPATH'], self._options)
 
         try:
             return self._run(self._replacements, env)
         finally:
             killdaemons(env['DAEMON_PIDS'])
 
     def _run(self, replacements, env):
@@ -580,17 +581,17 @@  class Test(object):
                     c in '/\\' and r'[/\\]' or c.isdigit() and c or '\\' + c
                     for c in self.testtmp), '$TESTTMP'))
         else:
             r.append((re.escape(self.testtmp), '$TESTTMP'))
 
         self._replacements = r
         self._port = port
 
-    def getenv(self):
+    def _getenv(self):
         env = os.environ.copy()
         env['TESTTMP'] = self.testtmp
         env['HOME'] = self.testtmp
         env["HGPORT"] = str(self._port)
         env["HGPORT1"] = str(self._port + 1)
         env["HGPORT2"] = str(self._port + 2)
         env["HGRCPATH"] = os.path.join(self._threadtmp, '.hgrc')
         env["DAEMON_PIDS"] = os.path.join(self._threadtmp, 'daemon.pids')
@@ -1019,21 +1020,20 @@  def runone(options, test, count):
     if os.path.exists(err):
         os.remove(err)       # Remove any previous output files
 
     # Make a tmp subdirectory to work in
     threadtmp = os.path.join(HGTMP, "child%d" % count)
     os.mkdir(threadtmp)
 
     t = runner(testpath, options, threadtmp, count)
-    env = t.getenv()
 
     starttime = time.time()
     try:
-        ret, out = t.run(env)
+        ret, out = t.run()
     except KeyboardInterrupt:
         endtime = time.time()
         log('INTERRUPTED: %s (after %d seconds)' % (test, endtime - starttime))
         raise
     endtime = time.time()
     times.append((test, endtime - starttime))
     vlog("# Ret was:", ret)