15
0

- Add packaging of GitHub URL tarball and make tests running.

OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-circuitbreaker?expand=0&rev=2
This commit is contained in:
2021-10-26 14:08:18 +00:00
committed by Git OBS Bridge
parent bba6d1ab7c
commit 3726f6bd98
4 changed files with 83 additions and 5 deletions

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1b2d01cd5d02ddb248e1e4d34c1e9d4ee8ebef1d0b8e648b514c936a90df4f7d
size 6032
oid sha256:d8e9adb8395b105b0eada4ba50459935b8857b60599d39ab63b859167f8e3754
size 7126

View File

@@ -1,3 +1,8 @@
-------------------------------------------------------------------
Tue Oct 26 14:07:30 UTC 2021 - Matej Cepl <mcepl@suse.com>
- Add packaging of GitHub URL tarball and make tests running.
-------------------------------------------------------------------
Tue Oct 26 09:54:13 UTC 2021 - John Paul Adrian Glaubitz <adrian.glaubitz@suse.com>

View File

@@ -17,16 +17,21 @@
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
%define modname circuitbreaker
Name: python-circuitbreaker
Version: 1.3.1
Release: 0
Summary: Python implementation of the "Circuit Breaker" Pattern
License: BSD-3-Clause
URL: https://github.com/fabfuel/circuitbreaker
Source: https://files.pythonhosted.org/packages/source/c/circuitbreaker/circuitbreaker-%{version}.tar.gz
BuildRequires: python-rpm-macros
Source: https://github.com/fabfuel/%{modname}/archive/refs/tags/%{version}.tar.gz#/%{modname}-%{version}.tar.gz
# PATCH-FIX-UPSTREAM use_stdlib_mock.patch bugno mcepl@suse.com
# Don't depend on the external mock
Patch0: use_stdlib_mock.patch
BuildRequires: %{python_module pytest}
BuildRequires: %{python_module setuptools}
BuildRequires: fdupes
BuildRequires: python-rpm-macros
Suggests: python-typing
BuildArch: noarch
%python_subpackages
@@ -35,7 +40,7 @@ BuildArch: noarch
Python implementation of the "Circuit Breaker" Pattern
%prep
%setup -q -n circuitbreaker-%{version}
%autosetup -p1 -n circuitbreaker-%{version}
%build
%python_build
@@ -44,6 +49,9 @@ Python implementation of the "Circuit Breaker" Pattern
%python_install
%python_expand %fdupes %{buildroot}%{$python_sitelib}
%check
%pytest
%files %{python_files}
%doc README.rst
%license LICENSE.rst

65
use_stdlib_mock.patch Normal file
View File

@@ -0,0 +1,65 @@
---
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')