Bug 1292439 - Use a fake _winreg module during tests. r?chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 05 Aug 2016 14:16:35 +0900
changeset 397071 6060e204b876e5b4b67ae33b6c4ada279db06050
parent 397070 ea9e47974d13414cab70a473f0398c08b7c2f3c7
child 527367 404e746f29ba6b6352b183fbfbbfe8634af2f56e
push id25194
push userbmo:mh+mozilla@glandium.org
push dateFri, 05 Aug 2016 05:27:35 +0000
reviewerschmanchester
bugs1292439
milestone51.0a1
Bug 1292439 - Use a fake _winreg module during tests. r?chmanchester While on automation, there is no MSVC to find through the registry, the story is different on local builds, and that can interfere with tests. Specifically, it breaks test_toolchain_configure.py because it's not expecting the registry to provide a valid path to an almost valid compiler, and then fails because that compiler doesn't match the expected target CPU. And because build/moz.configure/toolchain.configure also affects the PATH environment variable, subsequent tests end up failing even earlier because executing the empty mozconfig with the modified environment then fails because of the unicode value of PATH. This change implements enough of _winreg to make the get_registry_values function return nothing.
python/mozbuild/mozbuild/test/configure/common.py
--- a/python/mozbuild/mozbuild/test/configure/common.py
+++ b/python/mozbuild/mozbuild/test/configure/common.py
@@ -140,16 +140,25 @@ class ConfigureTestSandbox(ConfigureSand
                 create_unicode_buffer=self.create_unicode_buffer,
                 windll=ReadOnlyNamespace(
                     kernel32=ReadOnlyNamespace(
                         GetShortPathNameW=CTypesFunc(self.GetShortPathNameW),
                     )
                 ),
             )
 
+        if what == '_winreg':
+            def OpenKey(*args, **kwargs):
+                raise WindowsError()
+
+            return ReadOnlyNamespace(
+                HKEY_LOCAL_MACHINE=0,
+                OpenKey=OpenKey,
+            )
+
         return super(ConfigureTestSandbox, self)._get_one_import(what)
 
     def create_unicode_buffer(self, *args, **kwargs):
         class Buffer(object):
             def __init__(self):
                 self.value = ''
 
         return Buffer()