summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-01-21 21:15:18 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-01-21 21:15:18 (GMT)
commita203360836df8110b6e0e4b8a8ed551fa2f0df06 (patch)
tree24de25856b96c0b69442847b6fd3e651bb068c26
parentb2df6319e3a3bd5cecebd2b3ca8e95b0cc87b554 (diff)
parent362f058a89437f82f112cda439bb40abe4ddb8c5 (diff)
downloadcpython-a203360836df8110b6e0e4b8a8ed551fa2f0df06.zip
cpython-a203360836df8110b6e0e4b8a8ed551fa2f0df06.tar.gz
cpython-a203360836df8110b6e0e4b8a8ed551fa2f0df06.tar.bz2
Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY.
-rw-r--r--Lib/unittest/mock.py8
-rw-r--r--Lib/unittest/test/testmock/testmock.py17
-rw-r--r--Misc/NEWS2
3 files changed, 22 insertions, 5 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index dcac5a2..b6b3836 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -1769,14 +1769,18 @@ def _get_eq(self):
ret_val = self.__eq__._mock_return_value
if ret_val is not DEFAULT:
return ret_val
- return self is other
+ if self is other:
+ return True
+ return NotImplemented
return __eq__
def _get_ne(self):
def __ne__(other):
if self.__ne__._mock_return_value is not DEFAULT:
return DEFAULT
- return self is not other
+ if self is other:
+ return False
+ return NotImplemented
return __ne__
def _get_iter(self):
diff --git a/Lib/unittest/test/testmock/testmock.py b/Lib/unittest/test/testmock/testmock.py
index b07a7cc..b64c866 100644
--- a/Lib/unittest/test/testmock/testmock.py
+++ b/Lib/unittest/test/testmock/testmock.py
@@ -306,13 +306,24 @@ class MockTest(unittest.TestCase):
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
+ mm = mock.MagicMock()
+ self.assertTrue(mm == mm)
+ self.assertFalse(mm != mm)
+ self.assertFalse(mm == mock.MagicMock())
+ self.assertTrue(mm != mock.MagicMock())
+ self.assertTrue(mm == mock.ANY)
+ self.assertFalse(mm != mock.ANY)
+ self.assertTrue(mock.ANY == mm)
+ self.assertFalse(mock.ANY != mm)
+
+ call1 = mock.call(mock.MagicMock())
+ call2 = mock.call(mock.ANY)
self.assertTrue(call1 == call2)
self.assertFalse(call1 != call2)
+ self.assertTrue(call2 == call1)
+ self.assertFalse(call2 != call1)
def test_assert_called_with(self):
diff --git a/Misc/NEWS b/Misc/NEWS
index ed39fce..d829a56 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -47,6 +47,8 @@ Core and Builtins
Library
-------
+- Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY.
+
- Issue #29316: Restore the provisional status of typing module, add
corresponding note to documentation. Patch by Ivan L.