[Python-checkins] cpython (merge 3.5 -> default): Issue #25195: Fix a regression in mock.MagicMock
berker.peksag
python-checkins at python.org
Sun Mar 27 17:39:18 EDT 2016
https://hg.python.org/cpython/rev/880d609b6664
changeset: 100774:880d609b6664
parent: 100772:5be12f20d8f2
parent: 100773:dcd3b078ab84
user: Berker Peksag <berker.peksag at gmail.com>
date: Mon Mar 28 00:30:40 2016 +0300
summary:
Issue #25195: Fix a regression in mock.MagicMock
_Call is a subclass of tuple (changeset 3603bae63c13 only works
for classes) so we need to implement __ne__ ourselves.
Patch by Andrew Plummer.
files:
Lib/unittest/mock.py | 3 ++
Lib/unittest/test/testmock/testmock.py | 17 ++++++++++++++
Misc/NEWS | 4 +++
3 files changed, 24 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
@@ -2047,6 +2047,9 @@
return (other_args, other_kwargs) == (self_args, self_kwargs)
+ __ne__ = object.__ne__
+
+
def __call__(self, *args, **kwargs):
if self.name is None:
return _Call(('', args, kwargs), name='()')
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
@@ -304,6 +304,17 @@
# an exception. See issue 24857.
self.assertFalse(mock.call_args == "a long sequence")
+
+ def test_calls_equal_with_any(self):
+ call1 = mock.call(mock.MagicMock())
+ call2 = mock.call(mock.ANY)
+
+ # Check that equality and non-equality is consistent even when
+ # comparing with mock.ANY
+ self.assertTrue(call1 == call2)
+ self.assertFalse(call1 != call2)
+
+
def test_assert_called_with(self):
mock = Mock()
mock()
@@ -319,6 +330,12 @@
mock.assert_called_with(1, 2, 3, a='fish', b='nothing')
+ def test_assert_called_with_any(self):
+ m = MagicMock()
+ m(MagicMock())
+ m.assert_called_with(mock.ANY)
+
+
def test_assert_called_with_function_spec(self):
def f(a, b, c, d=None):
pass
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -232,6 +232,10 @@
Library
-------
+- Issue #25195: Fix a regression in mock.MagicMock. _Call is a subclass of
+ tuple (changeset 3603bae63c13 only works for classes) so we need to
+ implement __ne__ ourselves. Patch by Andrew Plummer.
+
- Issue #26644: Raise ValueError rather than SystemError when a negative
length is passed to SSLSocket.recv() or read().
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list