Skip to main content

wonderpatch

https://img.shields.io/pypi/v/wonderpatch.svg

Better patch for test.

Usage

patch module method

import sys

from wonderpatch import wonder

with wonder(os).cpu_count.called_once(return_value=12345):
    assert os.cpu_count() == 12345

Use path is ok:

import sys

from wonderpatch import wonder

with wonder('os.cpu_count').called_once(return_value=12345):
    assert os.cpu_count() == 12345

patch object

from wonderpatch import wonder

class TestObject:

    def name(self):
        return self.__class__.__name__


with wonder(TestObject.name).called_once(return_value='x'):
    assert TestObject().name() == 'x'

It is also works for property:

from wonderpatch import wonder

class TestObject:

    @property
    def name(self):
        return self.__class__.__name__


with wonder(TestObject.name).called_once(return_value='x'):
    assert TestObject().name == 'x'

Multiple patch in one function

If you want to use multiple patches in one place, and do not want to write a verify long statement, use wonder.together:

from wonderpatch import wonder

with wonder.together():
    wonder(TestObject.name).called_once(return_value='x')
    wonder(TestObject.age).called_once(return_value='x')

    assert TestObject().name() == 'x'
    assert TestObject().age == 'x'

Or as a decorator:

from wonderpatch import wonder

@wonder.together
def test_name():
    wonder(TestObject.name).called_once(return_value='x')
    assert TestObject().name() == 'x'

the wonder api

  • wonder(…).then_return(value: Any)

    patch and set return value, works for called 0+ times

  • wonder(…).then_raise(exception)

    patch and set raise value, works for called 0+ times

  • wonder(…).called(times=None, min=1, max=None, return_value=_empty, side_effect=_empty, only_self=False)

    patch and set min or max times call, default is at least 1 time.

  • wonder(…).called_with(*args, **kwargs)

    patch and set called at least once with args, kwargs

  • wonder(…).called_once_with(*args, **kwargs)

    patch and set called once with args, kwargs

  • wonder(…).never_called()

    patch and set never called.

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Metadata

Release files for wonderpatch 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wonderpatch 0.1.0
File Size Uploaded Provenance Actions
wonderpatch-0.1.0.tar.gz 11.0 kB Without provenance Details for wonderpatch-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wonderpatch 0.1.0
File Interpreter ABI Platform Actions
wonderpatch-0.1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details for wonderpatch-0.1.0-py2.py3-none-any.whl

Total release size: 16.0 kB

Release files / wonderpatch-0.1.0.tar.gz

Download URL wonderpatch-0.1.0.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
500526b0ead500dd58165d784ecf799e0a2060dd8627a29eff02a19109ee594e
BLAKE2b-256 checksum
How to use checksums
1898b84076b61d8272c337006e48ab1f456c7f58402d20d61e2ca516d54e2aae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release files / wonderpatch-0.1.0-py2.py3-none-any.whl

Download URL wonderpatch-0.1.0-py2.py3-none-any.whl
Size 5.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
49cadd5095a0182769dbaf061cb7dd54a0a77da47df14b6737a5a9f4446495e0
BLAKE2b-256 checksum
How to use checksums
faaea5758353c9dccf87b00a32737123046d24e5ad2cbbdf2afc29d53c3c2e6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Security for wonderpatch 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page