[Python-checkins] cpython (merge 3.3 -> default): Process DEFAULT values in mock side_effect that returns iterator.

andrew.svetlov python-checkins at python.org
Sun Apr 7 15:44:19 CEST 2013


http://hg.python.org/cpython/rev/5baa034c4181
changeset: 83180:5baa034c4181
parent: 83176:5e5081cdc086
parent: 83179:18fd64f1de2d
user: Andrew Svetlov <andrew.svetlov at gmail.com>
date: Sun Apr 07 16:44:07 2013 +0300
summary:
 Process DEFAULT values in mock side_effect that returns iterator.
Patch by Michael Ford.
files:
 Lib/unittest/mock.py | 2 ++
 Lib/unittest/test/testmock/testmock.py | 4 ++++
 2 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -931,6 +931,8 @@
 result = next(effect)
 if _is_exception(result):
 raise result
+ if result is DEFAULT:
+ result = self.return_value
 return result
 
 ret_val = effect(*args, **kwargs)
diff --git a/Lib/unittest/test/testmock/testmock.py b/Lib/unittest/test/testmock/testmock.py
--- a/Lib/unittest/test/testmock/testmock.py
+++ b/Lib/unittest/test/testmock/testmock.py
@@ -978,6 +978,10 @@
 self.assertRaises(StopIteration, mock)
 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):
 mock = Mock()
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /