Skip to content

Commit 6c4fab0

Browse files
amyreesevstinner
authored andcommitted
bpo-33516: Add support for __round__ in MagicMock (GH-6880)
unittest.mock.MagicMock now supports the __round__() magic method.
1 parent 4e29f56 commit 6c4fab0

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

Doc/library/unittest.mock.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,7 @@ The full list of supported magic methods is:
16601660

16611661
* ``__hash__``, ``__sizeof__``, ``__repr__`` and ``__str__``
16621662
* ``__dir__``, ``__format__`` and ``__subclasses__``
1663-
* ``__floor__``, ``__trunc__`` and ``__ceil__``
1663+
* ``__round__``, ``__floor__``, ``__trunc__`` and ``__ceil__``
16641664
* Comparisons: ``__lt__``, ``__gt__``, ``__le__``, ``__ge__``,
16651665
``__eq__`` and ``__ne__``
16661666
* Container methods: ``__getitem__``, ``__setitem__``, ``__delitem__``,

Lib/unittest/mock.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,7 @@ def _patch_stopall():
17091709
# because there is no idivmod
17101710
"divmod rdivmod neg pos abs invert "
17111711
"complex int float index "
1712-
"trunc floor ceil "
1712+
"round trunc floor ceil "
17131713
"bool next "
17141714
)
17151715

Lib/unittest/test/testmock/testmagicmethods.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import math
12
import unittest
23
import sys
34
from unittest.mock import Mock, MagicMock, _magics
@@ -280,6 +281,10 @@ def test_magicmock_defaults(self):
280281
self.assertEqual(hash(mock), object.__hash__(mock))
281282
self.assertEqual(str(mock), object.__str__(mock))
282283
self.assertTrue(bool(mock))
284+
self.assertEqual(round(mock), mock.__round__())
285+
self.assertEqual(math.trunc(mock), mock.__trunc__())
286+
self.assertEqual(math.floor(mock), mock.__floor__())
287+
self.assertEqual(math.ceil(mock), mock.__ceil__())
283288

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

0 commit comments

Comments
 (0)