Skip to main content

h-matchers

Test objects which pass equality checks with other objects

Usage

from h_matchers import Any
import re

assert [1, 2, ValueError(), print, print] == [
        Any(),
        Any.int(),
        Any.instance_of(ValueError),
        Any.function(),
        Any.callable()
    ]

assert ["easy", "string", "matching"] == [
        Any.string(),
        Any.string.containing("in"),
        Any.string.matching('^.*CHING!', re.IGNORECASE)
    ]

assert "http://www.example.com?a=3&b=2" == Any.url(
    host='www.example.com', query=Any.mapping.containing({'a': 3}))

assert 5 == Any.of([5, None])

assert "foo bar" == All.of([
    Any.string.containing('foo'),
    Any.string.containing('bar')
])

assert user == Any.object.of_type(MyUser).with_attrs({"name": "Username"})

assert "http://example.com/path" == Any.url.with_host("example.com")

assert prepared_request == (
    Any.request
    .with_url(Any.url.with_host("example.com"))
    .containing_headers({'Content-Type': 'application/json'})
)

# ... and lots more

For more details see:

Hacking

Installing h-matchers in a development environment

You will need

  • Git

  • pyenv Follow the instructions in the pyenv README to install it. The Homebrew method works best on macOS. On Ubuntu follow the Basic GitHub Checkout method.

Clone the git repo

git clone https://github.com/hypothesis/h-matchers.git

This will download the code into a h-matchers directory in your current working directory. You need to be in the h-matchers directory for the rest of the installation process:

cd h-matchers

Run the tests

make test

That's it! You’ve finished setting up your h-matchers development environment. Run make help to see all the commands that're available for linting, code formatting, packaging, etc.

Updating the Cookiecutter scaffolding

This project was created from the https://github.com/hypothesis/h-cookiecutter-pypackage/ template. If h-cookiecutter-pypackage itself has changed since this project was created, and you want to update this project with the latest changes, you can "replay" the cookiecutter over this project. Run:

make template

This will change the files in your working tree, applying the latest updates from the h-cookiecutter-pypackage template. Inspect and test the changes, do any fixups that are needed, and then commit them to git and send a pull request.

If you want make template to skip certain files, never changing them, add these files to "options.disable_replay" in .cookiecutter.json and commit that to git.

If you want make template to update a file that's listed in disable_replay simply delete that file and then run make template, it'll recreate the file for you.

Release files for h-matchers 1.2.11

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

Source distribution (sdist)

Source distribution for h-matchers 1.2.11
File Size Uploaded
h_matchers-1.2.11.tar.gz 19.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for h-matchers 1.2.11
File Interpreter ABI Platform
h_matchers-1.2.11-py3-none-any.whl Python 3 none any Details

Total release size: 44.4 kB

Release files / h_matchers-1.2.11.tar.gz

Download URL h_matchers-1.2.11.tar.gz
Size 19.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1488beb0529629735c454bced479a882409412ae2e8f44ce27716c0e4518b691
BLAKE2b-256 checksum
How to use checksums
c02fde6c61cce4c5ca71d7b5ccebc39e0edf6966fe462ff0ab0a87bd2b6aa794
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

Release files / h_matchers-1.2.11-py3-none-any.whl

Download URL h_matchers-1.2.11-py3-none-any.whl
Size 24.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3eb80ba7ea8553018a86e3a0b93a5af24395fa66674be89e6bd278ea2ab41345
BLAKE2b-256 checksum
How to use checksums
f8b2f5b555ddb940905956ef8796e6c3588f285014d4064f9019e7db5414bd8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5
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