Doc mock decorators (#33132)

* Add mock function for mocking decorators

* Mock the stdlib user module because importing it will open the repl
This commit is contained in:
Seth House 2016-05-10 08:25:13 -06:00 committed by Mike Place
parent 30edeadafd
commit 878d34a865

View file

@ -42,6 +42,9 @@ class Mock(object):
# pylint: enable=R0903
MOCK_MODULES = [
# Python stdlib
'user',
# salt core
'Crypto',
'Crypto.Signature',
@ -115,9 +118,29 @@ MOCK_MODULES = [
for mod_name in MOCK_MODULES:
sys.modules[mod_name] = Mock()
def mock_decorator_with_params(*oargs, **okwargs):
'''
Optionally mock a decorator that takes parameters
E.g.:
@blah(stuff=True)
def things():
pass
'''
def inner(fn, *iargs, **ikwargs):
if hasattr(fn, '__call__'):
return fn
else:
return Mock()
return inner
# Define a fake version attribute for libcloud so docs build as supposed
sys.modules['libcloud'].__version__ = '0.0.0'
# Define a fake version attribute for the following libs.
sys.modules['cherrypy'].config = mock_decorator_with_params
# -- Add paths to PYTHONPATH ---------------------------------------------------
try: