docs: Improve the Mock class

The python import machinery expects __path__ to be a string, so
__getattr__ has to return a mock string instead of a mock object.

__getattr__ now also returns Mock objects instead of the Mock class
and Mock objects are now callable.
rtd2
Patrick Totzke 2012-01-07 13:14:54 +00:00
parent 34d1392e6e
commit 178a68a17f
1 changed files with 5 additions and 1 deletions

View File

@ -38,9 +38,13 @@ You can mock out the imports for these modules in your conf.py with the followin
def __init__(self, *args, **kwargs):
pass
def __getattr__(self, name):
def __call__(self, *args, **kwargs):
return Mock()
@classmethod
def __getattr__(self, name):
return Mock() if name not in ('__file__', '__path__') else '/dev/null'
MOCK_MODULES = ['pygtk', 'gtk', 'gobject', 'argparse']
for mod_name in MOCK_MODULES:
sys.modules[mod_name] = Mock()