Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a785dece
Commit
a785dece
authored
Mar 15, 2015
by
Berker Peksag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #23568: Add rdivmod support to MagicMock() objects.
Patch by Håkan Lövdahl.
parent
b19542d0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
1 deletion
+21
-1
Lib/unittest/mock.py
Lib/unittest/mock.py
+3
-1
Lib/unittest/test/testmock/testmagicmethods.py
Lib/unittest/test/testmock/testmagicmethods.py
+15
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/unittest/mock.py
View file @
a785dece
...
...
@@ -1644,7 +1644,9 @@ magic_methods = (
"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 "
...
...
Lib/unittest/test/testmock/testmagicmethods.py
View file @
a785dece
...
...
@@ -424,5 +424,20 @@ class TestMockingMagicMethods(unittest.TestCase):
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
()
Misc/NEWS
View file @
a785dece
...
...
@@ -18,6 +18,9 @@ Core and Builtins
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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment