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))
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))
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))
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))
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))
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))
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))
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))