Issue #23581: Add matmul support to MagicMock.

Patch by Håkan Lövdahl.
This commit is contained in:
Berker Peksag 2015-03-12 20:42:48 +02:00
parent 4a0e14730b
commit 9bd8af788d
3 changed files with 14 additions and 1 deletions

View File

@ -1668,7 +1668,7 @@ magic_methods = (
) )
numerics = ( numerics = (
"add sub mul div floordiv mod lshift rshift and xor or pow truediv" "add sub mul matmul div floordiv mod lshift rshift and xor or pow truediv"
) )
inplace = ' '.join('i%s' % n for n in numerics.split()) inplace = ' '.join('i%s' % n for n in numerics.split())
right = ' '.join('r%s' % n for n in numerics.split()) right = ' '.join('r%s' % n for n in numerics.split())

View File

@ -424,5 +424,16 @@ class TestMockingMagicMethods(unittest.TestCase):
self.assertEqual(list(m), []) self.assertEqual(list(m), [])
def test_matmul(self):
m = MagicMock()
self.assertIsInstance(m @ 1, MagicMock)
m.__matmul__.return_value = 42
m.__rmatmul__.return_value = 666
m.__imatmul__.return_value = 24
self.assertEqual(m @ 1, 42)
self.assertEqual(1 @ m, 666)
m @= 24
self.assertEqual(m, 24)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -18,6 +18,8 @@ Core and Builtins
Library Library
------- -------
- Issue #23581: Add matmul support to MagicMock. Patch by Håkan Lövdahl.
- Issue #23566: enable(), register(), dump_traceback() and - Issue #23566: enable(), register(), dump_traceback() and
dump_traceback_later() functions of faulthandler now accept file dump_traceback_later() functions of faulthandler now accept file
descriptors. Patch by Wei Wu. descriptors. Patch by Wei Wu.