[Python-Dev] [Python-checkins] cpython (3.3): Process DEFAULT values in mock side_effect that returns iterator. (original) (raw)

Michael Foord fuzzyman at gmail.com
Mon Apr 8 11:52:30 CEST 2013


On 7 April 2013 14:44, andrew.svetlov <python-checkins at python.org> wrote:

http://hg.python.org/cpython/rev/18fd64f1de2d changeset: 83179:18fd64f1de2d branch: 3.3 user: Andrew Svetlov <andrew.svetlov at gmail.com> date: Sun Apr 07 16:42:24 2013 +0300 summary: Process DEFAULT values in mock sideeffect 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 @@ -904,6 +904,8 @@ result = next(effect) if isexception(result): raise result + if result is DEFAULT: + result = self.returnvalue return result retval = 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 @@ -906,6 +906,10 @@ self.assertRaises(StopIteration, mock) self.assertIs(mock.sideeffect, thisiter) + def testsideeffectiteratordefault(self): + mock = Mock(returnvalue=2) + mock.sideeffect = iter([1, DEFAULT]) + self.assertEqual([mock(), mock()], [1, 2]) def testasserthascallsanyorder(self): mock = Mock() -- Repository URL: http://hg.python.org/cpython

This was committed without a NEWS entry.

Michael


Python-checkins mailing list Python-checkins at python.org http://mail.python.org/mailman/listinfo/python-checkins

--

http://www.voidspace.org.uk/

May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130408/9bb6808f/attachment.html>



More information about the Python-Dev mailing list