Open GoogleCodeExporter opened 8 years ago
I'm inclined to say that if mock.Mock(spec=[], **kwargs) does what you want,
then just use that rather than add a new type to mock.
Original comment by fuzzyman
on 5 Nov 2012 at 9:07
Note that this class provides a "stub" functionality, identical to the "stub"
in the pretend library by Alex Gaynor. At the very least it should go as an
example in the documentation:
from mock import MagicMock, _is_magic
def _wrap(f, n):
if not (_is_magic(n) and isinstance(f, type(lambda: None))):
return f
def inner(self, *args, **kwargs):
return f(*args, **kwargs)
inner.__name__ = n
return inner
class stub(MagicMock):
def __init__(self, spec_set=None, **kwargs):
super(MagicMock, self).__init__(spec=list(kwargs), spec_set=spec_set)
[setattr(self, k, _wrap(v, k)) for k, v in kwargs.items()]
Original comment by fuzzyman
on 8 Nov 2012 at 11:25
Original issue reported on code.google.com by
jul...@grayvines.com
on 4 Sep 2012 at 12:59