re-assert
show where your regex match assertion failed!
installation
pip install re-assert
usage
re-assert provides a helper class to make assertions of regexes simpler.
re_assert.Matches(pattern: str, *args, **kwargs)
construct a Matches object.
note: under the hood, re-assert uses the regex library for matching,
any *args / **kwargs that regex.compile supports will work. in general,
the regex library is 100% compatible with the re library (and will even
accept its flags, etc.)
re_assert.Matches.from_pattern(pattern: Pattern[str]) -> Matches
construct a Matches object from an already-compiled regex.
this is useful (for instance) if you're testing an existing compiled regex.
>>> import re
>>> reg = re.compile('foo')
>>> Matches.from_pattern(reg) == 'fork'
False
>>> Matches.from_pattern(reg) == 'food'
True
Matches.__eq__(other) (==)
the equality operator is overridden for use with assertion frameworks such as pytest
>>> pat = Matches('foo')
>>> pat == 'bar'
False
>>> pat == 'food'
True
Matches.__repr__() (repr(...))
a side-effect of an equality failure changes the repr(...) of a Matches
object. this allows for useful pytest assertion messages:
> assert Matches('foo') == 'fork'
E AssertionError: assert Matches('foo'...ork\n # ^ == 'fork'
E -Matches('foo')\n
E - # regex failed to match at:\n
E - #\n
E - #> fork\n
E - # ^
E +'fork'
Matches.assert_matches(s: str)
if you're using some other test framework, this method is useful for producing a readable traceback
>>> Matches('foo').assert_matches('food')
>>> Matches('foo').assert_matches('fork')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/asottile/workspace/re-assert/re_assert.py", line 63, in assert_matches
assert self == s, self._fail
AssertionError: regex failed to match at:
> fork
^
Metadata
Release files for re-assert 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| re_assert-1.1.0.tar.gz | 3.9 kB | Without provenance | Details for re_assert-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| re_assert-1.1.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for re_assert-1.1.0-py2.py3-none-any.whl |
Total release size: 7.9 kB
Release files / re_assert-1.1.0.tar.gz
| Download URL | re_assert-1.1.0.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5172dfbd2047a15dff2347735dea7e495479cc7e58841199a4a4973256b20464
|
|
BLAKE2b-256 checksum How to use checksums |
72895801de335fa7a9cd9f402f66680b14be076d2084dd8244e3a3136a743262
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9
|
Release files / re_assert-1.1.0-py2.py3-none-any.whl
| Download URL | re_assert-1.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
6b2902d5beac2a0e715eb0312fcb226ab4da21d1ea6953441734734b5b68cd48
|
|
BLAKE2b-256 checksum How to use checksums |
95b0e70a69ece48c3b6862a5ae6ca87e1e76ff2941447885550073eb280235fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9
|
Security for re-assert 1.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.