Пример #1
0
 def test425_returns_throws_can_be_overwritten(self):
     stub = SinonStub()
     self.assertEqual(stub(), None)
     stub.returns(5)
     self.assertEqual(stub(), 5)
     stub.throws()
     with self.assertRaises(Exception):
         stub()
     stub.returns(10)
     self.assertEqual(stub(), 10)
Пример #2
0
 def test221_throws(self):
     fto = ForTestOnly()
     self.assertEqual(fto.func1(), "func1")
     stub = SinonStub(ForTestOnly, "func1")
     stub.throws()
     with self.assertRaises(Exception) as context:
         fto.func1()
     stub.throws(TypeError)
     with self.assertRaises(TypeError) as context:
         fto.func1()
Пример #3
0
 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()
Пример #4
0
 def test409_chained_withArgs_onCall_throws(self):
     stub = SinonStub()
     stub.withArgs(42).onFirstCall().throws(
         Exception('A')).onSecondCall().throws(Exception('B'))
     stub.throws(Exception('C'))
     with self.assertRaisesRegexp(Exception, 'C'):
         stub(1)
     with self.assertRaisesRegexp(Exception, 'A'):
         stub(42)
     with self.assertRaisesRegexp(Exception, 'C'):
         stub(1)
     with self.assertRaisesRegexp(Exception, 'B'):
         stub(42)
     with self.assertRaisesRegexp(Exception, 'C'):
         stub(1)
     with self.assertRaisesRegexp(Exception, 'C'):
         stub(42)