コード例 #1
0
 def test_non_retryable(self):
     with patch('time.sleep') as mock_time:
         fcn = MagicMock()
         fcn.side_effect = [BadJson('a'), self.response]
         # no assertRaises until 2.7
         try:
             _translate_and_retry(fcn, 3)
             self.fail('should have raised BadJson')
         except BadJson:
             pass
         self.assertEqual([], mock_time.mock_calls)
コード例 #2
0
 def test_non_retryable(self):
     with patch('time.sleep') as mock_time:
         fcn = MagicMock()
         fcn.side_effect = [BadJson('a'), self.response]
         # no assertRaises until 2.7
         try:
             _translate_and_retry(fcn, 3)
             self.fail('should have raised BadJson')
         except BadJson:
             pass
         self.assertEqual([], mock_time.mock_calls)
コード例 #3
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)
コード例 #4
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)
コード例 #5
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)
コード例 #6
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)
コード例 #7
0
 def test_works_first_try(self):
     fcn = MagicMock()
     fcn.side_effect = [self.response]
     self.assertTrue(self.response is _translate_and_retry(fcn, 3))  # no assertIs until 2.7
コード例 #8
0
 def test_works_first_try(self):
     fcn = MagicMock()
     fcn.side_effect = [self.response]
     self.assertTrue(self.response is _translate_and_retry(
         fcn, 3))  # no assertIs until 2.7