Skip to main content

No project description provided

Project description

argmatch

This project is a fork of callee.

Argument matchers for unittest.mock

Version Development Status Python Versions License Build Status

More robust tests

Python's mocking library (or its backport for Python <3.3) is simple, reliable, and easy to use. But it is also a little lacking when it comes to asserting what calls a mock has received.

You can be either very specific::

my_mock.assert_called_once_with(42, some_foo_object, 'certain string')

or extremely general::

my_mock.assert_called_with(ANY, ANY, ANY)
# passes as long as argument count is the same

| The former can make your tests over-specified, and thus fragile. | The latter could make them too broad, missing some erroneous cases and possibly letting your code fail in production.


argmatch provides argument matchers that allow you to be exactly as precise as you want::

my_mock.assert_called_with(GreaterThan(0), InstanceOf(Foo), String())

without tedious, handcrafted, and poorly readable code that checks call_args or call_args_list::

self.assertGreater(mock.call_args[0][0], 0)
self.assertIsInstance(mock.call_args[0][1], Foo)
self.assertIsInstance(mock.call_args[0][2], str)

It has plenty of matcher types to fit all common and uncommon needs, and you can easily write your own if necessary.

Installation


Installing *argmatch* is easy with pip::

    $ pip install argmatch

| *argmatch* support goes all the way back to Python 2.6.
| It also works both with the ``unittest.mock`` module from Python 3.3+ or its backport.


API reference

See the documentation_ for complete reference on the library usage and all available matchers.

.. _documentation: http://argmatch.readthedocs.org

Contributing


Contributions are welcome!
If you need ideas, head to the issue tracker or search for the various ``TODO``\ s scattered around the codebase.
Or just think what matchers you'd like to add :)

After cloning the repository, this should get you up and running::

    # ... create virtualenv as necessary ...
    pip install -r requirements-dev.txt
    tox

To regenerate documentation and display it in the browser, simply run::

    inv docs

Happy hacking!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

argmatch-1.0.2.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

argmatch-1.0.2-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

Details for the file argmatch-1.0.2.tar.gz.

File metadata

  • Download URL: argmatch-1.0.2.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for argmatch-1.0.2.tar.gz
Algorithm Hash digest
SHA256 bff5a4bbce0c81ccd70bb319bbb195dfafbb7551d58b8003ea3391c0d13f0c3f
MD5 b69f29c20efd7d1d7ea727d7c301713a
BLAKE2b-256 904102e1d0678f03b57aec4a686583decc51253ed2ac9a5952f040a832cae414

See more details on using hashes here.

Provenance

The following attestation bundles were made for argmatch-1.0.2.tar.gz:

Publisher: python-package.yml on mdgilene/argmatch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file argmatch-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: argmatch-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for argmatch-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 431698818d9fa303391e0257996565579fac0ff22fa01291ab87e24afa0427a0
MD5 7eaece73ec5d2284758b21908783cff3
BLAKE2b-256 2a1cb3ed5b326e50bf0c306816f389921c71be9d9ad24f4ee8d8ffedca91c205

See more details on using hashes here.

Provenance

The following attestation bundles were made for argmatch-1.0.2-py3-none-any.whl:

Publisher: python-package.yml on mdgilene/argmatch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page