def test441_throws_does_not_reset_call_count(self): stub = SinonStub() stub.onFirstCall().throws(Exception('first call')) with self.assertRaisesRegexp(Exception, 'first call'): stub() stub.onSecondCall().throws(Exception('second call')) with self.assertRaisesRegexp(Exception, 'second call'): stub()
def test400_correct_precedence(self): stub = SinonStub() stub.withArgs('A').returns('Arg of A') stub.onFirstCall().returns('First call!') stub.onSecondCall().returns('Second call!') stub.returns('No args') self.assertEqual(stub(), 'First call!') self.assertEqual(stub('A'), 'Arg of A') self.assertEqual(stub(), 'No args')
def test371_multiple_onCall_returns_named_functions(self): o = A_object() stub = SinonStub(o, 'A_func') stub.onFirstCall().returns(5) stub.onSecondCall().returns(10) stub.onThirdCall().returns(20) self.assertEqual(o.A_func(), 5) self.assertEqual(o.A_func(), 10) self.assertEqual(o.A_func(), 20)
def test401_correct_precedence_throws(self): stub = SinonStub() stub.withArgs('A').throws(Exception('A')) stub.onFirstCall().throws(Exception('First call!')) stub.onSecondCall().throws(Exception('Second call!')) stub.throws(Exception('No args')) with self.assertRaisesRegexp(Exception, 'First call!'): stub() with self.assertRaisesRegexp(Exception, 'A'): stub('A') with self.assertRaisesRegexp(Exception, 'No args'): stub()
def test440_returns_does_not_reset_call_count(self): stub = SinonStub() stub.onFirstCall().returns('first call') self.assertEqual(stub(), 'first call') stub.onSecondCall().returns('second call') self.assertEqual(stub(), 'second call')
def test420_conditions_can_be_overwritten_onCall(self): stub = SinonStub() stub.onFirstCall().onSecondCall().returns(3) self.assertEqual(stub(), None) self.assertEqual(stub(), 3)
def test230_onFirstCall(self): fto = ForTestOnly() stub = SinonStub(ForTestOnly, "func1") stub.onFirstCall().returns("onFirstCall") self.assertEqual(fto.func1(), "onFirstCall")