forked from pool/python-circuitbreaker
OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-circuitbreaker?expand=0&rev=2
66 lines
1.8 KiB
Diff
66 lines
1.8 KiB
Diff
---
|
|
tests/test_functional.py | 5 ++++-
|
|
tests/test_unit.py | 15 +++++++--------
|
|
2 files changed, 11 insertions(+), 9 deletions(-)
|
|
|
|
--- a/tests/test_functional.py
|
|
+++ b/tests/test_functional.py
|
|
@@ -1,6 +1,9 @@
|
|
from time import sleep
|
|
|
|
-from mock.mock import patch, Mock
|
|
+try:
|
|
+ from unittest.mock import patch, Mock
|
|
+except (ImportError, ModuleNotFoundError):
|
|
+ from mock import patch, Mock
|
|
from pytest import raises
|
|
|
|
from circuitbreaker import CircuitBreaker, CircuitBreakerError, \
|
|
--- a/tests/test_unit.py
|
|
+++ b/tests/test_unit.py
|
|
@@ -1,9 +1,8 @@
|
|
try:
|
|
- from unittest.mock import Mock
|
|
-except ImportError:
|
|
- from mock import Mock
|
|
+ from unittest.mock import Mock, patch
|
|
+except (ImportError, ModuleNotFoundError):
|
|
+ from mock import Mock, patch
|
|
|
|
-from mock.mock import patch
|
|
from pytest import raises
|
|
|
|
from circuitbreaker import CircuitBreaker, CircuitBreakerError, circuit
|
|
@@ -50,7 +49,7 @@ def test_circuitbreaker_should_call_fall
|
|
func = Mock(return_value=False)
|
|
|
|
CircuitBreaker.opened = lambda self: True
|
|
-
|
|
+
|
|
cb = CircuitBreaker(name='WithFallback', fallback_function=fallback)
|
|
cb.call(func)
|
|
fallback.assert_called_once_with()
|
|
@@ -61,11 +60,11 @@ def test_circuitbreaker_should_not_call_
|
|
func = Mock(return_value=False)
|
|
|
|
CircuitBreaker.opened = lambda self: True
|
|
-
|
|
+
|
|
cb = CircuitBreaker(name='WithFallback', fallback_function=fallback)
|
|
assert cb.call(func) == fallback.return_value
|
|
assert not func.called
|
|
-
|
|
+
|
|
|
|
def mocked_function(*args, **kwargs):
|
|
pass
|
|
@@ -82,7 +81,7 @@ def test_circuitbreaker_call_fallback_fu
|
|
func_decorated('test2',test='test')
|
|
|
|
# check args and kwargs are getting correctly to fallback function
|
|
-
|
|
+
|
|
fallback.assert_called_once_with('test2', test='test')
|
|
|
|
@patch('circuitbreaker.CircuitBreaker.decorate')
|