Bug 1267454 - Set up a mock-able import for os.environ in configure tests. draft
authorChris Manchester <cmanchester@mozilla.com>
Thu, 05 May 2016 16:02:03 -0700
changeset 363981 21af16108f74b7acd9b78ee42f7cf7ba2fb89a15
parent 363980 1c55a98496aa816299cf8f56eb884f26cb948c92
child 363982 c666a9fbdf39f6a61ec3baed66cb5d337f6e8224
push id17355
push usercmanchester@mozilla.com
push dateThu, 05 May 2016 23:02:20 +0000
bugs1267454
milestone49.0a1
Bug 1267454 - Set up a mock-able import for os.environ in configure tests. MozReview-Commit-ID: AtkkLC5xEip
python/mozbuild/mozbuild/test/configure/common.py
--- a/python/mozbuild/mozbuild/test/configure/common.py
+++ b/python/mozbuild/mozbuild/test/configure/common.py
@@ -69,16 +69,17 @@ class ConfigureTestSandbox(ConfigureSand
 
         paths = paths.keys()
 
         environ = dict(environ)
         if 'CONFIG_SHELL' not in environ:
             environ['CONFIG_SHELL'] = mozpath.abspath('/bin/sh')
             self._subprocess_paths[environ['CONFIG_SHELL']] = self.shell
             paths.append(environ['CONFIG_SHELL'])
+        self._environ = environ
 
         vfs = ConfigureTestVFS(paths)
 
         self.OS = ReadOnlyNamespace(path=ReadOnlyNamespace(**{
             k: v if k not in ('exists', 'isfile')
             else getattr(vfs, k)
             for k, v in ConfigureSandbox.OS.path.__dict__.iteritems()
         }))
@@ -102,16 +103,19 @@ class ConfigureTestSandbox(ConfigureSand
         if what == 'subprocess':
             return ReadOnlyNamespace(
                 CalledProcessError=subprocess.CalledProcessError,
                 check_output=self.check_output,
                 PIPE=subprocess.PIPE,
                 Popen=self.Popen,
             )
 
+        if what == 'os.environ':
+            return self._environ
+
         return super(ConfigureTestSandbox, self)._get_one_import(what)
 
     def which(self, command, path=None):
         for parent in (path or self._search_path):
             candidate = mozpath.join(parent, command)
             if self.OS.path.exists(candidate):
                 return candidate
         raise WhichError()