diff options
author | Łukasz Langa <lukasz@langa.pl> | 2015-04-14 06:12:42 (GMT) |
---|---|---|
committer | Łukasz Langa <lukasz@langa.pl> | 2015-04-14 06:12:42 (GMT) |
commit | a468db9b0bd8d17575923b91db5fbc4a222d4252 (patch) | |
tree | ce2ee26a354e880ce35c3eabf7c25601823e6080 /Lib/unittest/test/testmock | |
parent | cd1aa9158ec89d541ed6309f1766e188778a1499 (diff) | |
download | cpython-a468db9b0bd8d17575923b91db5fbc4a222d4252.zip cpython-a468db9b0bd8d17575923b91db5fbc4a222d4252.tar.gz cpython-a468db9b0bd8d17575923b91db5fbc4a222d4252.tar.bz2 |
Issue #23310: Fix MagicMock's initializer to work with __methods__.
Behavior equivalent to m.configure_mock(). Patch by Kasia Jachim.
Diffstat (limited to 'Lib/unittest/test/testmock')
-rw-r--r-- | Lib/unittest/test/testmock/testmagicmethods.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/unittest/test/testmock/testmagicmethods.py b/Lib/unittest/test/testmock/testmagicmethods.py index 3c53ec4..bb9b956 100644 --- a/Lib/unittest/test/testmock/testmagicmethods.py +++ b/Lib/unittest/test/testmock/testmagicmethods.py @@ -450,5 +450,20 @@ class TestMockingMagicMethods(unittest.TestCase): bar_direct = m.__rdivmod__(2) self.assertIsInstance(bar_direct, MagicMock) + # http://bugs.python.org/issue23310 + # Check if you can change behaviour of magic methds in MagicMock init + def test_magic_in_initialization(self): + m = MagicMock(**{'__str__.return_value': "12"}) + self.assertEqual(str(m), "12") + + def test_changing_magic_set_in_initialization(self): + m = MagicMock(**{'__str__.return_value': "12"}) + m.__str__.return_value = "13" + self.assertEqual(str(m), "13") + m = MagicMock(**{'__str__.return_value': "12"}) + m.configure_mock(**{'__str__.return_value': "14"}) + self.assertEqual(str(m), "14") + + if __name__ == '__main__': unittest.main() |