[packages/python-oslotest] - new; patched not to require mock for python3
qboosh
qboosh at pld-linux.org
Fri Feb 23 19:31:34 CET 2024
commit 9771c0822e09acb7949d7dd6797d34156db5abe8
Author: Jakub Bogusz <qboosh at pld-linux.org>
Date: Fri Feb 23 19:11:27 2024 +0100
- new; patched not to require mock for python3
oslotest-mock.patch | 101 +++++++++++++++++++++++++++++
python-oslotest.spec | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 279 insertions(+)
---
diff --git a/python-oslotest.spec b/python-oslotest.spec
new file mode 100644
index 0000000..90767dc
--- /dev/null
+++ b/python-oslotest.spec
@@ -0,0 +1,178 @@
+#
+# Conditional build:
+%bcond_without doc # Sphinx documentation
+%bcond_without tests # unit tests
+%bcond_without python2 # CPython 2.x module
+%bcond_without python3 # CPython 3.x module
+
+Summary: Oslo test framework
+Summary(pl.UTF-8): Szkielet testów Oslo
+Name: python-oslotest
+# keep 3.x here for python2 support
+Version: 3.9.0
+Release: 1
+License: Apache v2.0
+Group: Libraries/Python
+#Source0Download: https://pypi.org/simple/oslotest/
+Source0: https://files.pythonhosted.org/packages/source/o/oslotest/oslotest-%{version}.tar.gz
+# Source0-md5: b32b2287080f9ff75ba4b20ca68c4c59
+Patch0: oslotest-mock.patch
+URL: https://pypi.org/project/oslotest/
+%if %{with python2}
+BuildRequires: python-modules >= 1:2.7
+BuildRequires: python-pbr >= 2.0.0
+BuildRequires: python-setuptools
+%if %{with tests}
+BuildRequires: python-debtcollector >= 1.2.0
+BuildRequires: python-fixtures >= 3.0.0
+BuildRequires: python-mock >= 2.0.0
+BuildRequires: python-mox3 >= 0.20.0
+BuildRequires: python-os-client-config >= 1.28.0
+BuildRequires: python-six >= 1.10.0
+BuildRequires: python-stestr >= 2.0.0
+BuildRequires: python-subunit >= 1.0.0
+BuildRequires: python-testtools >= 2.2.0
+%endif
+%endif
+%if %{with python3}
+BuildRequires: python3-modules >= 1:3.6
+BuildRequires: python3-pbr >= 2.0.0
+BuildRequires: python3-setuptools
+%if %{with tests}
+BuildRequires: python3-debtcollector >= 1.2.0
+BuildRequires: python3-fixtures >= 3.0.0
+BuildRequires: python3-mox3 >= 0.20.0
+BuildRequires: python3-os-client-config >= 1.28.0
+BuildRequires: python3-six >= 1.10.0
+BuildRequires: python3-stestr >= 2.0.0
+BuildRequires: python3-subunit >= 1.0.0
+BuildRequires: python3-testtools >= 2.2.0
+%endif
+%endif
+BuildRequires: rpm-pythonprov
+BuildRequires: rpmbuild(macros) >= 1.714
+%if %{with doc}
+BuildRequires: python3-openstackdocstheme >= 1.18.1
+BuildRequires: python3-reno >= 2.5.0
+BuildRequires: sphinx-pdg-2 >= 1.7.0
+%endif
+Requires: python-modules >= 1:2.7
+BuildArch: noarch
+BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
+
+%description
+The Oslo Test framework provides common fixtures, support for
+debugging, and better support for mocking results.
+
+%description -l pl.UTF-8
+Szkielet testów Oslo dostarcza wspólne wyposażenie, obsługę śledzenia
+oraz lepsze wsparcie atrap wyników.
+
+%package -n python3-oslotest
+Summary: Oslo test framework
+Summary(pl.UTF-8): Szkielet testów Oslo
+Group: Libraries/Python
+Requires: python3-modules >= 1:3.6
+
+%description -n python3-oslotest
+The Oslo Test framework provides common fixtures, support for
+debugging, and better support for mocking results.
+
+%description -n python3-oslotest -l pl.UTF-8
+Szkielet testów Oslo dostarcza wspólne wyposażenie, obsługę śledzenia
+oraz lepsze wsparcie atrap wyników.
+
+%package apidocs
+Summary: API documentation for Python oslotest module
+Summary(pl.UTF-8): Dokumentacja API modułu Pythona oslotest
+Group: Documentation
+
+%description apidocs
+API documentation for Python oslotest module.
+
+%description apidocs -l pl.UTF-8
+Dokumentacja API modułu Pythona oslotest.
+
+%prep
+%setup -q -n oslotest-%{version}
+%patch0 -p1
+
+%build
+%if %{with python2}
+%py_build
+
+%if %{with tests}
+stestr-2 run
+%endif
+%endif
+
+%if %{with python3}
+%py3_build
+
+%if %{with tests}
+stestr-3 run
+%endif
+%endif
+
+%if %{with doc}
+sphinx-build-2 -b html doc/source doc/build/html
+%endif
+
+%install
+rm -rf $RPM_BUILD_ROOT
+
+%if %{with python2}
+%py_install
+
+%py_postclean
+%{__rm} -r $RPM_BUILD_ROOT%{py_sitescriptdir}/oslotest/tests
+
+for f in oslo_debug_helper oslo_run_cross_tests oslo_run_pre_release_tests ; do
+ %{__mv} $RPM_BUILD_ROOT%{_bindir}/$f $RPM_BUILD_ROOT%{_bindir}/${f}-2
+done
+%endif
+
+%if %{with python3}
+%py3_install
+
+%{__rm} -r $RPM_BUILD_ROOT%{py3_sitescriptdir}/oslotest/tests
+
+for f in oslo_debug_helper oslo_run_cross_tests oslo_run_pre_release_tests ; do
+ %{__mv} $RPM_BUILD_ROOT%{_bindir}/$f $RPM_BUILD_ROOT%{_bindir}/${f}-3
+ ln -sf $f-3 $RPM_BUILD_ROOT%{_bindir}/${f}
+done
+%endif
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%if %{with python2}
+%files
+%defattr(644,root,root,755)
+%doc AUTHORS ChangeLog README.rst
+%attr(755,root,root) %{_bindir}/oslo_debug_helper-2
+%attr(755,root,root) %{_bindir}/oslo_run_cross_tests-2
+%attr(755,root,root) %{_bindir}/oslo_run_pre_release_tests-2
+%{py_sitescriptdir}/oslotest
+%{py_sitescriptdir}/oslotest-%{version}-py*.egg-info
+%endif
+
+%if %{with python3}
+%files -n python3-oslotest
+%defattr(644,root,root,755)
+%doc AUTHORS ChangeLog README.rst
+%attr(755,root,root) %{_bindir}/oslo_debug_helper
+%attr(755,root,root) %{_bindir}/oslo_debug_helper-3
+%attr(755,root,root) %{_bindir}/oslo_run_cross_tests
+%attr(755,root,root) %{_bindir}/oslo_run_cross_tests-3
+%attr(755,root,root) %{_bindir}/oslo_run_pre_release_tests
+%attr(755,root,root) %{_bindir}/oslo_run_pre_release_tests-3
+%{py3_sitescriptdir}/oslotest
+%{py3_sitescriptdir}/oslotest-%{version}-py*.egg-info
+%endif
+
+%if %{with doc}
+%files apidocs
+%defattr(644,root,root,755)
+%doc doc/build/html/{_static,contributor,install,reference,user,*.html,*.js}
+%endif
diff --git a/oslotest-mock.patch b/oslotest-mock.patch
new file mode 100644
index 0000000..bf872d5
--- /dev/null
+++ b/oslotest-mock.patch
@@ -0,0 +1,101 @@
+--- oslotest-3.9.0/oslotest/mock_fixture.py.orig 2020-01-06 11:29:37.000000000 +0100
++++ oslotest-3.9.0/oslotest/mock_fixture.py 2024-02-22 21:36:47.580748811 +0100
+@@ -17,7 +17,14 @@
+ import functools
+
+ import fixtures
+-import mock
++try:
++ from unittest import mock
++ mock_module = mock
++ mock_module_name = 'unittest.mock'
++except ImportError:
++ import mock
++ mock_module = mock.mock
++ mock_module_name = 'mock'
+
+
+ def _lazy_autospec_method(mocked_method, original_method, eat_self):
+@@ -77,7 +77,7 @@ class _AutospecMockMixin(object):
+ original_attr = getattr(original_spec, name)
+ if callable(original_attr):
+ # lazily autospec callable attribute.
+- eat_self = mock.mock._must_skip(original_spec, name,
++ eat_self = mock_module._must_skip(original_spec, name,
+ isinstance(original_spec, type))
+
+ _lazy_autospec_method(attr, original_attr, eat_self)
+@@ -115,15 +115,17 @@ class MockAutospecFixture(fixtures.Fixtu
+ super(MockAutospecFixture, self).setUp()
+
+ # patch both external and internal usage of Mock / MagicMock.
+- self.useFixture(fixtures.MonkeyPatch('mock.Mock', _AutospecMock))
+- self.useFixture(fixtures.MonkeyPatch('mock.mock.Mock', _AutospecMock))
+- self.useFixture(fixtures.MonkeyPatch('mock.MagicMock',
+- _AutospecMagicMock))
+- self.useFixture(fixtures.MonkeyPatch('mock.mock.MagicMock',
+- _AutospecMagicMock))
++ self.useFixture(fixtures.MonkeyPatch(mock_module_name+'.Mock', _AutospecMock))
++ if mock_module_name == 'mock':
++ self.useFixture(fixtures.MonkeyPatch('mock.mock.Mock', _AutospecMock))
++ self.useFixture(fixtures.MonkeyPatch(mock_module_name+'.MagicMock',
++ _AutospecMagicMock))
++ if mock_module_name == 'mock':
++ self.useFixture(fixtures.MonkeyPatch('mock.mock.MagicMock',
++ _AutospecMagicMock))
+
+
+-class _patch(mock.mock._patch):
++class _patch(mock_module._patch):
+ """Patch class with working autospec functionality.
+
+ Currently, mock.patch functionality doesn't handle the autospec parameter
+@@ -164,7 +164,7 @@ class _patch(mock_module._patch):
+ if autospec:
+ target = self.getter()
+ original_attr = getattr(target, self.attribute)
+- eat_self = mock.mock._must_skip(target, self.attribute,
++ eat_self = mock_module._must_skip(target, self.attribute,
+ isinstance(target, type))
+
+ new = super(_patch, self).__enter__()
+@@ -189,11 +191,11 @@ def _safe_attribute_error_wrapper(func):
+
+ def patch_mock_module():
+ """Replaces the mock.patch class."""
+- mock.mock._patch = _patch
++ mock_module._patch = _patch
+
+ # NOTE(claudiub): mock cannot autospec partial functions properly,
+ # especially those created by LazyLoader objects (scheduler client),
+ # as it will try to copy the partial function's __name__ (which they do
+ # not have).
+- mock.mock._copy_func_details = _safe_attribute_error_wrapper(
+- mock.mock._copy_func_details)
++ mock_module._copy_func_details = _safe_attribute_error_wrapper(
++ mock_module._copy_func_details)
+--- oslotest-3.9.0/oslotest/tests/unit/test_mock_fixture.py.orig 2020-01-06 11:29:37.000000000 +0100
++++ oslotest-3.9.0/oslotest/tests/unit/test_mock_fixture.py 2024-02-22 21:17:21.007068683 +0100
+@@ -13,7 +13,10 @@
+ # License for the specific language governing permissions and limitations
+ # under the License.
+
+-import mock
++try:
++ from unittest import mock
++except ImportError:
++ import mock
+ import testtools
+
+ from oslotest import mock_fixture
+--- oslotest-3.9.0/requirements.txt.orig 2020-01-06 11:29:37.000000000 +0100
++++ oslotest-3.9.0/requirements.txt 2024-02-23 19:09:47.790460765 +0100
+@@ -7,7 +7,7 @@ python-subunit>=1.0.0 # Apache-2.0/BSD
+ six>=1.10.0 # MIT
+ stestr>=2.0.0 # Apache-2.0
+ testtools>=2.2.0 # MIT
+-mock>=2.0.0 # BSD
++mock>=2.0.0;python_version<'3.2' # BSD
+ mox3>=0.20.0 # Apache-2.0
+ os-client-config>=1.28.0 # Apache-2.0
+ debtcollector>=1.2.0 # Apache-2.0
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/python-oslotest.git/commitdiff/9771c0822e09acb7949d7dd6797d34156db5abe8
More information about the pld-cvs-commit
mailing list