コード例 #1
0
    def testUrlretrieveRaisesOnNonRetriableErrorWithoutRetry(self):
        with mock.patch.object(base, "time") as mock_time:
            with mock.patch.object(base, "urllib") as mock_urllib:
                mock_urllib.request.urlretrieve.side_effect = [IOError(2, "No such file or directory")]
                with self.assertRaises(IOError):
                    base.urlretrieve_with_retry("http://dummy.com", "/tmp/dummy")

        # Assert no retries
        self.assertFalse(mock_time.called)
コード例 #2
0
  def testUrlretrieveRaisesOnNonRetriableErrorWithoutRetry(self):
    with mock.patch.object(base, "time") as mock_time:
      with mock.patch.object(base, "urllib") as mock_urllib:
        mock_urllib.request.urlretrieve.side_effect = [
            IOError(2, "No such file or directory"),
        ]
        with self.assertRaises(IOError):
          base.urlretrieve_with_retry("http://dummy.com", "/tmp/dummy")

    # Assert no retries
    self.assertFalse(mock_time.called)
コード例 #3
0
    def testUrlretrieveRetriesOnIOError(self):
        with mock.patch.object(base, "time") as mock_time:
            with mock.patch.object(base, "urllib") as mock_urllib:
                mock_urllib.request.urlretrieve.side_effect = [_TIMEOUT, _TIMEOUT, _TIMEOUT, _TIMEOUT, _TIMEOUT, None]
                base.urlretrieve_with_retry("http://dummy.com", "/tmp/dummy")

        # Assert full backoff was tried
        actual_list = [arg[0][0] for arg in mock_time.sleep.call_args_list]
        expected_list = [1, 2, 4, 8, 16]
        for actual, expected in zip(actual_list, expected_list):
            self.assertLessEqual(abs(actual - expected), 0.25 * expected)
        self.assertEquals(len(actual_list), len(expected_list))
コード例 #4
0
ファイル: base_test.py プロジェクト: HowieYang0/notmnist-ex
    def testUrlretrieveRetriesOnIOError(self):
        with mock.patch.object(base, "time") as mock_time:
            with mock.patch.object(base, "urllib") as mock_urllib:
                mock_urllib.request.urlretrieve.side_effect = [
                    _TIMEOUT, _TIMEOUT, _TIMEOUT, _TIMEOUT, _TIMEOUT, None
                ]
                base.urlretrieve_with_retry("http://dummy.com", "/tmp/dummy")

        # Assert full backoff was tried
        actual_list = [arg[0][0] for arg in mock_time.sleep.call_args_list]
        expected_list = [1, 2, 4, 8, 16]
        for actual, expected in zip(actual_list, expected_list):
            self.assertLessEqual(abs(actual - expected), 0.25 * expected)
        self.assertEquals(len(actual_list), len(expected_list))