From ec49a057b588e1190c144c3bf667ab81a54c8c9e6e52a400a266fad084de02f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= Date: Wed, 6 Mar 2019 12:46:45 +0000 Subject: [PATCH] Accepting request 682097 from home:jayvdb:coala:python3-bears - Initial spec for v2.0.1 OBS-URL: https://build.opensuse.org/request/show/682097 OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-first?expand=0&rev=1 --- .gitattributes | 23 ++++++++++++++++++ .gitignore | 1 + first-2.0.1.tar.gz | 3 +++ python-first.changes | 4 ++++ python-first.spec | 57 ++++++++++++++++++++++++++++++++++++++++++++ test_first.py | 40 +++++++++++++++++++++++++++++++ 6 files changed, 128 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 first-2.0.1.tar.gz create mode 100644 python-first.changes create mode 100644 python-first.spec create mode 100644 test_first.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/first-2.0.1.tar.gz b/first-2.0.1.tar.gz new file mode 100644 index 0000000..703ae43 --- /dev/null +++ b/first-2.0.1.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3bb3de3582cb27071cfb514f00ed784dc444b7f96dc21e140de65fe00585c95e +size 5325 diff --git a/python-first.changes b/python-first.changes new file mode 100644 index 0000000..54542d9 --- /dev/null +++ b/python-first.changes @@ -0,0 +1,4 @@ +------------------------------------------------------------------- +Wed Mar 6 10:35:25 AM UTC 2019 - John Vandenberg + +- Initial spec for v2.0.1 diff --git a/python-first.spec b/python-first.spec new file mode 100644 index 0000000..2bf04a6 --- /dev/null +++ b/python-first.spec @@ -0,0 +1,57 @@ +# +# spec file for package python-first +# +# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. +# +# 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/ +# + + +%{?!python_module:%define python_module() python-%{**} python3-%{**}} +Name: python-first +Version: 2.0.1 +Release: 0 +Summary: Return the first true value of an iterable +License: MIT +Group: Development/Languages/Python +URL: http://github.com/hynek/first/ +Source: https://files.pythonhosted.org/packages/source/f/first/first-%{version}.tar.gz +Source1: https://raw.githubusercontent.com/hynek/first/master/test_first.py +BuildRequires: %{python_module setuptools} +BuildRequires: fdupes +BuildRequires: python-rpm-macros +BuildArch: noarch +%python_subpackages + +%description +Return the first true value of an iterable. + +%prep +%setup -q -n first-%{version} +cp %{SOURCE1} . + +%build +%python_build + +%install +%python_install +%python_expand %fdupes %{buildroot}%{$python_sitelib} + +%check +%python_expand PYTHONPATH=. $python test_first.py + +%files %{python_files} +%doc AUTHORS.rst README.rst +%license LICENSE +%{python_sitelib}/* + +%changelog diff --git a/test_first.py b/test_first.py new file mode 100644 index 0000000..ceac45e --- /dev/null +++ b/test_first.py @@ -0,0 +1,40 @@ +import unittest +from first import first + + +isbool = lambda x: isinstance(x, bool) +isint = lambda x: isinstance(x, int) +odd = lambda x: isint(x) and x % 2 != 0 +even = lambda x: isint(x) and x % 2 == 0 +is_meaning_of_life = lambda x: x == 42 + + +class TestFirst(unittest.TestCase): + def test_empty_iterables(self): + s = set() + l = [] + assert first(s) is None + assert first(l) is None + + def test_default_value(self): + s = set() + l = [] + assert first(s, default=42) == 42 + assert first(l, default=3.14) == 3.14 + + l = [0, False, []] + assert first(l, default=3.14) == 3.14 + + def test_selection(self): + l = [(), 0, False, 3, []] + + assert first(l, default=42) == 3 + assert first(l, key=isint) == 0 + assert first(l, key=isbool) is False + assert first(l, key=odd) == 3 + assert first(l, key=even) == 0 + assert first(l, key=is_meaning_of_life) is None + + +if __name__ == '__main__': + unittest.main()