[Python-Dev] [Python-checkins] cpython (3.3): Process DEFAULT values in mock side_effect that returns iterator.
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 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
> @@ -904,6 +904,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
> @@ -906,6 +906,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
>
>
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