diff options
author | Michael Foord <michael@voidspace.org.uk> | 2014-04-14 15:23:48 (GMT) |
---|---|---|
committer | Michael Foord <michael@voidspace.org.uk> | 2014-04-14 15:23:48 (GMT) |
commit | d2623d778663c1fee90a8835c00d0caa5690d2bd (patch) | |
tree | f47a9cbe1e1715a5d9779efc6bb11378a39cdd54 /Lib/unittest/test/testmock/testmagicmethods.py | |
parent | 604453c9cea5dfcc5c6373028d0c30a4bd4f94f2 (diff) | |
download | cpython-d2623d778663c1fee90a8835c00d0caa5690d2bd.zip cpython-d2623d778663c1fee90a8835c00d0caa5690d2bd.tar.gz cpython-d2623d778663c1fee90a8835c00d0caa5690d2bd.tar.bz2 |
Issue 20968. unittest.mock.MagicMock now supports division
Diffstat (limited to 'Lib/unittest/test/testmock/testmagicmethods.py')
-rw-r--r-- | Lib/unittest/test/testmock/testmagicmethods.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/unittest/test/testmock/testmagicmethods.py b/Lib/unittest/test/testmock/testmagicmethods.py index 5ff158d..cc0e707 100644 --- a/Lib/unittest/test/testmock/testmagicmethods.py +++ b/Lib/unittest/test/testmock/testmagicmethods.py @@ -126,6 +126,31 @@ class TestMockingMagicMethods(unittest.TestCase): self.assertEqual(7 + mock, mock) self.assertEqual(mock.value, 16) + def test_division(self): + original = mock = Mock() + mock.value = 32 + self.assertRaises(TypeError, lambda: mock / 2) + + def truediv(self, other): + mock.value /= other + return self + mock.__truediv__ = truediv + self.assertEqual(mock / 2, mock) + self.assertEqual(mock.value, 16) + + del mock.__truediv__ + def itruediv(mock): + mock /= 4 + self.assertRaises(TypeError, itruediv, mock) + mock.__itruediv__ = truediv + mock /= 8 + self.assertEqual(mock, original) + self.assertEqual(mock.value, 2) + + self.assertRaises(TypeError, lambda: 8 / mock) + mock.__rtruediv__ = truediv + self.assertEqual(0.5 / mock, mock) + self.assertEqual(mock.value, 4) def test_hash(self): mock = Mock() |