def test225_onCall_plus_withArgs(self): fto = ForTestOnly() self.assertEqual(fto.func1(), "func1") stub = SinonStub(ForTestOnly, "func1") stub.withArgs(1).returns("1") stub.withArgs(1).onSecondCall().returns("oncall") stub.onThirdCall().returns("##") stub.onCall(4).returns("###") # on fifth call will return "###" self.assertEqual(fto.func1(1), "1") self.assertEqual(fto.func1(1), "oncall") self.assertEqual(fto.func1(1), "1") # the priority of onCall is lower than withArgs self.assertEqual(fto.func1(), None) self.assertEqual(fto.func1(), "###")
def test370_multiple_onCall_returns(self): o = A_object() stub = SinonStub(o, 'A_func') stub.onCall(0).returns(5) stub.onCall(1).returns(10) stub.onCall(2).returns(20) stub.onCall(3).returns(30) self.assertEqual(o.A_func(), 5) self.assertEqual(o.A_func(), 10) self.assertEqual(o.A_func(), 20) self.assertEqual(o.A_func(), 30)