Process DEFAULT values in mock side_effect that returns iterator.
Patch by Michael Ford.
This commit is contained in:
parent
595365de32
commit
8b2cd75bdd
|
@ -904,6 +904,8 @@ class CallableMixin(Base):
|
||||||
result = next(effect)
|
result = next(effect)
|
||||||
if _is_exception(result):
|
if _is_exception(result):
|
||||||
raise result
|
raise result
|
||||||
|
if result is DEFAULT:
|
||||||
|
result = self.return_value
|
||||||
return result
|
return result
|
||||||
|
|
||||||
ret_val = effect(*args, **kwargs)
|
ret_val = effect(*args, **kwargs)
|
||||||
|
|
|
@ -906,6 +906,10 @@ class MockTest(unittest.TestCase):
|
||||||
self.assertRaises(StopIteration, mock)
|
self.assertRaises(StopIteration, mock)
|
||||||
self.assertIs(mock.side_effect, this_iter)
|
self.assertIs(mock.side_effect, this_iter)
|
||||||
|
|
||||||
|
def test_side_effect_iterator_default(self):
|
||||||
|
mock = Mock(return_value=2)
|
||||||
|
mock.side_effect = iter([1, DEFAULT])
|
||||||
|
self.assertEqual([mock(), mock()], [1, 2])
|
||||||
|
|
||||||
def test_assert_has_calls_any_order(self):
|
def test_assert_has_calls_any_order(self):
|
||||||
mock = Mock()
|
mock = Mock()
|
||||||
|
|
Loading…
Reference in New Issue