[PATCH 1 of 2] tests: replace os.environ invocation by osenviron variable

liscju piotr.listkiewicz at gmail.com
Sat Mar 26 07:45:30 EDT 2016


# HG changeset patch
# User liscju <piotr.listkiewicz at gmail.com>
# Date 1458978497 -3600
#      Sat Mar 26 08:48:17 2016 +0100
# Node ID ffe9bc7aea5a63bc82e7322da9ff3448f13abaec
# Parent  62e73d42bd141a39a576a8cfd6f1ffcf06a0b2d0
tests: replace os.environ invocation by osenviron variable

It is more consistent because os.environb is accessed by
osenvironb. It also makes a change in accessing os.environ
easier to perform.

diff -r 62e73d42bd14 -r ffe9bc7aea5a tests/run-tests.py
--- a/tests/run-tests.py	Thu Mar 17 21:03:22 2016 +0000
+++ b/tests/run-tests.py	Sat Mar 26 08:48:17 2016 +0100
@@ -69,6 +69,7 @@ except ImportError:
 from xml.dom import minidom
 import unittest
 
+osenviron = os.environ
 osenvironb = getattr(os, 'environb', os.environ)
 processlock = threading.Lock()
 
@@ -276,7 +277,7 @@ def getparser():
                             "revision as a known-good revision."))
 
     for option, (envvar, default) in defaults.items():
-        defaults[option] = type(default)(os.environ.get(envvar, default))
+        defaults[option] = type(default)(osenviron.get(envvar, default))
     parser.set_defaults(**defaults)
 
     return parser
@@ -789,7 +790,7 @@ class Test(unittest.TestCase):
         def defineport(i):
             offset = '' if i == 0 else '%s' % i
             env["HGPORT%s" % offset] = '%s' % (self._startport + i)
-        env = os.environ.copy()
+        env = osenviron.copy()
         env['TESTTMP'] = self._testtmp
         env['HOME'] = self._testtmp
         # This number should match portneeded in _getport
@@ -1856,7 +1857,7 @@ class TextTestRunner(unittest.TextTestRu
                    skipped + ignored, warned, failed))
             if failed:
                 self.stream.writeln('python hash seed: %s' %
-                    os.environ['PYTHONHASHSEED'])
+                    osenviron['PYTHONHASHSEED'])
             if self._runner.options.time:
                 self.printtimes(result.times)
 
@@ -1981,10 +1982,10 @@ class TestRunner(object):
         self._testdir = osenvironb[b'TESTDIR'] = getattr(
             os, 'getcwdb', os.getcwd)()
 
-        if 'PYTHONHASHSEED' not in os.environ:
+        if 'PYTHONHASHSEED' not in osenviron:
             # use a random python hash seed all the time
             # we do the randomness ourself to know what seed is used
-            os.environ['PYTHONHASHSEED'] = str(random.getrandbits(32))
+            osenviron['PYTHONHASHSEED'] = str(random.getrandbits(32))
 
         if self.options.tmpdir:
             self.options.keep_tmpdir = True
@@ -2090,19 +2091,19 @@ class TestRunner(object):
         osenvironb[IMPL_PATH] = sepb.join(pypath)
 
         if self.options.pure:
-            os.environ["HGTEST_RUN_TESTS_PURE"] = "--pure"
+            osenviron["HGTEST_RUN_TESTS_PURE"] = "--pure"
 
         if self.options.allow_slow_tests:
-            os.environ["HGTEST_SLOW"] = "slow"
-        elif 'HGTEST_SLOW' in os.environ:
-            del os.environ['HGTEST_SLOW']
+            osenviron["HGTEST_SLOW"] = "slow"
+        elif 'HGTEST_SLOW' in osenviron:
+            del osenviron['HGTEST_SLOW']
 
         self._coveragefile = os.path.join(self._testdir, b'.coverage')
 
         vlog("# Using TESTDIR", self._testdir)
         vlog("# Using RUNTESTDIR", osenvironb[b'RUNTESTDIR'])
         vlog("# Using HGTMP", self._hgtmp)
-        vlog("# Using PATH", os.environ["PATH"])
+        vlog("# Using PATH", osenviron["PATH"])
         vlog("# Using", IMPL_PATH, osenvironb[IMPL_PATH])
 
         try:
@@ -2281,10 +2282,10 @@ class TestRunner(object):
             exedir, exename = os.path.split(sys.executable)
             vlog("# Modifying search path to find %s as %s in '%s'" %
                  (exename, pyexename, exedir))
-            path = os.environ['PATH'].split(os.pathsep)
+            path = osenviron['PATH'].split(os.pathsep)
             while exedir in path:
                 path.remove(exedir)
-            os.environ['PATH'] = os.pathsep.join([exedir] + path)
+            osenviron['PATH'] = os.pathsep.join([exedir] + path)
             if not self._findprogram(pyexename):
                 print("WARNING: Cannot find %s in search path" % pyexename)
 
@@ -2397,7 +2398,7 @@ class TestRunner(object):
             shutil.copyfile(custom, target)
             rc = os.path.join(self._testdir, '.coveragerc')
             vlog('# Installing coverage rc to %s' % rc)
-            os.environ['COVERAGE_PROCESS_START'] = rc
+            osenviron['COVERAGE_PROCESS_START'] = rc
             covdir = os.path.join(self._installdir, '..', 'coverage')
             try:
                 os.mkdir(covdir)
@@ -2405,7 +2406,7 @@ class TestRunner(object):
                 if e.errno != errno.EEXIST:
                     raise
 
-            os.environ['COVERAGE_DIR'] = covdir
+            osenviron['COVERAGE_DIR'] = covdir
 
     def _checkhglib(self, verb):
         """Ensure that the 'mercurial' package imported by python is


More information about the Mercurial-devel mailing list