2323# as an Intergovernmental Organization or submit itself to any jurisdiction.
2424
2525"""Hijacks `mock` to fake as many non-available modules as possible."""
26+
2627import sys
2728import types
2829
3334
3435# skip `_is_magic` check.
3536orig_is_magic = mock ._is_magic
37+
38+
3639def always_false (* args , ** kwargs ):
3740 return False
3841
3942
4043# avoid spec configuration for mocked classes with super classes.
4144# honestly this does not happen very often and is kind of a tricky case.
4245orig_mock_add_spec = mock .NonCallableMock ._mock_add_spec
46+
47+
4348def mock_add_spec_fake (self , spec , spec_set ):
4449 orig_mock_add_spec (self , None , None )
4550
@@ -66,7 +71,7 @@ class MockedModule(types.ModuleType):
6671 def __init__ (self , name ):
6772 super (types .ModuleType , self ).__init__ (name )
6873 self .__name__ = super .__name__
69- self .__file__ = self .__name__ .replace ('.' , '/' ) + ' .py'
74+ self .__file__ = self .__name__ .replace ("." , "/" ) + " .py"
7075 sys .modules [self .__name__ ] = self
7176
7277 def __getattr__ (self , key ):
@@ -77,12 +82,16 @@ def __getattr__(self, key):
7782
7883# overwrite imports
7984orig_import = __import__
85+
86+
8087def import_mock (name , * args , ** kwargs ):
8188 try :
8289 return orig_import (name , * args , ** kwargs )
8390 except ImportError :
8491 return MockedModule (name )
85- import_patch = mock .patch ('__builtin__.__import__' , side_effect = import_mock )
92+
93+
94+ import_patch = mock .patch ("__builtin__.__import__" , side_effect = import_mock )
8695
8796
8897# public methods
0 commit comments