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

unittest.mock.MagicMock now supports the __round__() magic method.
This commit is contained in:
John Reese 2018-05-22 13:01:10 -07:00 committed by Victor Stinner
parent 4e29f566e8
commit 6c4fab0f4b
4 changed files with 8 additions and 2 deletions

View file

@ -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 "
)

View file

@ -1,3 +1,4 @@
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