本文整理汇总了Python中urllib3.util.retry.Retry.increment方法的典型用法代码示例。如果您正苦于以下问题:Python Retry.increment方法的具体用法?Python Retry.increment怎么用?Python Retry.increment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib3.util.retry.Retry
的用法示例。
在下文中一共展示了Retry.increment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_retry_read_zero
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import increment [as 别名]
def test_retry_read_zero(self):
""" No second chances on read timeouts, by default """
error = ReadTimeoutError(None, "/", "read timed out")
retry = Retry(read=0)
with pytest.raises(MaxRetryError) as e:
retry.increment(method='GET', error=error)
assert e.value.reason == error
示例2: test_error_message
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import increment [as 别名]
def test_error_message(self):
retry = Retry(total=0)
with pytest.raises(MaxRetryError) as e:
retry = retry.increment(method='GET',
error=ReadTimeoutError(None, "/", "read timed out"))
assert 'Caused by redirect' not in str(e.value)
assert str(e.value.reason) == 'None: read timed out'
retry = Retry(total=1)
with pytest.raises(MaxRetryError) as e:
retry = retry.increment('POST', '/')
retry = retry.increment('POST', '/')
assert 'Caused by redirect' not in str(e.value)
assert isinstance(e.value.reason, ResponseError)
assert str(e.value.reason) == ResponseError.GENERIC_ERROR
retry = Retry(total=1)
response = HTTPResponse(status=500)
with pytest.raises(MaxRetryError) as e:
retry = retry.increment('POST', '/', response=response)
retry = retry.increment('POST', '/', response=response)
assert 'Caused by redirect' not in str(e.value)
msg = ResponseError.SPECIFIC_ERROR.format(status_code=500)
assert str(e.value.reason) == msg
retry = Retry(connect=1)
with pytest.raises(MaxRetryError) as e:
retry = retry.increment(error=ConnectTimeoutError('conntimeout'))
retry = retry.increment(error=ConnectTimeoutError('conntimeout'))
assert 'Caused by redirect' not in str(e.value)
assert str(e.value.reason) == 'conntimeout'
示例3: test_backoff
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import increment [as 别名]
def test_backoff(self):
""" Backoff is computed correctly """
max_backoff = Retry.BACKOFF_MAX
retry = Retry(total=100, backoff_factor=0.2)
self.assertEqual(retry.get_backoff_time(), 0) # First request
retry = retry.increment()
self.assertEqual(retry.get_backoff_time(), 0) # First retry
retry = retry.increment()
self.assertEqual(retry.backoff_factor, 0.2)
self.assertEqual(retry.total, 98)
self.assertEqual(retry.get_backoff_time(), 0.4) # Start backoff
retry = retry.increment()
self.assertEqual(retry.get_backoff_time(), 0.8)
retry = retry.increment()
self.assertEqual(retry.get_backoff_time(), 1.6)
for i in xrange(10):
retry = retry.increment()
self.assertEqual(retry.get_backoff_time(), max_backoff)
示例4: test_backoff
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import increment [as 别名]
def test_backoff(self):
""" Backoff is computed correctly """
max_backoff = Retry.BACKOFF_MAX
retry = Retry(total=100, backoff_factor=0.2)
assert retry.get_backoff_time() == 0 # First request
retry = retry.increment(method='GET')
assert retry.get_backoff_time() == 0 # First retry
retry = retry.increment(method='GET')
assert retry.backoff_factor == 0.2
assert retry.total == 98
assert retry.get_backoff_time() == 0.4 # Start backoff
retry = retry.increment(method='GET')
assert retry.get_backoff_time() == 0.8
retry = retry.increment(method='GET')
assert retry.get_backoff_time() == 1.6
for _ in xrange(10):
retry = retry.increment(method='GET')
assert retry.get_backoff_time() == max_backoff
示例5: test_retry_higher_total_loses_vs_read
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import increment [as 别名]
def test_retry_higher_total_loses_vs_read(self):
""" A lower read timeout than the total is honored """
error = ReadTimeoutError(None, "/", "read timed out")
retry = Retry(read=2, total=3)
retry = retry.increment(method='GET', error=error)
retry = retry.increment(method='GET', error=error)
with pytest.raises(MaxRetryError):
retry.increment(method='GET', error=error)
示例6: test_status_counter
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import increment [as 别名]
def test_status_counter(self):
resp = HTTPResponse(status=400)
retry = Retry(status=2)
retry = retry.increment(response=resp)
retry = retry.increment(response=resp)
with pytest.raises(MaxRetryError) as e:
retry.increment(response=resp)
assert str(e.value.reason) == ResponseError.SPECIFIC_ERROR.format(status_code=400)
示例7: test_retry_higher_total_loses
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import increment [as 别名]
def test_retry_higher_total_loses(self):
""" A lower connect timeout than the total is honored """
error = ConnectTimeoutError()
retry = Retry(connect=2, total=3)
retry = retry.increment(error=error)
retry = retry.increment(error=error)
with pytest.raises(MaxRetryError):
retry.increment(error=error)
示例8: test_retry_both_specified
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import increment [as 别名]
def test_retry_both_specified(self):
"""Total can win if it's lower than the connect value"""
error = ConnectTimeoutError()
retry = Retry(connect=3, total=2)
retry = retry.increment(error=error)
retry = retry.increment(error=error)
with pytest.raises(MaxRetryError) as e:
retry.increment(error=error)
assert e.value.reason == error
示例9: test_retry_read_zero
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import increment [as 别名]
def test_retry_read_zero(self):
""" No second chances on read timeouts, by default """
error = ReadTimeoutError(None, "/", "read timed out")
retry = Retry(read=0)
try:
retry.increment(error=error)
self.fail("Failed to raise error.")
except MaxRetryError as e:
self.assertEqual(e.reason, error)
示例10: test_backoff_reset_after_redirect
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import increment [as 别名]
def test_backoff_reset_after_redirect(self):
retry = Retry(total=100, redirect=5, backoff_factor=0.2)
retry = retry.increment()
retry = retry.increment()
self.assertEqual(retry.get_backoff_time(), 0.4)
redirect_response = HTTPResponse(status=302, headers={'location': 'test'})
retry = retry.increment(response=redirect_response)
self.assertEqual(retry.get_backoff_time(), 0)
retry = retry.increment()
retry = retry.increment()
self.assertEqual(retry.get_backoff_time(), 0.4)
示例11: test_backoff_reset_after_redirect
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import increment [as 别名]
def test_backoff_reset_after_redirect(self):
retry = Retry(total=100, redirect=5, backoff_factor=0.2)
retry = retry.increment(method='GET')
retry = retry.increment(method='GET')
assert retry.get_backoff_time() == 0.4
redirect_response = HTTPResponse(status=302, headers={'location': 'test'})
retry = retry.increment(method='GET', response=redirect_response)
assert retry.get_backoff_time() == 0
retry = retry.increment(method='GET')
retry = retry.increment(method='GET')
assert retry.get_backoff_time() == 0.4
示例12: test_retry_both_specified
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import increment [as 别名]
def test_retry_both_specified(self):
"""Total can win if it's lower than the connect value"""
error = ConnectTimeoutError()
retry = Retry(connect=3, total=2)
retry = retry.increment(error=error)
retry = retry.increment(error=error)
try:
retry.increment(error=error)
self.fail("Failed to raise error.")
except MaxRetryError as e:
self.assertEqual(e.reason, error)
示例13: test_history
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import increment [as 别名]
def test_history(self):
retry = Retry(total=10)
self.assertEqual(retry.history, tuple())
connection_error = ConnectTimeoutError('conntimeout')
retry = retry.increment('GET', '/test1', None, connection_error)
self.assertEqual(retry.history, (RequestHistory('GET', '/test1', connection_error, None, None),))
read_error = ReadTimeoutError(None, "/test2", "read timed out")
retry = retry.increment('POST', '/test2', None, read_error)
self.assertEqual(retry.history, (RequestHistory('GET', '/test1', connection_error, None, None),
RequestHistory('POST', '/test2', read_error, None, None)))
response = HTTPResponse(status=500)
retry = retry.increment('GET', '/test3', response, None)
self.assertEqual(retry.history, (RequestHistory('GET', '/test1', connection_error, None, None),
RequestHistory('POST', '/test2', read_error, None, None),
RequestHistory('GET', '/test3', None, 500, None)))
示例14: test_string
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import increment [as 别名]
def test_string(self):
""" Retry string representation looks the way we expect """
retry = Retry()
assert str(retry) == 'Retry(total=10, connect=None, read=None, redirect=None, status=None)'
for _ in range(3):
retry = retry.increment(method='GET')
assert str(retry) == 'Retry(total=7, connect=None, read=None, redirect=None, status=None)'
示例15: test_retry_higher_total_loses_vs_read
# 需要导入模块: from urllib3.util.retry import Retry [as 别名]
# 或者: from urllib3.util.retry.Retry import increment [as 别名]
def test_retry_higher_total_loses_vs_read(self):
""" A lower read timeout than the total is honored """
error = ReadTimeoutError(None, "/", "read timed out")
retry = Retry(read=2, total=3)
retry = retry.increment(error=error)
retry = retry.increment(error=error)
self.assertRaises(MaxRetryError, retry.increment, error=error)