diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python-assertionlib.spec | 636 | ||||
-rw-r--r-- | sources | 1 |
3 files changed, 638 insertions, 0 deletions
@@ -0,0 +1 @@ +/AssertionLib-3.2.2.tar.gz diff --git a/python-assertionlib.spec b/python-assertionlib.spec new file mode 100644 index 0000000..7953cdb --- /dev/null +++ b/python-assertionlib.spec @@ -0,0 +1,636 @@ +%global _empty_manifest_terminate_build 0 +Name: python-AssertionLib +Version: 3.2.2 +Release: 1 +Summary: A package for performing assertions and providing informative exception messages. +License: Apache Software License +URL: https://github.com/nlesc-nano/AssertionLib +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/3d/73/fda51a469c141c8c70e4d664167198e12320d5d277072b27d6652d887232/AssertionLib-3.2.2.tar.gz +BuildArch: noarch + +Requires: python3-Nano-Utils +Requires: python3-Nano-Utils +Requires: python3-sphinx +Requires: python3-sphinx-rtd-theme +Requires: python3-numpy +Requires: python3-pandas +Requires: python3-pytest +Requires: python3-pytest-cov +Requires: python3-sphinx +Requires: python3-sphinx-rtd-theme +Requires: python3-pytest +Requires: python3-pytest-cov + +%description +.. image:: https://readthedocs.org/projects/assertionlib/badge/?version=latest + :target: https://assertionlib.readthedocs.io/en/latest/ +.. image:: https://badge.fury.io/py/AssertionLib.svg + :target: https://badge.fury.io/py/AssertionLib +.. image:: https://github.com/nlesc-nano/AssertionLib/workflows/Python%20package/badge.svg + :target: https://github.com/nlesc-nano/AssertionLib/actions +.. image:: https://codecov.io/gh/nlesc-nano/AssertionLib/branch/master/graph/badge.svg + :target: https://codecov.io/gh/nlesc-nano/AssertionLib +.. image:: https://zenodo.org/badge/214183943.svg + :target: https://zenodo.org/badge/latestdoi/214183943 + +| + +.. image:: https://img.shields.io/badge/python-3.6-blue.svg + :target: https://docs.python.org/3.6/ +.. image:: https://img.shields.io/badge/python-3.7-blue.svg + :target: https://docs.python.org/3.7/ +.. image:: https://img.shields.io/badge/python-3.8-blue.svg + :target: https://docs.python.org/3.8/ +.. image:: https://img.shields.io/badge/python-3.9-blue.svg + :target: https://docs.python.org/3.9/ +.. image:: https://img.shields.io/badge/python-3.10-blue.svg + :target: https://docs.python.org/3.10/ +.. image:: https://img.shields.io/badge/python-3.11-blue.svg + :target: https://docs.python.org/3.11/ + +############ +AssertionLib +############ +A package for performing assertions and providing informative exception messages. + + +Installation +************ +* PyPi: ``pip install AssertionLib`` +* GitHub: ``pip install git+https://github.com/nlesc-nano/AssertionLib`` + + +Usage +***** +A comprehensive overview of all available assertion methods is +provided in the documentation_. +A few examples of some basic assertion: + +.. code:: python + + >>> import numpy as np + >>> from assertionlib import assertion + + # Assert the output of specific callables + >>> assertion.eq(5, 5) # 5 == 5 + >>> assertion.lt(5, 6) # 5 < 6 + >>> assertion.gt(6, 5) # 5 > 6 + >>> assertion.isinstance(5, int) + >>> assertion.hasattr(5, '__init__') + >>> assertion.any([False, False, True]) + >>> assertion.isfinite(1.0) + + # Simply assert a value + >>> assertion(5 == 5) + >>> assertion(isinstance(5, int)) + + # Apply post-processing before conducting the assertion + >>> ar_large = np.ones(10) + >>> ar_small = np.zeros(10) + >>> assertion.gt(ar_large, ar_small, post_process=np.all) # all(ar_large > ar_small) + + # Perform an assertion which will raise an AssertionError + >>> assertion.eq(5, 6, message='Fancy custom error message') # 5 == 6 + Traceback (most recent call last): + ... + AssertionError: output = eq(a, b); assert output + + exception: AssertionError = AssertionError('Fancy custom error message') + + output: bool = False + a: int = 5 + b: int = 6 + +A few examples of AssertionErrors raised due to incorrect method signatures: + +.. code:: python + + >>> from assertionlib import assertion + + >>> assertion.len(5) + Traceback (most recent call last): + ... + AssertionError: output = len(obj); assert output + + exception: TypeError = TypeError("object of type 'int' has no len()") + + output: NoneType = None + obj: int = 5 + + +.. code:: python + + >>> from assertionlib import assertion + + >>> assertion.eq(5, 5, 5, 5) + Traceback (most recent call last): + ... + AssertionError: output = eq(a, b, _a, _b); assert output + + exception: TypeError = TypeError('eq expected 2 arguments, got 4') + + output: NoneType = None + a: int = 5 + b: int = 5 + _a: int = 5 + _b: int = 5 + +A demonstration of the ``exception`` parameter. +Providing an exception type will assert that the provided exception is raised +during/before the assertion process: + +.. code:: python + + >>> from assertionlib import assertion + + >>> len(5) + Traceback (most recent call last): + ... + TypeError: object of type 'int' has no len() + + +.. code:: python + + >>> from assertionlib import assertion + + >>> assertion.len(5, exception=TypeError) # i.e. len(5) should raise a TypeError + >>> assertion.len([5], exception=TypeError) + Traceback (most recent call last): + ... + AssertionError: output = len(obj); assert output + + exception: AssertionError = AssertionError("Failed to raise 'TypeError'") + + output: int = 1 + obj: list = [5] + +Lastly, the output of custom callables can be asserted in one of the following two ways, +supplying the callable to ``AssertionManager.assert()`` or creating a custom assertion +method and adding it to an instance with ``AssertionManager.add_to_instance()``: + +.. code:: python + + >>> from assertionlib import assertion + + >>> def my_fancy_func(a: object) -> bool: + ... return False + + # Approach #1, supply to-be asserted callable to assertion.assert_() + >>> assertion.assert_(my_fancy_func, 5) + Traceback (most recent call last): + ... + AssertionError: output = my_fancy_func(a); assert output + + exception: AssertionError = AssertionError(None) + + output: bool = False + a: int = 5 + + +.. code:: python + + >>> from assertionlib import assertion + + # Approach #2, permanantly add a new bound method using assertion.add_to_instance() + >>> assertion.add_to_instance(my_fancy_func) + >>> assertion.my_fancy_func(5) + Traceback (most recent call last): + ... + AssertionError: output = my_fancy_func(a); assert output + + exception: AssertionError = AssertionError(None) + + output: bool = False + a: int = 5 + +.. _documentation: https://assertionlib.readthedocs.io/en/latest/3_assertionmanager.html + + + + +%package -n python3-AssertionLib +Summary: A package for performing assertions and providing informative exception messages. +Provides: python-AssertionLib +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-AssertionLib +.. image:: https://readthedocs.org/projects/assertionlib/badge/?version=latest + :target: https://assertionlib.readthedocs.io/en/latest/ +.. image:: https://badge.fury.io/py/AssertionLib.svg + :target: https://badge.fury.io/py/AssertionLib +.. image:: https://github.com/nlesc-nano/AssertionLib/workflows/Python%20package/badge.svg + :target: https://github.com/nlesc-nano/AssertionLib/actions +.. image:: https://codecov.io/gh/nlesc-nano/AssertionLib/branch/master/graph/badge.svg + :target: https://codecov.io/gh/nlesc-nano/AssertionLib +.. image:: https://zenodo.org/badge/214183943.svg + :target: https://zenodo.org/badge/latestdoi/214183943 + +| + +.. image:: https://img.shields.io/badge/python-3.6-blue.svg + :target: https://docs.python.org/3.6/ +.. image:: https://img.shields.io/badge/python-3.7-blue.svg + :target: https://docs.python.org/3.7/ +.. image:: https://img.shields.io/badge/python-3.8-blue.svg + :target: https://docs.python.org/3.8/ +.. image:: https://img.shields.io/badge/python-3.9-blue.svg + :target: https://docs.python.org/3.9/ +.. image:: https://img.shields.io/badge/python-3.10-blue.svg + :target: https://docs.python.org/3.10/ +.. image:: https://img.shields.io/badge/python-3.11-blue.svg + :target: https://docs.python.org/3.11/ + +############ +AssertionLib +############ +A package for performing assertions and providing informative exception messages. + + +Installation +************ +* PyPi: ``pip install AssertionLib`` +* GitHub: ``pip install git+https://github.com/nlesc-nano/AssertionLib`` + + +Usage +***** +A comprehensive overview of all available assertion methods is +provided in the documentation_. +A few examples of some basic assertion: + +.. code:: python + + >>> import numpy as np + >>> from assertionlib import assertion + + # Assert the output of specific callables + >>> assertion.eq(5, 5) # 5 == 5 + >>> assertion.lt(5, 6) # 5 < 6 + >>> assertion.gt(6, 5) # 5 > 6 + >>> assertion.isinstance(5, int) + >>> assertion.hasattr(5, '__init__') + >>> assertion.any([False, False, True]) + >>> assertion.isfinite(1.0) + + # Simply assert a value + >>> assertion(5 == 5) + >>> assertion(isinstance(5, int)) + + # Apply post-processing before conducting the assertion + >>> ar_large = np.ones(10) + >>> ar_small = np.zeros(10) + >>> assertion.gt(ar_large, ar_small, post_process=np.all) # all(ar_large > ar_small) + + # Perform an assertion which will raise an AssertionError + >>> assertion.eq(5, 6, message='Fancy custom error message') # 5 == 6 + Traceback (most recent call last): + ... + AssertionError: output = eq(a, b); assert output + + exception: AssertionError = AssertionError('Fancy custom error message') + + output: bool = False + a: int = 5 + b: int = 6 + +A few examples of AssertionErrors raised due to incorrect method signatures: + +.. code:: python + + >>> from assertionlib import assertion + + >>> assertion.len(5) + Traceback (most recent call last): + ... + AssertionError: output = len(obj); assert output + + exception: TypeError = TypeError("object of type 'int' has no len()") + + output: NoneType = None + obj: int = 5 + + +.. code:: python + + >>> from assertionlib import assertion + + >>> assertion.eq(5, 5, 5, 5) + Traceback (most recent call last): + ... + AssertionError: output = eq(a, b, _a, _b); assert output + + exception: TypeError = TypeError('eq expected 2 arguments, got 4') + + output: NoneType = None + a: int = 5 + b: int = 5 + _a: int = 5 + _b: int = 5 + +A demonstration of the ``exception`` parameter. +Providing an exception type will assert that the provided exception is raised +during/before the assertion process: + +.. code:: python + + >>> from assertionlib import assertion + + >>> len(5) + Traceback (most recent call last): + ... + TypeError: object of type 'int' has no len() + + +.. code:: python + + >>> from assertionlib import assertion + + >>> assertion.len(5, exception=TypeError) # i.e. len(5) should raise a TypeError + >>> assertion.len([5], exception=TypeError) + Traceback (most recent call last): + ... + AssertionError: output = len(obj); assert output + + exception: AssertionError = AssertionError("Failed to raise 'TypeError'") + + output: int = 1 + obj: list = [5] + +Lastly, the output of custom callables can be asserted in one of the following two ways, +supplying the callable to ``AssertionManager.assert()`` or creating a custom assertion +method and adding it to an instance with ``AssertionManager.add_to_instance()``: + +.. code:: python + + >>> from assertionlib import assertion + + >>> def my_fancy_func(a: object) -> bool: + ... return False + + # Approach #1, supply to-be asserted callable to assertion.assert_() + >>> assertion.assert_(my_fancy_func, 5) + Traceback (most recent call last): + ... + AssertionError: output = my_fancy_func(a); assert output + + exception: AssertionError = AssertionError(None) + + output: bool = False + a: int = 5 + + +.. code:: python + + >>> from assertionlib import assertion + + # Approach #2, permanantly add a new bound method using assertion.add_to_instance() + >>> assertion.add_to_instance(my_fancy_func) + >>> assertion.my_fancy_func(5) + Traceback (most recent call last): + ... + AssertionError: output = my_fancy_func(a); assert output + + exception: AssertionError = AssertionError(None) + + output: bool = False + a: int = 5 + +.. _documentation: https://assertionlib.readthedocs.io/en/latest/3_assertionmanager.html + + + + +%package help +Summary: Development documents and examples for AssertionLib +Provides: python3-AssertionLib-doc +%description help +.. image:: https://readthedocs.org/projects/assertionlib/badge/?version=latest + :target: https://assertionlib.readthedocs.io/en/latest/ +.. image:: https://badge.fury.io/py/AssertionLib.svg + :target: https://badge.fury.io/py/AssertionLib +.. image:: https://github.com/nlesc-nano/AssertionLib/workflows/Python%20package/badge.svg + :target: https://github.com/nlesc-nano/AssertionLib/actions +.. image:: https://codecov.io/gh/nlesc-nano/AssertionLib/branch/master/graph/badge.svg + :target: https://codecov.io/gh/nlesc-nano/AssertionLib +.. image:: https://zenodo.org/badge/214183943.svg + :target: https://zenodo.org/badge/latestdoi/214183943 + +| + +.. image:: https://img.shields.io/badge/python-3.6-blue.svg + :target: https://docs.python.org/3.6/ +.. image:: https://img.shields.io/badge/python-3.7-blue.svg + :target: https://docs.python.org/3.7/ +.. image:: https://img.shields.io/badge/python-3.8-blue.svg + :target: https://docs.python.org/3.8/ +.. image:: https://img.shields.io/badge/python-3.9-blue.svg + :target: https://docs.python.org/3.9/ +.. image:: https://img.shields.io/badge/python-3.10-blue.svg + :target: https://docs.python.org/3.10/ +.. image:: https://img.shields.io/badge/python-3.11-blue.svg + :target: https://docs.python.org/3.11/ + +############ +AssertionLib +############ +A package for performing assertions and providing informative exception messages. + + +Installation +************ +* PyPi: ``pip install AssertionLib`` +* GitHub: ``pip install git+https://github.com/nlesc-nano/AssertionLib`` + + +Usage +***** +A comprehensive overview of all available assertion methods is +provided in the documentation_. +A few examples of some basic assertion: + +.. code:: python + + >>> import numpy as np + >>> from assertionlib import assertion + + # Assert the output of specific callables + >>> assertion.eq(5, 5) # 5 == 5 + >>> assertion.lt(5, 6) # 5 < 6 + >>> assertion.gt(6, 5) # 5 > 6 + >>> assertion.isinstance(5, int) + >>> assertion.hasattr(5, '__init__') + >>> assertion.any([False, False, True]) + >>> assertion.isfinite(1.0) + + # Simply assert a value + >>> assertion(5 == 5) + >>> assertion(isinstance(5, int)) + + # Apply post-processing before conducting the assertion + >>> ar_large = np.ones(10) + >>> ar_small = np.zeros(10) + >>> assertion.gt(ar_large, ar_small, post_process=np.all) # all(ar_large > ar_small) + + # Perform an assertion which will raise an AssertionError + >>> assertion.eq(5, 6, message='Fancy custom error message') # 5 == 6 + Traceback (most recent call last): + ... + AssertionError: output = eq(a, b); assert output + + exception: AssertionError = AssertionError('Fancy custom error message') + + output: bool = False + a: int = 5 + b: int = 6 + +A few examples of AssertionErrors raised due to incorrect method signatures: + +.. code:: python + + >>> from assertionlib import assertion + + >>> assertion.len(5) + Traceback (most recent call last): + ... + AssertionError: output = len(obj); assert output + + exception: TypeError = TypeError("object of type 'int' has no len()") + + output: NoneType = None + obj: int = 5 + + +.. code:: python + + >>> from assertionlib import assertion + + >>> assertion.eq(5, 5, 5, 5) + Traceback (most recent call last): + ... + AssertionError: output = eq(a, b, _a, _b); assert output + + exception: TypeError = TypeError('eq expected 2 arguments, got 4') + + output: NoneType = None + a: int = 5 + b: int = 5 + _a: int = 5 + _b: int = 5 + +A demonstration of the ``exception`` parameter. +Providing an exception type will assert that the provided exception is raised +during/before the assertion process: + +.. code:: python + + >>> from assertionlib import assertion + + >>> len(5) + Traceback (most recent call last): + ... + TypeError: object of type 'int' has no len() + + +.. code:: python + + >>> from assertionlib import assertion + + >>> assertion.len(5, exception=TypeError) # i.e. len(5) should raise a TypeError + >>> assertion.len([5], exception=TypeError) + Traceback (most recent call last): + ... + AssertionError: output = len(obj); assert output + + exception: AssertionError = AssertionError("Failed to raise 'TypeError'") + + output: int = 1 + obj: list = [5] + +Lastly, the output of custom callables can be asserted in one of the following two ways, +supplying the callable to ``AssertionManager.assert()`` or creating a custom assertion +method and adding it to an instance with ``AssertionManager.add_to_instance()``: + +.. code:: python + + >>> from assertionlib import assertion + + >>> def my_fancy_func(a: object) -> bool: + ... return False + + # Approach #1, supply to-be asserted callable to assertion.assert_() + >>> assertion.assert_(my_fancy_func, 5) + Traceback (most recent call last): + ... + AssertionError: output = my_fancy_func(a); assert output + + exception: AssertionError = AssertionError(None) + + output: bool = False + a: int = 5 + + +.. code:: python + + >>> from assertionlib import assertion + + # Approach #2, permanantly add a new bound method using assertion.add_to_instance() + >>> assertion.add_to_instance(my_fancy_func) + >>> assertion.my_fancy_func(5) + Traceback (most recent call last): + ... + AssertionError: output = my_fancy_func(a); assert output + + exception: AssertionError = AssertionError(None) + + output: bool = False + a: int = 5 + +.. _documentation: https://assertionlib.readthedocs.io/en/latest/3_assertionmanager.html + + + + +%prep +%autosetup -n AssertionLib-3.2.2 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-AssertionLib -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Fri May 05 2023 Python_Bot <Python_Bot@openeuler.org> - 3.2.2-1 +- Package Spec generated @@ -0,0 +1 @@ +e1e26169a8ca493ffa257392ce5d5741 AssertionLib-3.2.2.tar.gz |