Example #1
0
    def test_call_with_fake_and_args(self):
        """Testing FunctionSpy calls with call_fake and arguments"""
        obj = MathClass()

        self.agency.spy_on(obj.do_math_pos, call_fake=fake_do_math)
        result = obj.do_math_pos(10, 20)

        self.assertEqual(result, -10)
        self.assertEqual(len(obj.do_math_pos.calls), 1)
        self.assertEqual(obj.do_math_pos.calls[0].args, (10, 20))
        self.assertEqual(obj.do_math_pos.calls[0].kwargs, {})
Example #2
0
    def test_call_with_original_true_and_unbound_method_args(self):
        """Testing FunctionSpy calls with call_original=True and unbound
        method with all positional arguments
        """
        self.agency.spy_on(MathClass.do_math_pos, call_original=True)

        obj = MathClass()
        result = obj.do_math_pos(10, 20)

        self.assertEqual(result, 30)
        self.assertEqual(len(MathClass.do_math_pos.calls), 1)
        self.assertTrue(MathClass.do_math_pos.last_called_with(10, 20))
Example #3
0
    def test_call_with_original_true_and_bound_method_args(self):
        """Testing FunctionSpy calls with call_original=True and bound method
        with all positional arguments
        """
        obj = MathClass()

        self.agency.spy_on(obj.do_math_pos, call_original=True)
        result = obj.do_math_pos(10, 20)

        self.assertEqual(result, 30)
        self.assertEqual(len(obj.do_math_pos.calls), 1)
        self.assertEqual(obj.do_math_pos.calls[0].args, (10, 20))
        self.assertEqual(len(obj.do_math_pos.calls[0].kwargs), 0)
Example #4
0
    def test_call_with_all_original_false_and_args(self):
        """Testing FunctionSpy calls with call_original=False and positional
        arguments
        """
        obj = MathClass()

        self.agency.spy_on(obj.do_math_pos, call_original=False)
        result = obj.do_math_pos(10, 20)

        self.assertIsNone(result)
        self.assertEqual(len(obj.do_math_pos.calls), 1)
        self.assertEqual(obj.do_math_pos.calls[0].args, (10, 20))
        self.assertEqual(obj.do_math_pos.calls[0].kwargs, {})