{"id":15009394,"url":"https://github.com/nlesc-nano/assertionlib","last_synced_at":"2026-03-06T23:32:22.817Z","repository":{"id":36246105,"uuid":"214183943","full_name":"nlesc-nano/AssertionLib","owner":"nlesc-nano","description":"A package for performing assertions and providing informative exception messages.","archived":false,"fork":false,"pushed_at":"2024-02-05T14:49:51.000Z","size":279,"stargazers_count":1,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T19:23:13.379Z","etag":null,"topics":["assertion","assertion-library","assertions","python-3","python-3-6","python-3-7","python-3-8","python-3-9","testing","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nlesc-nano.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.rst","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-10T13:00:23.000Z","updated_at":"2021-12-10T16:39:15.000Z","dependencies_parsed_at":"2024-10-12T09:21:37.092Z","dependency_job_id":"b088703f-4ddf-4687-9ba0-633a3ee6b098","html_url":"https://github.com/nlesc-nano/AssertionLib","commit_stats":{"total_commits":200,"total_committers":4,"mean_commits":50.0,"dds":0.26,"last_synced_commit":"1e5873836d894ff6fa1850f2042e0b8b5eddc6f0"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlesc-nano%2FAssertionLib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlesc-nano%2FAssertionLib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlesc-nano%2FAssertionLib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlesc-nano%2FAssertionLib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nlesc-nano","download_url":"https://codeload.github.com/nlesc-nano/AssertionLib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248075515,"owners_count":21043601,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assertion","assertion-library","assertions","python-3","python-3-6","python-3-7","python-3-8","python-3-9","testing","unit-testing"],"created_at":"2024-09-24T19:24:52.479Z","updated_at":"2026-03-06T23:32:22.766Z","avatar_url":"https://github.com/nlesc-nano.png","language":"Python","readme":".. image:: https://readthedocs.org/projects/assertionlib/badge/?version=latest\n    :target: https://assertionlib.readthedocs.io/en/latest/\n.. image:: https://badge.fury.io/py/AssertionLib.svg\n    :target: https://badge.fury.io/py/AssertionLib\n.. image:: https://github.com/nlesc-nano/AssertionLib/workflows/Python%20package/badge.svg\n    :target: https://github.com/nlesc-nano/AssertionLib/actions\n.. image:: https://codecov.io/gh/nlesc-nano/AssertionLib/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/nlesc-nano/AssertionLib\n.. image:: https://zenodo.org/badge/214183943.svg\n    :target: https://zenodo.org/badge/latestdoi/214183943\n\n|\n\n.. image:: https://img.shields.io/badge/python-3.6-blue.svg\n    :target: https://docs.python.org/3.6/\n.. image:: https://img.shields.io/badge/python-3.7-blue.svg\n    :target: https://docs.python.org/3.7/\n.. image:: https://img.shields.io/badge/python-3.8-blue.svg\n    :target: https://docs.python.org/3.8/\n.. image:: https://img.shields.io/badge/python-3.9-blue.svg\n    :target: https://docs.python.org/3.9/\n.. image:: https://img.shields.io/badge/python-3.10-blue.svg\n    :target: https://docs.python.org/3.10/\n.. image:: https://img.shields.io/badge/python-3.11-blue.svg\n    :target: https://docs.python.org/3.11/\n\n############\nAssertionLib\n############\nA package for performing assertions and providing informative exception messages.\n\n\nInstallation\n************\n* PyPi: ``pip install AssertionLib``\n* GitHub: ``pip install git+https://github.com/nlesc-nano/AssertionLib``\n\n\nUsage\n*****\nA comprehensive overview of all available assertion methods is\nprovided in the documentation_.\nA few examples of some basic assertion:\n\n.. code:: python\n\n    \u003e\u003e\u003e import numpy as np\n    \u003e\u003e\u003e from assertionlib import assertion\n\n    # Assert the output of specific callables\n    \u003e\u003e\u003e assertion.eq(5, 5)  # 5 == 5\n    \u003e\u003e\u003e assertion.lt(5, 6)  # 5 \u003c 6\n    \u003e\u003e\u003e assertion.gt(6, 5)  # 5 \u003e 6\n    \u003e\u003e\u003e assertion.isinstance(5, int)\n    \u003e\u003e\u003e assertion.hasattr(5, '__init__')\n    \u003e\u003e\u003e assertion.any([False, False, True])\n    \u003e\u003e\u003e assertion.isfinite(1.0)\n\n    # Simply assert a value\n    \u003e\u003e\u003e assertion(5 == 5)\n    \u003e\u003e\u003e assertion(isinstance(5, int))\n\n    # Apply post-processing before conducting the assertion\n    \u003e\u003e\u003e ar_large = np.ones(10)\n    \u003e\u003e\u003e ar_small = np.zeros(10)\n    \u003e\u003e\u003e assertion.gt(ar_large, ar_small, post_process=np.all)  # all(ar_large \u003e ar_small)\n\n    # Perform an assertion which will raise an AssertionError\n    \u003e\u003e\u003e assertion.eq(5, 6, message='Fancy custom error message')  # 5 == 6\n    Traceback (most recent call last):\n      ...\n    AssertionError: output = eq(a, b); assert output\n\n    exception: AssertionError = AssertionError('Fancy custom error message')\n\n    output: bool = False\n    a: int = 5\n    b: int = 6\n\nA few examples of AssertionErrors raised due to incorrect method signatures:\n\n.. code:: python\n\n    \u003e\u003e\u003e from assertionlib import assertion\n\n    \u003e\u003e\u003e assertion.len(5)\n    Traceback (most recent call last):\n      ...\n    AssertionError: output = len(obj); assert output\n\n    exception: TypeError = TypeError(\"object of type 'int' has no len()\")\n\n    output: NoneType = None\n    obj: int = 5\n\n\n.. code:: python\n\n    \u003e\u003e\u003e from assertionlib import assertion\n\n    \u003e\u003e\u003e assertion.eq(5, 5, 5, 5)\n    Traceback (most recent call last):\n      ...\n    AssertionError: output = eq(a, b, _a, _b); assert output\n\n    exception: TypeError = TypeError('eq expected 2 arguments, got 4')\n\n    output: NoneType = None\n    a: int = 5\n    b: int = 5\n    _a: int = 5\n    _b: int = 5\n\nA demonstration of the ``exception`` parameter.\nProviding an exception type will assert that the provided exception is raised\nduring/before the assertion process:\n\n.. code:: python\n\n    \u003e\u003e\u003e from assertionlib import assertion\n\n    \u003e\u003e\u003e len(5)\n    Traceback (most recent call last):\n      ...\n    TypeError: object of type 'int' has no len()\n\n\n.. code:: python\n\n    \u003e\u003e\u003e from assertionlib import assertion\n\n    \u003e\u003e\u003e assertion.len(5, exception=TypeError)  # i.e. len(5) should raise a TypeError\n    \u003e\u003e\u003e assertion.len([5], exception=TypeError)\n    Traceback (most recent call last):\n      ...\n    AssertionError: output = len(obj); assert output\n\n    exception: AssertionError = AssertionError(\"Failed to raise 'TypeError'\")\n\n    output: int = 1\n    obj: list = [5]\n\nLastly, the output of custom callables can be asserted in one of the following two ways,\nsupplying the callable to ``AssertionManager.assert()`` or creating a custom assertion\nmethod and adding it to an instance with ``AssertionManager.add_to_instance()``:\n\n.. code:: python\n\n    \u003e\u003e\u003e from assertionlib import assertion\n\n    \u003e\u003e\u003e def my_fancy_func(a: object) -\u003e bool:\n    ...     return False\n\n    # Approach #1, supply to-be asserted callable to assertion.assert_()\n    \u003e\u003e\u003e assertion.assert_(my_fancy_func, 5)\n    Traceback (most recent call last):\n      ...\n    AssertionError: output = my_fancy_func(a); assert output\n\n    exception: AssertionError = AssertionError(None)\n\n    output: bool = False\n    a: int = 5\n\n\n.. code:: python\n\n    \u003e\u003e\u003e from assertionlib import assertion\n\n    # Approach #2, permanantly add a new bound method using assertion.add_to_instance()\n    \u003e\u003e\u003e assertion.add_to_instance(my_fancy_func)\n    \u003e\u003e\u003e assertion.my_fancy_func(5)\n    Traceback (most recent call last):\n      ...\n    AssertionError: output = my_fancy_func(a); assert output\n\n    exception: AssertionError = AssertionError(None)\n\n    output: bool = False\n    a: int = 5\n\n.. _documentation: https://assertionlib.readthedocs.io/en/latest/3_assertionmanager.html\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnlesc-nano%2Fassertionlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnlesc-nano%2Fassertionlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnlesc-nano%2Fassertionlib/lists"}