Metadata-Version: 2.4
Name: hamcrest-proto
Version: 0.0.8
Summary: Hamcrest matchers for protobufs
Author: mdepinet
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Dist: protobuf>=3.20
Requires-Dist: pyhamcrest>=2.0.2
Requires-Python: >=3.9
Project-URL: Homepage, https://github.com/mdepinet/hamcrest-proto
Description-Content-Type: text/markdown

# hamcrest-proto

[Hamcrest](https://pypi.org/project/PyHamcrest/) matchers for [Protocol Buffers](https://protobuf.dev/) in Python.

This is forked from [proto-matcher](https://pypi.org/project/proto-matcher/) which was no longer receiving updates and which was itself based on [MessageDifferencer](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.util.message_differencer) and [EqualsProto](https://github.com/google/googletest/issues/1761) googletest matcher.

## API

This packages provides the following proto-related [matchers](https://pyhamcrest.readthedocs.io/en/latest/library.html):

### `equals_proto`

```python
equals_proto(expected: Message | str)
```
Test the argument equals the given protobuf message.

### `approximately`

```python
approximately(matcher: Matcher[Message],
              float_margin: float | None = None,
              float_fraction: float | None = None)
```
Test the argument equals the given protobuf message, while comparing any float field using approximation.

### `ignoring_field_paths`

```python
ignoring_field_paths(field_paths: set[tuple[str, ...]],
                     matcher: Matcher[Message])
```
Test the argument equals the given protobuf message, while ignoring those fields specified in the field paths.


### `ignoring_repeated_field_ordering`

```python
ignoring_repeated_field_ordering(matcher: Matcher[Message])
```
Test the argument equals the given protobuf message, ignoring the ordering of any repeated field.


### `partially`

```python
partially(matcher: Matcher[Message])
```
Test the argument partially equals the given protobuf message, i.e. if a field is in the argument but not in the expected message, it's ignored in the comparison.

## Development

This project uses [uv](https://docs.astral.sh/uv/) for dependency management and
[just](https://github.com/casey/just) as a command runner.

```sh
just install   # create the venv and generate the test protos
just           # format, run all checks (ruff, pyright, deptry), and test
```

See the `Justfile` for individual recipes.
