예제 #1
0
    def test_last_called_with(self):
        """Testing FunctionSpy.last_called_with"""
        obj = MathClass()
        self.agency.spy_on(obj.do_math_mixed)

        obj.do_math_mixed(1, 2)
        obj.do_math_mixed(3, 4)

        self.assertFalse(obj.do_math_mixed.last_called_with(1, a=2))
        self.assertTrue(obj.do_math_mixed.last_called_with(3, b=4))
예제 #2
0
    def test_last_called_with_and_keyword_args(self):
        """Testing FunctionSpy.last_called_with and keyword arguments"""
        obj = MathClass()
        self.agency.spy_on(obj.do_math_mixed)

        obj.do_math_mixed(a=1, b=2)
        obj.do_math_mixed(a=3, b=4)

        self.assertTrue(obj.do_math_mixed.last_called_with(3, b=4))
        self.assertFalse(obj.do_math_mixed.last_called_with(1, b=2))
        self.assertFalse(obj.do_math_mixed.last_called_with(1, b=2, c=3))
예제 #3
0
    def test_returned(self):
        """Testing SpyCall.returned"""
        obj = MathClass()
        self.agency.spy_on(obj.do_math_mixed)

        obj.do_math_mixed(1, 2)
        obj.do_math_mixed(3, 4)

        call = obj.do_math_mixed.calls[0]
        self.assertTrue(call.returned(3))
        self.assertFalse(call.returned(7))
        self.assertFalse(call.returned(None))
예제 #4
0
    def test_called_with_and_partial_args(self):
        """Testing SpyCall.called_with and partial arguments"""
        obj = MathClass()
        self.agency.spy_on(obj.do_math_mixed)

        obj.do_math_mixed(1, 2)
        obj.do_math_mixed(3, 4)

        call = obj.do_math_mixed.calls[0]
        self.assertTrue(call.called_with(1))
        self.assertFalse(call.called_with(1, 2, 3))
        self.assertFalse(call.called_with(3))
예제 #5
0
    def test_last_called_with_and_partial_args(self):
        """Testing FunctionSpy.called_with and partial arguments"""
        obj = MathClass()
        self.agency.spy_on(obj.do_math_mixed)

        obj.do_math_mixed(1, 2)
        obj.do_math_mixed(3, 4)

        self.assertTrue(obj.do_math_mixed.last_called_with(3))
        self.assertTrue(obj.do_math_mixed.last_called_with(3, b=4))
        self.assertFalse(obj.do_math_mixed.last_called_with(3, b=4, c=5))
        self.assertFalse(obj.do_math_mixed.last_called_with(1, b=2))
예제 #6
0
    def test_returned(self):
        """Testing SpyCall.returned"""
        obj = MathClass()
        self.agency.spy_on(obj.do_math_mixed)

        obj.do_math_mixed(1, 2)
        obj.do_math_mixed(3, 4)

        call = obj.do_math_mixed.calls[0]
        self.assertTrue(call.returned(3))
        self.assertFalse(call.returned(7))
        self.assertFalse(call.returned(None))
예제 #7
0
    def test_called_with_and_partial_args(self):
        """Testing SpyCall.called_with and partial arguments"""
        obj = MathClass()
        self.agency.spy_on(obj.do_math_mixed)

        obj.do_math_mixed(1, 2)
        obj.do_math_mixed(3, 4)

        call = obj.do_math_mixed.calls[0]
        self.assertTrue(call.called_with(1))
        self.assertFalse(call.called_with(1, 2, 3))
        self.assertFalse(call.called_with(3))
예제 #8
0
    def test_called_with(self):
        """Testing SpyCall.called_with"""
        obj = MathClass()
        self.agency.spy_on(obj.do_math_mixed)

        obj.do_math_mixed(1, b=2)
        obj.do_math_mixed(3, b=4)

        call = obj.do_math_mixed.calls[0]
        self.assertTrue(call.called_with(1, b=2))
        self.assertTrue(call.called_with(a=1, b=2))
        self.assertFalse(call.called_with(3, b=4))
        self.assertFalse(call.called_with(1, 2))
예제 #9
0
    def test_called_with_and_keyword_args(self):
        """Testing SpyCall.called_with and keyword arguments"""
        obj = MathClass()
        self.agency.spy_on(obj.do_math_mixed)

        obj.do_math_mixed(a=1, b=2)
        obj.do_math_mixed(a=3, b=4)

        call = obj.do_math_mixed.calls[0]
        self.assertTrue(call.called_with(1, b=2))
        self.assertTrue(call.called_with(a=1, b=2))
        self.assertFalse(call.called_with(1, 2))
        self.assertFalse(call.called_with(3, b=4))
예제 #10
0
    def test_called_with(self):
        """Testing SpyCall.called_with"""
        obj = MathClass()
        self.agency.spy_on(obj.do_math_mixed)

        obj.do_math_mixed(1, b=2)
        obj.do_math_mixed(3, b=4)

        call = obj.do_math_mixed.calls[0]
        self.assertTrue(call.called_with(1, b=2))
        self.assertTrue(call.called_with(a=1, b=2))
        self.assertFalse(call.called_with(3, b=4))
        self.assertFalse(call.called_with(1, 2))
예제 #11
0
    def test_called_with_and_keyword_args(self):
        """Testing SpyCall.called_with and keyword arguments"""
        obj = MathClass()
        self.agency.spy_on(obj.do_math_mixed)

        obj.do_math_mixed(a=1, b=2)
        obj.do_math_mixed(a=3, b=4)

        call = obj.do_math_mixed.calls[0]
        self.assertTrue(call.called_with(1, b=2))
        self.assertTrue(call.called_with(a=1, b=2))
        self.assertFalse(call.called_with(1, 2))
        self.assertFalse(call.called_with(3, b=4))
예제 #12
0
    def test_called_with_and_partial_kwargs(self):
        """Testing FunctionSpy.called_with and partial keyword arguments"""
        obj = MathClass()
        self.agency.spy_on(obj.do_math_mixed)

        obj.do_math_mixed(a=1, b=2)
        obj.do_math_mixed(a=3, b=4)

        self.assertTrue(obj.do_math_mixed.called_with(1))
        self.assertTrue(obj.do_math_mixed.called_with(b=2))
        self.assertTrue(obj.do_math_mixed.called_with(3))
        self.assertTrue(obj.do_math_mixed.called_with(b=4))
        self.assertTrue(obj.do_math_mixed.called_with(a=1, b=2))
        self.assertTrue(obj.do_math_mixed.called_with(a=3, b=4))
        self.assertFalse(obj.do_math_mixed.called_with(1, 2))
        self.assertFalse(obj.do_math_mixed.called_with(3, 4))
        self.assertFalse(obj.do_math_mixed.called_with(a=4))
        self.assertFalse(obj.do_math_mixed.called_with(a=1, b=2, c=3))
        self.assertFalse(obj.do_math_mixed.called_with(a=1, b=4))
        self.assertFalse(obj.do_math_mixed.called_with(a=3, b=2))