Bug 1266343 - Move ConfigureTestSandbox to a common module for all configure tests. r=chmanchester
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 20 Apr 2016 10:51:18 +0900
changeset 332289 1c806c5bf368aebbd4af87ab2ee98b992b190e76
parent 332288 5919b9e90fc829b590800434016498f2c840d810
child 332290 3af1b75d889a3efa3e99fb48c2f684587b029c38
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1266343
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1266343 - Move ConfigureTestSandbox to a common module for all configure tests. r=chmanchester
python/mozbuild/mozbuild/test/configure/common.py
python/mozbuild/mozbuild/test/configure/test_checks_configure.py
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/configure/common.py
@@ -0,0 +1,59 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+import os
+
+from mozbuild.configure import ConfigureSandbox
+from mozbuild.util import ReadOnlyNamespace
+from mozpack import path as mozpath
+
+from which import WhichError
+
+
+class ConfigureTestVFS(object):
+    def __init__(self, paths):
+        self._paths = set(mozpath.abspath(p) for p in paths)
+
+    def exists(self, path):
+        return mozpath.abspath(path) in self._paths
+
+    def isfile(self, path):
+        return mozpath.abspath(path) in self._paths
+
+
+class ConfigureTestSandbox(ConfigureSandbox):
+    def __init__(self, paths, config, environ, *args, **kwargs):
+        self._search_path = environ.get('PATH', '').split(os.pathsep)
+
+        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()
+        }))
+
+        super(ConfigureTestSandbox, self).__init__(config, environ, *args,
+                                                   **kwargs)
+
+    def _get_one_import(self, what):
+        if what == 'which.which':
+            return self.which
+
+        if what == 'which':
+            return ReadOnlyNamespace(
+                which=self.which,
+                WhichError=WhichError,
+            )
+
+        return super(ConfigureTestSandbox, self)._get_one_import(what)
+
+    def which(self, command):
+        for parent in self._search_path:
+            path = mozpath.join(parent, command)
+            if self.OS.path.exists(path):
+                return path
+        raise WhichError()
--- a/python/mozbuild/mozbuild/test/configure/test_checks_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_checks_configure.py
@@ -10,70 +10,21 @@ import textwrap
 import unittest
 
 from mozunit import main
 
 from mozbuild.configure import (
     ConfigureError,
     ConfigureSandbox,
 )
-from mozbuild.util import (
-    exec_,
-    ReadOnlyNamespace,
-)
+from mozbuild.util import exec_
 from mozpack import path as mozpath
 
 from buildconfig import topsrcdir
-from which import WhichError
-
-
-class ConfigureTestVFS(object):
-    def __init__(self, paths):
-        self._paths = set(mozpath.abspath(p) for p in paths)
-
-    def exists(self, path):
-        return mozpath.abspath(path) in self._paths
-
-    def isfile(self, path):
-        return mozpath.abspath(path) in self._paths
-
-
-class ConfigureTestSandbox(ConfigureSandbox):
-    def __init__(self, paths, config, environ, *args, **kwargs):
-        self._search_path = environ.get('PATH', '').split(os.pathsep)
-
-        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()
-        }))
-
-        super(ConfigureTestSandbox, self).__init__(config, environ, *args,
-                                                   **kwargs)
-
-    def _get_one_import(self, what):
-        if what == 'which.which':
-            return self.which
-
-        if what == 'which':
-            return ReadOnlyNamespace(
-                which=self.which,
-                WhichError=WhichError,
-            )
-
-        return super(ConfigureTestSandbox, self)._get_one_import(what)
-
-    def which(self, command):
-        for parent in self._search_path:
-            path = mozpath.join(parent, command)
-            if self.OS.path.exists(path):
-                return path
-        raise WhichError()
+from common import ConfigureTestSandbox
 
 
 class TestChecksConfigure(unittest.TestCase):
     def test_checking(self):
         out = StringIO()
         sandbox = ConfigureSandbox({}, stdout=out, stderr=out)
         base_dir = os.path.join(topsrcdir, 'build', 'moz.configure')
         sandbox.include_file(os.path.join(base_dir, 'checks.configure'))