userver: en/testsuite/compare.py Source File
Loading...
Searching...
No Matches
compare.py
1import dataclasses
2import typing
3
4
5class Reporter(typing.Protocol):
6 def __call__(self, msg: str, *, path: typing.Any) -> None:
7 pass
8
9
10@dataclasses.dataclass(kw_only=True)
12 """
13 Extension point for `pytest_register_compare_visitors`: lets a plugin
14 teach the `assertrepr_compare` machinery how to decompose a custom type
15 into something comparable (e.g. a nested dict/list/set), so that a
16 failing `==` assertion involving it gets a helpful diff.
17 """
18
19 class Predicate(typing.Protocol):
20 def __call__(self, left: typing.Any, right: typing.Any) -> bool:
21 pass
22
23 class Visitor(typing.Protocol):
24 def __call__(
25 self,
26 left: typing.Any,
27 right: typing.Any,
28 reporter: Reporter,
29 ) -> tuple[typing.Any, typing.Any]:
30 pass
31
32 predicate: Predicate
33 visit: Visitor