From 3168ea416a442911c28fc262773afdb1131e6af9366278aef5b62c220059c8bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mark=C3=A9ta=20Machov=C3=A1?= Date: Tue, 3 Jun 2025 12:09:56 +0000 Subject: [PATCH] - Convert to pip-based build OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-pretend?expand=0&rev=14 --- .gitattributes | 23 ++++++ .gitignore | 1 + pretend-1.0.9.tar.gz | 3 + python-pretend.changes | 42 ++++++++++ python-pretend.spec | 59 +++++++++++++ test_pretend.py | 184 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 312 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 pretend-1.0.9.tar.gz create mode 100644 python-pretend.changes create mode 100644 python-pretend.spec create mode 100644 test_pretend.py diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9b03811 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,23 @@ +## Default LFS +*.7z filter=lfs diff=lfs merge=lfs -text +*.bsp filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.gem filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.jar filter=lfs diff=lfs merge=lfs -text +*.lz filter=lfs diff=lfs merge=lfs -text +*.lzma filter=lfs diff=lfs merge=lfs -text +*.obscpio filter=lfs diff=lfs merge=lfs -text +*.oxt filter=lfs diff=lfs merge=lfs -text +*.pdf filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.rpm filter=lfs diff=lfs merge=lfs -text +*.tbz filter=lfs diff=lfs merge=lfs -text +*.tbz2 filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.ttf filter=lfs diff=lfs merge=lfs -text +*.txz filter=lfs diff=lfs merge=lfs -text +*.whl filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57affb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.osc diff --git a/pretend-1.0.9.tar.gz b/pretend-1.0.9.tar.gz new file mode 100644 index 0000000..acae45f --- /dev/null +++ b/pretend-1.0.9.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c90eb810cde8ebb06dafcb8796f9a95228ce796531bc806e794c2f4649aa1b10 +size 4848 diff --git a/python-pretend.changes b/python-pretend.changes new file mode 100644 index 0000000..21d92b6 --- /dev/null +++ b/python-pretend.changes @@ -0,0 +1,42 @@ +------------------------------------------------------------------- +Tue Jun 3 12:09:40 UTC 2025 - Markéta Machová + +- Convert to pip-based build + +------------------------------------------------------------------- +Fri Apr 21 12:29:41 UTC 2023 - Dirk Müller + +- add sle15_python_module_pythons (jsc#PED-68) + +------------------------------------------------------------------- +Thu Apr 13 22:43:10 UTC 2023 - Matej Cepl + +- Make calling of %{sle15modernpython} optional. + +------------------------------------------------------------------- +Mon Jan 31 00:39:16 UTC 2022 - Matej Cepl + +- Fix files list + +------------------------------------------------------------------- +Thu Feb 14 08:25:57 UTC 2019 - John Vandenberg + +- Activate test suite +- Update to v1.0.9 + * Make 'stub' object callable + * Build and doc enhancements + +------------------------------------------------------------------- +Tue Dec 4 12:51:39 UTC 2018 - Matej Cepl + +- Remove superfluous devel dependency for noarch package + +------------------------------------------------------------------- +Thu Mar 16 14:48:02 UTC 2017 - tbechtold@suse.com + +- Switch to singlespec approach + +------------------------------------------------------------------- +Mon Mar 31 14:59:55 UTC 2014 - speilicke@suse.com + +- Initial version for v1.0.8 diff --git a/python-pretend.spec b/python-pretend.spec new file mode 100644 index 0000000..1cefcad --- /dev/null +++ b/python-pretend.spec @@ -0,0 +1,59 @@ +# +# spec file for package python-pretend +# +# Copyright (c) 2025 SUSE LLC +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# + + +%{?sle15_python_module_pythons} +Name: python-pretend +Version: 1.0.9 +Release: 0 +Summary: A library for stubbing in Python +License: BSD-3-Clause +Group: Development/Languages/Python +URL: https://github.com/alex/pretend +Source: https://files.pythonhosted.org/packages/source/p/pretend/pretend-%{version}.tar.gz +Source1: https://raw.githubusercontent.com/alex/pretend/master/test_pretend.py +BuildRequires: %{python_module pip} +BuildRequires: %{python_module pytest} +BuildRequires: %{python_module setuptools} +BuildRequires: %{python_module wheel} +BuildRequires: python-rpm-macros +BuildArch: noarch +%python_subpackages + +%description +Pretend is a library to make stubbing with Python easier. + +%prep +%setup -q -n pretend-%{version} +cp %{SOURCE1} . + +%build +%pyproject_wheel + +%install +%pyproject_install + +%check +%pytest + +%files %{python_files} +%license LICENSE.rst +%doc README.rst +%{python_sitelib}/pretend* +%{python_sitelib}/__pycache__/* + +%changelog diff --git a/test_pretend.py b/test_pretend.py new file mode 100644 index 0000000..3e38622 --- /dev/null +++ b/test_pretend.py @@ -0,0 +1,184 @@ +import operator + +import pytest + +from pretend import stub, raiser, call, call_recorder, PY3K + + +class TestStub(object): + def test_attribute(self): + x = stub(attr=3) + assert hasattr(x, "attr") + assert x.attr == 3 + + def test_function(self): + x = stub(meth=lambda x, y: x + y) + assert x.meth(3, 4) == 7 + + def test_iter(self): + x = stub(__iter__=lambda: iter([1, 2, 3])) + iterator = iter(x) + assert next(iterator) == 1 + + @pytest.mark.skipif("not PY3K") + def test_next(self): + x = stub(__next__=lambda: 12) + assert next(x) == 12 + + def test_contains(self): + x = stub(__contains__=lambda other: True) + assert "hello world" in x + + @pytest.mark.skipif("PY3K") + def test_nonzero(self): + x = stub(__nonzero__=lambda: False) + assert not bool(x) + + @pytest.mark.skipif("not PY3K") + def test_bool(self): + x = stub(__bool__=lambda: False) + assert not bool(x) + + def test_len(self): + x = stub(__len__=lambda: 12) + assert len(x) == 12 + + @pytest.mark.parametrize(("func", "op"), [ + (operator.lt, "__lt__"), + (operator.le, "__le__"), + (operator.eq, "__eq__"), + (operator.ne, "__ne__"), + (operator.gt, "__gt__"), + (operator.ge, "__ge__"), + + (operator.add, "__add__"), + (operator.and_, "__and__"), + (divmod, "__divmod__"), + (operator.floordiv, "__floordiv__"), + (operator.lshift, "__lshift__"), + (operator.mod, "__mod__"), + (operator.mul, "__mul__"), + (operator.or_, "__or__"), + (operator.pow, "__pow__"), + (operator.rshift, "__rshift__"), + (operator.sub, "__sub__"), + (operator.truediv, "__truediv__"), + (operator.xor, "__xor__"), + ]) + def test_special_binops(self, func, op): + x = stub(**{ + op: lambda y: func(2, y) + }) + assert func(x, 4) == func(2, 4) + assert func(x, 2) == func(2, 2) + + @pytest.mark.skipif("PY3K") + def test_div(self): + x = stub( + __div__=lambda y: 4 + ) + assert x / 3 == 4 + + def test_missing_op_error(self): + x = stub() + with pytest.raises(TypeError): + x + 2 + + def test_subscript(self): + x = stub( + __getitem__=lambda idx: idx + ) + assert x[5] == 5 + assert x[1, 2] == (1, 2) + + def test_setitem(self): + d = {} + x = stub( + __setitem__=d.__setitem__ + ) + x[5] = 'a' + x['b'] = 6 + assert d == {5: 'a', 'b': 6} + + def test_delitem(self): + d = {5: 'a', 'b': 6} + x = stub( + __delitem__=d.__delitem__ + ) + del x['b'] + assert d == {5: 'a'} + + def test_context_manager(self): + should_reraise = True + x = stub( + __enter__=lambda: 3, + __exit__=lambda exc_type, exc_value, tb: should_reraise + ) + with x as value: + assert value == 3 + raise ValueError + should_reraise = False + with pytest.raises(ValueError): + with x as value: + assert value == 3 + raise ValueError + + def test_default_repr(self): + x = stub(a=10) + + assert repr(x) == "" + + def test_custom_repr(self): + x = stub(id=300, __repr__=lambda: '') + + assert x.id == 300 + assert repr(x) == '' + + def test_callable(self): + x = stub(__call__=lambda: 4) + + assert x() == 4 + + +class TestRaiser(object): + def test_call_raiser(self): + f = raiser(ValueError) + with pytest.raises(ValueError): + f() + + def test_call_raiser_exc_value(self): + exc = ValueError(14) + f = raiser(exc) + with pytest.raises(ValueError) as exc_info: + f() + assert exc_info.value is exc + + def test_non_exc_raiser(self): + with pytest.raises(TypeError): + raiser("test") + + +class TestCallRecorder(object): + def test_call_eq(self): + assert call(a=2) == call(a=2) + assert not (call(a=2) != call(a=2)) + assert call(a=2) != call(a=3) + assert not (call(a=2) == call(a=3)) + + assert call() != [] + + def test_call_repr(self): + assert repr(call(1, 2, a=3)) == "" + assert repr(call(a=2)) == "" + + def test_call_hash(self): + c1 = call(a=2) + c2 = call(a=2) + assert hash(c1) == hash(c2) + + def test_simple(self): + f = call_recorder(lambda *args, **kwargs: 3) + assert f() == 3 + assert f.calls == [ + call() + ]