changeset: 94994:35a780a9a3b4 branch: 3.4 parent: 94991:5f49f79d5a83 user: Berker Peksag date: Sun Mar 15 01:51:56 2015 +0200 files: Lib/unittest/mock.py Lib/unittest/test/testmock/testmagicmethods.py Misc/NEWS description: Issue #23568: Add rdivmod support to MagicMock() objects. Patch by Håkan Lövdahl. diff -r 5f49f79d5a83 -r 35a780a9a3b4 Lib/unittest/mock.py --- a/Lib/unittest/mock.py Sat Mar 14 21:32:57 2015 +0200 +++ b/Lib/unittest/mock.py Sun Mar 15 01:51:56 2015 +0200 @@ -1644,7 +1644,9 @@ "len contains iter " "hash str sizeof " "enter exit " - "divmod neg pos abs invert " + # we added divmod and rdivmod here instead of numerics + # because there is no idivmod + "divmod rdivmod neg pos abs invert " "complex int float index " "trunc floor ceil " "bool next " diff -r 5f49f79d5a83 -r 35a780a9a3b4 Lib/unittest/test/testmock/testmagicmethods.py --- a/Lib/unittest/test/testmock/testmagicmethods.py Sat Mar 14 21:32:57 2015 +0200 +++ b/Lib/unittest/test/testmock/testmagicmethods.py Sun Mar 15 01:51:56 2015 +0200 @@ -424,5 +424,20 @@ self.assertEqual(list(m), []) + def test_divmod_and_rdivmod(self): + m = MagicMock() + self.assertIsInstance(divmod(5, m), MagicMock) + m.__divmod__.return_value = (2, 1) + self.assertEqual(divmod(m, 2), (2, 1)) + m = MagicMock() + foo = divmod(2, m) + self.assertIsInstance(foo, MagicMock) + foo_direct = m.__divmod__(2) + self.assertIsInstance(foo_direct, MagicMock) + bar = divmod(m, 2) + self.assertIsInstance(bar, MagicMock) + bar_direct = m.__rdivmod__(2) + self.assertIsInstance(bar_direct, MagicMock) + if __name__ == '__main__': unittest.main() diff -r 5f49f79d5a83 -r 35a780a9a3b4 Misc/NEWS --- a/Misc/NEWS Sat Mar 14 21:32:57 2015 +0200 +++ b/Misc/NEWS Sun Mar 15 01:51:56 2015 +0200 @@ -18,6 +18,9 @@ Library ------- +- Issue #23568: Add rdivmod support to MagicMock() objects. + Patch by Håkan Lövdahl. + - Issue #23138: Fixed parsing cookies with absent keys or values in cookiejar. Patch by Demian Brecht.