Skip to content

Commit

Permalink
bpo-33516: Add support for __round__ in MagicMock (GH-6880)
Browse files Browse the repository at this point in the history
unittest.mock.MagicMock now supports the __round__() magic method.
  • Loading branch information
amyreese authored and vstinner committed May 22, 2018
1 parent 4e29f56 commit 6c4fab0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Doc/library/unittest.mock.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ The full list of supported magic methods is:

* ``__hash__``, ``__sizeof__``, ``__repr__`` and ``__str__``
* ``__dir__``, ``__format__`` and ``__subclasses__``
* ``__floor__``, ``__trunc__`` and ``__ceil__``
* ``__round__``, ``__floor__``, ``__trunc__`` and ``__ceil__``
* Comparisons: ``__lt__``, ``__gt__``, ``__le__``, ``__ge__``,
``__eq__`` and ``__ne__``
* Container methods: ``__getitem__``, ``__setitem__``, ``__delitem__``,
Expand Down
2 changes: 1 addition & 1 deletion Lib/unittest/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@ def _patch_stopall():
# because there is no idivmod
"divmod rdivmod neg pos abs invert "
"complex int float index "
"trunc floor ceil "
"round trunc floor ceil "
"bool next "
)

Expand Down
5 changes: 5 additions & 0 deletions Lib/unittest/test/testmock/testmagicmethods.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import math
import unittest
import sys
from unittest.mock import Mock, MagicMock, _magics
Expand Down Expand Up @@ -280,6 +281,10 @@ def test_magicmock_defaults(self):
self.assertEqual(hash(mock), object.__hash__(mock))
self.assertEqual(str(mock), object.__str__(mock))
self.assertTrue(bool(mock))
self.assertEqual(round(mock), mock.__round__())
self.assertEqual(math.trunc(mock), mock.__trunc__())
self.assertEqual(math.floor(mock), mock.__floor__())
self.assertEqual(math.ceil(mock), mock.__ceil__())

# in Python 3 oct and hex use __index__
# so these tests are for __index__ in py3k
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:class:`unittest.mock.MagicMock` now supports the ``__round__`` magic method.

0 comments on commit 6c4fab0

Please sign in to comment.