def test226_throws_with_condition(self): fto = ForTestOnly() self.assertEqual(fto.func1(), "func1") stub = SinonStub(ForTestOnly, "func1") stub.onSecondCall().throws() fto.func1() with self.assertRaises(Exception) as context: fto.func1()
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 test223_onCall(self): fto = ForTestOnly() self.assertEqual(fto.func1(), "func1") stub = SinonStub(ForTestOnly, "func1") stub.onSecondCall().returns("oncall") self.assertEqual(fto.func1(), None) self.assertEqual(fto.func1(), "oncall") stub.onThirdCall().returns("oncall") self.assertEqual(fto.func1(), "oncall") self.assertEqual(fto.func1(), None)
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')