This commit is contained in:
Alan Saul 2013-01-31 13:01:56 +00:00
parent a8120bd015
commit 021c429720

View file

@ -15,74 +15,74 @@ import sys, os
#Mocking uninstalled modules: https://read-the-docs.readthedocs.org/en/latest/faq.html #Mocking uninstalled modules: https://read-the-docs.readthedocs.org/en/latest/faq.html
class Mock(object): #class Mock(object):
__all__ = [] #__all__ = []
def __init__(self, *args, **kwargs): #def __init__(self, *args, **kwargs):
for key, value in kwargs.iteritems(): #for key, value in kwargs.iteritems():
setattr(self, key, value) #setattr(self, key, value)
def __call__(self, *args, **kwargs): #def __call__(self, *args, **kwargs):
return Mock() #return Mock()
__add__ = __mul__ = __getitem__ = __setitem__ = \ #__add__ = __mul__ = __getitem__ = __setitem__ = \
__delitem__ = __sub__ = __floordiv__ = __mod__ = __divmod__ = \ #__delitem__ = __sub__ = __floordiv__ = __mod__ = __divmod__ = \
__pow__ = __lshift__ = __rshift__ = __and__ = __xor__ = __or__ = \ #__pow__ = __lshift__ = __rshift__ = __and__ = __xor__ = __or__ = \
__rmul__ = __rsub__ = __rfloordiv__ = __rmod__ = __rdivmod__ = \ #__rmul__ = __rsub__ = __rfloordiv__ = __rmod__ = __rdivmod__ = \
__rpow__ = __rlshift__ = __rrshift__ = __rand__ = __rxor__ = __ror__ = \ #__rpow__ = __rlshift__ = __rrshift__ = __rand__ = __rxor__ = __ror__ = \
__imul__ = __isub__ = __ifloordiv__ = __imod__ = __idivmod__ = \ #__imul__ = __isub__ = __ifloordiv__ = __imod__ = __idivmod__ = \
__ipow__ = __ilshift__ = __irshift__ = __iand__ = __ixor__ = __ior__ = \ #__ipow__ = __ilshift__ = __irshift__ = __iand__ = __ixor__ = __ior__ = \
__neg__ = __pos__ = __abs__ = __invert__ = __call__ #__neg__ = __pos__ = __abs__ = __invert__ = __call__
def __getattr__(self, name): #def __getattr__(self, name):
if name in ('__file__', '__path__'): #if name in ('__file__', '__path__'):
return '/dev/null' #return '/dev/null'
if name == 'sqrt': #if name == 'sqrt':
return math.sqrt #return math.sqrt
elif name[0] != '_' and name[0] == name[0].upper(): #elif name[0] != '_' and name[0] == name[0].upper():
return type(name, (), {}) #return type(name, (), {})
else: #else:
return Mock(**vars(self)) #return Mock(**vars(self))
def __lt__(self, *args, **kwargs): #def __lt__(self, *args, **kwargs):
return True #return True
__nonzero__ = __le__ = __eq__ = __ne__ = __gt__ = __ge__ = __contains__ = \ #__nonzero__ = __le__ = __eq__ = __ne__ = __gt__ = __ge__ = __contains__ = \
__lt__ #__lt__
def __repr__(self): #def __repr__(self):
# Use _mock_repr to fake the __repr__ call ## Use _mock_repr to fake the __repr__ call
res = getattr(self, "_mock_repr") #res = getattr(self, "_mock_repr")
return res if isinstance(res, str) else "Mock" #return res if isinstance(res, str) else "Mock"
def __hash__(self): #def __hash__(self):
return 1 #return 1
__len__ = __int__ = __long__ = __index__ = __hash__ #__len__ = __int__ = __long__ = __index__ = __hash__
def __oct__(self): #def __oct__(self):
return '01' #return '01'
def __hex__(self): #def __hex__(self):
return '0x1' #return '0x1'
def __float__(self): #def __float__(self):
return 0.1 #return 0.1
def __complex__(self): #def __complex__(self):
return 1j #return 1j
MOCK_MODULES = [ #MOCK_MODULES = [
'pylab', 'scipy', 'matplotlib', 'matplotlib.pyplot', 'pyfits', #'pylab', 'scipy', 'matplotlib', 'matplotlib.pyplot', 'pyfits',
'scipy.constants.constants', 'matplotlib.cm', #'scipy.constants.constants', 'matplotlib.cm',
'matplotlib.image', 'matplotlib.colors', 'sunpy.cm', #'matplotlib.image', 'matplotlib.colors', 'sunpy.cm',
'pandas', 'pandas.io', 'pandas.io.parsers', #'pandas', 'pandas.io', 'pandas.io.parsers',
'suds', 'matplotlib.ticker', 'matplotlib.colorbar', #'suds', 'matplotlib.ticker', 'matplotlib.colorbar',
'matplotlib.dates', 'scipy.optimize', 'scipy.ndimage', #'matplotlib.dates', 'scipy.optimize', 'scipy.ndimage',
'matplotlib.figure', 'scipy.ndimage.interpolation', 'bs4'] #'matplotlib.figure', 'scipy.ndimage.interpolation', 'bs4']
for mod_name in MOCK_MODULES: #for mod_name in MOCK_MODULES:
sys.modules[mod_name] = Mock() #sys.modules[mod_name] = Mock()
#sys.modules['numpy'] = Mock(pi=math.pi, G=6.67364e-11, #sys.modules['numpy'] = Mock(pi=math.pi, G=6.67364e-11,
@ -111,9 +111,11 @@ for mod_name in MOCK_MODULES:
#else: #else:
#return Mock() #return Mock()
#MOCK_MODULES = ['pylab']#'matplotlib', 'matplotlib.color', 'matplotlib.pyplot', 'pylab' ] import mock
#for mod_name in MOCK_MODULES:
#sys.modules[mod_name] = Mock() MOCK_MODULES = ['pylab', 'matplotlib']#'matplotlib', 'matplotlib.color', 'matplotlib.pyplot', 'pylab' ]
for mod_name in MOCK_MODULES:
sys.modules[mod_name] = mock.Mock()
# If extensions (or modules to document with autodoc) are in another directory, # If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the # add these directories to sys.path here. If the directory is relative to the