def test_spy_raises(self): s = Spy() s.raises(ValueError("Text")) with self.assertRaises(ValueError) as e: s() self.assertEqual(str(e.exception), 'Text')
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_raises_with_condition(self): wrapper = AttributeWrapper('name', Spy()) wrapper.raises_if_args(lambda x: x == 2, ValueError, 'Message') with self.assertRaises(ValueError) as e: wrapper(2) self.assertEqual(str(e.exception), 'Message')
def test_raises(self): wrapper = AttributeWrapper('name', Spy()) wrapper.raises(ValueError, 'Message') with self.assertRaises(ValueError) as e: wrapper() self.assertEqual(str(e.exception), 'Message')
def test_str(self): wrapper = AttributeWrapper('name', Spy()) self.assertTrue('Wrapper for method "name" on object:' in str(wrapper))
def test_was_called(self): wrapper = AttributeWrapper('name', Spy()) self.assertFalse(wrapper.was_called()) wrapper() self.assertTrue(wrapper.was_called())
def test_returns_value_if_specified_after_function(self): wrapper = AttributeWrapper('name', Spy()) wrapper.use_function(bool) wrapper.returns(False) self.assertFalse(wrapper(1))
def test_returns(self): wrapper = AttributeWrapper('name', Spy()) wrapper.returns(5) self.assertEqual(5, wrapper())
def test_returns_when_func_called(self): spy = Spy('string') spy.upper.returns(22) self.assertEqual(22, spy.upper())
def test_can_call_empty_spy(self): spy = Spy() spy()
def test_create_spy_on_str(self): s = 'string' spy = Spy(s)
def test_create_spy_empty(self): spy = Spy()
def test_spy_isinstance_for_empty(self): spy = Spy() self.assertTrue(isinstance(spy, type(None)))
def test_spy_isinstance(self): spy = Spy("sds") self.assertTrue(isinstance(spy, str)) self.assertFalse(isinstance(spy, int)) self.assertFalse(isinstance('text', int)) self.assertTrue(isinstance(11, int))
def test_spy_on_stringio(self): spy = Spy(StringIO('1')) spy.write.returns(10) self.assertEqual(10, spy.write())
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_was_exact_func_called(self): spy = Spy('string') spy.upper(1) self.assertTrue(spy.was_exact_function_called('upper', 1))
def test_can_call_str_func_on_spy(self): s = "string" spy = Spy(s) spy.upper()
def test_default_returns_none(self): wrapper = AttributeWrapper('name', Spy()) self.assertIsNone(wrapper())
def test_was_called_works(self): spy = Spy() self.assertFalse(spy.was_called()) spy() self.assertTrue(spy.was_called())
def test_returns_function_result(self): wrapper = AttributeWrapper('name', Spy()) wrapper.use_function(bool) self.assertTrue(wrapper(1))
def test_was_called_empty_with_arg(self): spy = Spy() spy(10) self.assertTrue(spy.was_called()) self.assertTrue(spy.was_called_with_argument(10))
def test_returns_on_called_empty(self): spy = Spy() spy.returns(11) self.assertEqual(11, spy())
def test_str_on_empty(self): spy = Spy() self.assertEqual('Empty Test Spy', str(spy))
def test_raises_with_condition_not_raise_if_no_arg(self): wrapper = AttributeWrapper('name', Spy()) wrapper.raises_if_args(lambda x: x == 2, ValueError, 'Message') wrapper()
def test_str_(self): spy = Spy('string') self.assertEqual("Test spy of the \"string\" <class 'str'>", str(spy))
def test_call_count(self): wrapper = AttributeWrapper('name', Spy()) self.assertEqual(0, wrapper.call_count()) wrapper() self.assertEqual(1, wrapper.call_count())
def test_all_calls(self): spy = Spy('string') self.assertEqual([], spy.all_calls()) spy.upper() self.assertTrue(len(spy.all_calls()) == 1)
def test_all_calls(self): wrapper = AttributeWrapper('name', Spy()) self.assertEqual([], wrapper.all_calls()) wrapper() self.assertEqual([((), {})], wrapper.all_calls())
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())