def test_callcount(self): m = Mock() m.do_stuff() m.do_stuff('abcd') m.do_more_stuff() m.do_more_stuff(3) m.do_more_stuff('with a friend') self.assertEqual(m.callcount_do_stuff(), 2) self.assertEqual(m.callcount_do_more_stuff(), 3)
def test_not_override_members(self): m = Mock() m.do_stuff = 2 try: m.expect_do_stuff(toReturn=2) m.do_stuff(2) except AttributeError: self.assertEqual(m.do_stuff, 2) pass else: self.fail('field was replaced my a method, which is wrong!') self.assertEqual(m.do_stuff, 2)
def test_verify(self): m = Mock() m.do_stuff() m.do_more_stuff() m.do_more_stuff(3) m.do_more_stuff('with a friend') self.assertTrue(m.verify_do_stuff()) self.assertTrue(m.verify_do_more_stuff()) self.assertTrue(m.verify_do_more_stuff(3)) self.assertTrue(m.verify_do_more_stuff('with a friend')) self.assertFalse(m.verify_do_stuff(None)) self.assertFalse(m.verify_do_more_stuff(0)) self.assertFalse(m.verify_do_more_stuff('')) self.assertFalse(m.verify_do_more_stuff([]))