mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-33516: Add support for __round__ in MagicMock (GH-6880)
unittest.mock.MagicMock now supports the __round__() magic method.
This commit is contained in:
parent
4e29f566e8
commit
6c4fab0f4b
4 changed files with 8 additions and 2 deletions
|
@ -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 "
|
||||
)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue