]> granicus.if.org Git - python/commitdiff
Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY.
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 21 Jan 2017 21:12:58 +0000 (23:12 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 21 Jan 2017 21:12:58 +0000 (23:12 +0200)
Lib/unittest/mock.py
Lib/unittest/test/testmock/testmock.py
Misc/NEWS

index 669890a4de2c3b4bc18a05bfd474397088de2e64..0512cca4e29ba472196907b9d4b7942794a416cf 100644 (file)
@@ -1749,14 +1749,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):
index 5f82b8296610e172009f96de48462171975091c7..a96ec683a95b0d0d3a8960675f1007bd004f5279 100644 (file)
@@ -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):
index f357d6dfbead21f525ddc12bb6fab85c7e678835..84fa9d1b9fda9c2df62504d88ab4c87454066e90 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY.
+
 - Issue #29011:  Fix an important omission by adding Deque to the typing module.
 
 - Issue #29219: Fixed infinite recursion in the repr of uninitialized