summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay Holder <ray@blacklocus.com>2014-11-09 20:24:34 -0600
committerRay Holder <ray@blacklocus.com>2014-11-09 20:24:34 -0600
commitad35b7e2401574d0e49bce04712f73ad03750a15 (patch)
tree51e81569d21a47832c10078757781ee7904c4358
parentd51fd58129df84615dbb28ed2377301e0fc9fc60 (diff)
downloadretrying-ad35b7e2401574d0e49bce04712f73ad03750a15.tar.gz
fix up some some pep8 stuff
-rw-r--r--test_retrying.py33
1 files changed, 29 insertions, 4 deletions
diff --git a/test_retrying.py b/test_retrying.py
index da440b0..bfef02d 100644
--- a/test_retrying.py
+++ b/test_retrying.py
@@ -19,6 +19,7 @@ from retrying import RetryError
from retrying import Retrying
from retrying import retry
+
class TestStopConditions(unittest.TestCase):
def test_never_stop(self):
@@ -38,7 +39,7 @@ class TestStopConditions(unittest.TestCase):
self.assertTrue(r.stop(2, 1001))
def test_legacy_explicit_stop_type(self):
- r = Retrying(stop="stop_after_attempt")
+ Retrying(stop="stop_after_attempt")
def test_stop_func(self):
r = Retrying(stop_func=lambda attempt, delay: attempt == delay)
@@ -70,7 +71,9 @@ class TestWaitConditions(unittest.TestCase):
times.add(r.wait(1, 6546))
times.add(r.wait(1, 6546))
times.add(r.wait(1, 6546))
- self.assertTrue(len(times) > 1) # this is kind of non-deterministic...
+
+ # this is kind of non-deterministic...
+ self.assertTrue(len(times) > 1)
for t in times:
self.assertTrue(t >= 1000)
self.assertTrue(t <= 2000)
@@ -82,7 +85,9 @@ class TestWaitConditions(unittest.TestCase):
times.add(r.wait(1, 6546))
times.add(r.wait(1, 6546))
times.add(r.wait(1, 6546))
- self.assertTrue(len(times) > 1) # this is kind of non-deterministic...
+
+ # this is kind of non-deterministic...
+ self.assertTrue(len(times) > 1)
for t in times:
self.assertTrue(t >= 0)
self.assertTrue(t <= 2000)
@@ -119,7 +124,7 @@ class TestWaitConditions(unittest.TestCase):
self.assertEqual(r.wait(50, 0), 50000)
def test_legacy_explicit_wait_type(self):
- r = Retrying(wait="exponential_sleep")
+ Retrying(wait="exponential_sleep")
def test_wait_func(self):
r = Retrying(wait_func=lambda attempt, delay: attempt * delay)
@@ -146,6 +151,7 @@ class NoneReturnUntilAfterCount:
return None
return True
+
class NoIOErrorAfterCount:
"""
This class holds counter state for invoking a method several times in a row.
@@ -164,6 +170,7 @@ class NoIOErrorAfterCount:
raise IOError("Hi there, I'm an IOError")
return True
+
class NoNameErrorAfterCount:
"""
This class holds counter state for invoking a method several times in a row.
@@ -182,6 +189,7 @@ class NoNameErrorAfterCount:
raise NameError("Hi there, I'm a NameError")
return True
+
class CustomError(Exception):
"""
This is a custom exception class. Note that For Python 2.x, we don't
@@ -198,6 +206,7 @@ class CustomError(Exception):
def __str__(self):
return repr(self.value)
+
class NoCustomErrorAfterCount:
"""
This class holds counter state for invoking a method several times in a row.
@@ -217,40 +226,49 @@ class NoCustomErrorAfterCount:
raise CustomError(derived_message)
return True
+
def retry_if_result_none(result):
return result is None
+
def retry_if_exception_of_type(retryable_types):
def retry_if_exception_these_types(exception):
print("Detected Exception of type: {0}".format(str(type(exception))))
return isinstance(exception, retryable_types)
return retry_if_exception_these_types
+
def current_time_ms():
return int(round(time.time() * 1000))
+
@retry(wait_fixed=50, retry_on_result=retry_if_result_none)
def _retryable_test_with_wait(thing):
return thing.go()
+
@retry(stop_max_attempt_number=3, retry_on_result=retry_if_result_none)
def _retryable_test_with_stop(thing):
return thing.go()
+
@retry(retry_on_exception=retry_if_exception_of_type(IOError))
def _retryable_test_with_exception_type_io(thing):
return thing.go()
+
@retry(retry_on_exception=retry_if_exception_of_type(IOError), wrap_exception=True)
def _retryable_test_with_exception_type_io_wrap(thing):
return thing.go()
+
@retry(
stop_max_attempt_number=3,
retry_on_exception=retry_if_exception_of_type(IOError))
def _retryable_test_with_exception_type_io_attempt_limit(thing):
return thing.go()
+
@retry(
stop_max_attempt_number=3,
retry_on_exception=retry_if_exception_of_type(IOError),
@@ -258,28 +276,34 @@ def _retryable_test_with_exception_type_io_attempt_limit(thing):
def _retryable_test_with_exception_type_io_attempt_limit_wrap(thing):
return thing.go()
+
@retry
def _retryable_default(thing):
return thing.go()
+
@retry()
def _retryable_default_f(thing):
return thing.go()
+
@retry(retry_on_exception=retry_if_exception_of_type(CustomError))
def _retryable_test_with_exception_type_custom(thing):
return thing.go()
+
@retry(retry_on_exception=retry_if_exception_of_type(CustomError), wrap_exception=True)
def _retryable_test_with_exception_type_custom_wrap(thing):
return thing.go()
+
@retry(
stop_max_attempt_number=3,
retry_on_exception=retry_if_exception_of_type(CustomError))
def _retryable_test_with_exception_type_custom_attempt_limit(thing):
return thing.go()
+
@retry(
stop_max_attempt_number=3,
retry_on_exception=retry_if_exception_of_type(CustomError),
@@ -287,6 +311,7 @@ def _retryable_test_with_exception_type_custom_attempt_limit(thing):
def _retryable_test_with_exception_type_custom_attempt_limit_wrap(thing):
return thing.go()
+
class TestDecoratorWrapper(unittest.TestCase):
def test_with_wait(self):