def test_call_count(self): s = Spy('str') s.upper() self.assertEqual(1, s.upper.call_count()) s.lower() self.assertEqual(1, s.upper.call_count()) s.upper() self.assertEqual(2, s.upper.call_count())
def test_returns_when_func_called(self): spy = Spy('string') spy.upper.returns(22) self.assertEqual(22, spy.upper())
def test_was_exact_func_called(self): spy = Spy('string') spy.upper(1) self.assertTrue(spy.was_exact_function_called('upper', 1))
def test_was_func_called_with_arg(self): spy = Spy('string') spy.upper(1) self.assertTrue(spy.was_function_with_argument_called('upper', 1))
def test_all_calls(self): spy = Spy('string') self.assertEqual([], spy.all_calls()) spy.upper() self.assertTrue(len(spy.all_calls()) == 1)
def test_can_call_str_func_on_spy(self): s = "string" spy = Spy(s) spy.upper()
def test_all_calls_args_flatten(self): s = Spy('str') s.replace('t', 'T') s.upper() s.lower(1) self.assertEqual(['t', 'T', 1], s.all_calls_args_flatten())
def test_all_calls_args(self): s = Spy('str') s.replace('t', 'T') s.upper() s.lower(1) self.assertEqual([('t', 'T'), (), (1, )], s.all_calls_args())