예제 #1
0
 def test_never_works(self):
     with patch('time.sleep') as mock_time:
         fcn = MagicMock()
         fcn.side_effect = [
             ServiceError('a'), ServiceError('a'), ServiceError('a'), self.response
         ]
         # no assertRaises until 2.7
         try:
             _translate_and_retry(fcn, 3)
             self.fail('should have raised ServiceError')
         except ServiceError:
             pass
         self.assertEqual([call(1.0), call(1.5)], mock_time.mock_calls)
예제 #2
0
 def test_works_second_try(self):
     with patch('time.sleep') as mock_time:
         fcn = MagicMock()
         fcn.side_effect = [ServiceError('a'), self.response]
         self.assertTrue(self.response is _translate_and_retry(
             fcn, 3))  # no assertIs until 2.7
         self.assertEqual([call(1.0)], mock_time.mock_calls)