Kaydet (Commit) 8b2cd75b authored tarafından Andrew Svetlov's avatar Andrew Svetlov

Process DEFAULT values in mock side_effect that returns iterator.

Patch by Michael Ford.
üst 595365de
...@@ -904,6 +904,8 @@ class CallableMixin(Base): ...@@ -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): ...@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment