Here are the examples of the python api mock._is_exception taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
3
Example 1
def __call__(self, *args, **kwargs):
obj = self._lookup(call(*args, **kwargs))
if _is_exception(obj):
raise obj
if isinstance(obj, _Sequence):
return obj()
return obj
0
Example 2
Project: mockextras Source File: _fluent.py
def when(mock_fn):
class ListSeq(_Sequence):
def __init__(self):
self.list = []
def __call__(self):
if len(self.list) > 1:
retval = self.list.pop(0)
else:
retval = self.list[0]
if _is_exception(retval):
raise retval
return retval
class When(object):
def __init__(self, mock_fn):
self._mock_fn = mock_fn
if not _is_instance_mock(self._mock_fn):
raise RuntimeError("mock_fn must be an instance of Mock")
if not isinstance(self._mock_fn.side_effect, _Stub):
if self._mock_fn.side_effect is not None:
raise RuntimeError("Mock '%s' already has a side_effect set defined" % self._mock_fn)
self._mock_fn.side_effect = _Stub()
if not isinstance(self._mock_fn.side_effect._results, list): #pylint: disable=protected-access
self._mock_fn.side_effect._results = list(self._mock_fn.side_effect._results) #pylint: disable=protected-access
def called_with(self, *args, **kwargs):
return CalledWith(self._mock_fn.side_effect._results, call(*args, **kwargs)) #pylint: disable=protected-access
class CalledWith(object):
def __init__(self, results, key):
self._results = results
self._key = key
self._list = None
def then(self, obj):
if self._list is None:
s = ListSeq()
self._results.append((self._key, s))
self._list = s.list
self._list.append(obj)
return self
def __repr__(self):
return ""
return When(mock_fn)
0
Example 3
def __call__(self):
retval = next(self._iterator)
if _is_exception(retval):
raise retval
return retval