[Python-checkins] cpython (merge 3.4 -> default): Issue #23568: Add rdivmod support to MagicMock() objects.
berker.peksag
python-checkins at python.org
Sun Mar 15 00:57:41 CET 2015
https://hg.python.org/cpython/rev/90f08e7fbdc3
changeset: 94995:90f08e7fbdc3
parent: 94993:e058423d3ca4
parent: 94994:35a780a9a3b4
user: Berker Peksag <berker.peksag at gmail.com>
date: Sun Mar 15 01:57:38 2015 +0200
summary:
Issue #23568: Add rdivmod support to MagicMock() objects.
Patch by Håkan Lövdahl.
files:
Lib/unittest/mock.py | 4 ++-
Lib/unittest/test/testmock/testmagicmethods.py | 15 ++++++++++
Misc/NEWS | 3 ++
3 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -1661,7 +1661,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 --git a/Lib/unittest/test/testmock/testmagicmethods.py b/Lib/unittest/test/testmock/testmagicmethods.py
--- a/Lib/unittest/test/testmock/testmagicmethods.py
+++ b/Lib/unittest/test/testmock/testmagicmethods.py
@@ -435,5 +435,20 @@
m @= 24
self.assertEqual(m, 24)
+ 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 --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -18,6 +18,9 @@
Library
-------
+- Issue #23568: Add rdivmod support to MagicMock() objects.
+ Patch by Håkan Lövdahl.
+
- Issue #2052: Add charset parameter to HtmlDiff.make_file().
- Issue #23138: Fixed parsing cookies with absent keys or values in cookiejar.
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list