]> granicus.if.org Git - python/commitdiff
bpo-33516: Add support for __round__ in MagicMock (GH-6880)
authorJohn Reese <john@noswap.com>
Tue, 22 May 2018 20:01:10 +0000 (13:01 -0700)
committerVictor Stinner <vstinner@redhat.com>
Tue, 22 May 2018 20:01:10 +0000 (22:01 +0200)
unittest.mock.MagicMock now supports the __round__() magic method.

Doc/library/unittest.mock.rst
Lib/unittest/mock.py
Lib/unittest/test/testmock/testmagicmethods.py
Misc/NEWS.d/next/Library/2018-05-15-17-06-42.bpo-33516.ZzARe4.rst [new file with mode: 0644]

index bb647bb6a811507819f50ee8e9c88fda3c5eb43b..7dad3340ad61ac99c118501508aa3c95ade8499f 100644 (file)
@@ -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__``,
index 9302dedae7fdaddc318e6dff2a0a7a900b2f6ea3..e9bb4635906023696c5a925fd2d96617d4fdea1b 100644 (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 "
 )
 
index 37623dcebc6c3ac1949fb69ca9aff965283308f5..5ab95978f60db218ccef74d7b59eb4cbca0e655b 100644 (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
diff --git a/Misc/NEWS.d/next/Library/2018-05-15-17-06-42.bpo-33516.ZzARe4.rst b/Misc/NEWS.d/next/Library/2018-05-15-17-06-42.bpo-33516.ZzARe4.rst
new file mode 100644 (file)
index 0000000..77b1428
--- /dev/null
@@ -0,0 +1 @@
+:class:`unittest.mock.MagicMock` now supports the ``__round__`` magic method.