Bug 1267454 - Set up a mock-able import for os.environ in configure tests.
MozReview-Commit-ID: AtkkLC5xEip
--- 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()