changeset: 106255:4a38781538f7 branch: 3.6 parent: 106249:413e4827d705 parent: 106254:442eb26b1ca4 user: Serhiy Storchaka date: Sat Jan 21 23:15:18 2017 +0200 files: Lib/unittest/mock.py Lib/unittest/test/testmock/testmock.py Misc/NEWS description: Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY. diff -r 413e4827d705 -r 4a38781538f7 Lib/unittest/mock.py --- a/Lib/unittest/mock.py Fri Jan 20 10:35:46 2017 -0500 +++ b/Lib/unittest/mock.py Sat Jan 21 23:15:18 2017 +0200 @@ -1769,14 +1769,18 @@ 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 -r 413e4827d705 -r 4a38781538f7 Lib/unittest/test/testmock/testmock.py --- a/Lib/unittest/test/testmock/testmock.py Fri Jan 20 10:35:46 2017 -0500 +++ b/Lib/unittest/test/testmock/testmock.py Sat Jan 21 23:15:18 2017 +0200 @@ -306,13 +306,24 @@ def test_calls_equal_with_any(self): + # 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) - - # Check that equality and non-equality is consistent even when - # comparing with 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 -r 413e4827d705 -r 4a38781538f7 Misc/NEWS --- a/Misc/NEWS Fri Jan 20 10:35:46 2017 -0500 +++ b/Misc/NEWS Sat Jan 21 23:15:18 2017 +0200 @@ -47,6 +47,8 @@ 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.