Commit 6c4fab0f authored by John Reese's avatar John Reese Committed by Victor Stinner

bpo-33516: Add support for __round__ in MagicMock (GH-6880)

unittest.mock.MagicMock now supports the __round__() magic method.
parent 4e29f566
......@@ -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__``,
......
......@@ -1709,7 +1709,7 @@ magic_methods = (
# because there is no idivmod
"divmod rdivmod neg pos abs invert "
"complex int float index "
"trunc floor ceil "
"round trunc floor ceil "
"bool next "
)
......
import math
import unittest
import sys
from unittest.mock import Mock, MagicMock, _magics
......@@ -280,6 +281,10 @@ class TestMockingMagicMethods(unittest.TestCase):
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
......
:class:`unittest.mock.MagicMock` now supports the ``__round__`` magic method.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment