Beispiel #1
0
    def test_spy_raises(self):
        s = Spy()
        s.raises(ValueError("Text"))
        with self.assertRaises(ValueError) as e:
            s()

        self.assertEqual(str(e.exception), 'Text')
Beispiel #2
0
    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')
Beispiel #3
0
    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')
Beispiel #4
0
 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())
Beispiel #5
0
 def test_str(self):
     wrapper = AttributeWrapper('name', Spy())
     self.assertTrue('Wrapper for method "name" on object:' in str(wrapper))
Beispiel #6
0
 def test_was_called(self):
     wrapper = AttributeWrapper('name', Spy())
     self.assertFalse(wrapper.was_called())
     wrapper()
     self.assertTrue(wrapper.was_called())
Beispiel #7
0
 def test_returns_value_if_specified_after_function(self):
     wrapper = AttributeWrapper('name', Spy())
     wrapper.use_function(bool)
     wrapper.returns(False)
     self.assertFalse(wrapper(1))
Beispiel #8
0
 def test_returns(self):
     wrapper = AttributeWrapper('name', Spy())
     wrapper.returns(5)
     self.assertEqual(5, wrapper())
Beispiel #9
0
 def test_returns_when_func_called(self):
     spy = Spy('string')
     spy.upper.returns(22)
     self.assertEqual(22, spy.upper())
Beispiel #10
0
 def test_can_call_empty_spy(self):
     spy = Spy()
     spy()
Beispiel #11
0
 def test_create_spy_on_str(self):
     s = 'string'
     spy = Spy(s)
Beispiel #12
0
 def test_create_spy_empty(self):
     spy = Spy()
Beispiel #13
0
 def test_spy_isinstance_for_empty(self):
     spy = Spy()
     self.assertTrue(isinstance(spy, type(None)))
Beispiel #14
0
 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))
Beispiel #15
0
 def test_spy_on_stringio(self):
     spy = Spy(StringIO('1'))
     spy.write.returns(10)
     self.assertEqual(10, spy.write())
Beispiel #16
0
 def test_was_func_called_with_arg(self):
     spy = Spy('string')
     spy.upper(1)
     self.assertTrue(spy.was_function_with_argument_called('upper', 1))
Beispiel #17
0
 def test_was_exact_func_called(self):
     spy = Spy('string')
     spy.upper(1)
     self.assertTrue(spy.was_exact_function_called('upper', 1))
Beispiel #18
0
 def test_can_call_str_func_on_spy(self):
     s = "string"
     spy = Spy(s)
     spy.upper()
Beispiel #19
0
 def test_default_returns_none(self):
     wrapper = AttributeWrapper('name', Spy())
     self.assertIsNone(wrapper())
Beispiel #20
0
 def test_was_called_works(self):
     spy = Spy()
     self.assertFalse(spy.was_called())
     spy()
     self.assertTrue(spy.was_called())
Beispiel #21
0
 def test_returns_function_result(self):
     wrapper = AttributeWrapper('name', Spy())
     wrapper.use_function(bool)
     self.assertTrue(wrapper(1))
Beispiel #22
0
 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))
Beispiel #23
0
 def test_returns_on_called_empty(self):
     spy = Spy()
     spy.returns(11)
     self.assertEqual(11, spy())
Beispiel #24
0
 def test_str_on_empty(self):
     spy = Spy()
     self.assertEqual('Empty Test Spy', str(spy))
Beispiel #25
0
 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()
Beispiel #26
0
 def test_str_(self):
     spy = Spy('string')
     self.assertEqual("Test spy of the \"string\" <class 'str'>", str(spy))
Beispiel #27
0
 def test_call_count(self):
     wrapper = AttributeWrapper('name', Spy())
     self.assertEqual(0, wrapper.call_count())
     wrapper()
     self.assertEqual(1, wrapper.call_count())
Beispiel #28
0
 def test_all_calls(self):
     spy = Spy('string')
     self.assertEqual([], spy.all_calls())
     spy.upper()
     self.assertTrue(len(spy.all_calls()) == 1)
Beispiel #29
0
 def test_all_calls(self):
     wrapper = AttributeWrapper('name', Spy())
     self.assertEqual([], wrapper.all_calls())
     wrapper()
     self.assertEqual([((), {})], wrapper.all_calls())
Beispiel #30
0
 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())