File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed
Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -42,19 +42,25 @@ class BaseAutoMatcher[T](BaseMatcher, metaclass=AutoMatcherMeta):
4242 """Create matchers for classes. Use like so:
4343
4444 ```python
45- from hamcrest import assert_that, equal_to
45+ from hamcrest import assert_that
46+ from hamcrest.core.matcher import Matcher
47+ from pydantic import BaseModel
4648
47- class EligibilityStatus (BaseModel):
48- status : str
49+ class Status (BaseModel):
50+ status_code : str
4951 reason: str | None = None
52+ count: int
5053
51- class EligibilityStatusMatcher(BaseAutoMatcher[EligibilityStatus]): ...
52- def is_eligibility_status() -> Matcher[EligibilityStatus]: return EligibilityStatusMatcher()
54+ class StatusMatcher(BaseAutoMatcher[Status]): ...
5355
54- assert_that(EligibilityStatus(status="ACTIVE"), is_eligibility_status().with_status("ACTIVE").and_reason(None))
56+ def is_status() -> Matcher[Status]: return StatusMatcher()
57+
58+ actual = Status(status_code="ACTIVE", count=99)
59+ assert_that(actual, is_status().with_status_code("ACTIVE").and_reason(None))
60+ assert_that(actual, is_status().with_count(42)) # Will fail
5561 ```
5662
57- Works only for classes with `__annotations__`; manually annotated classes, dataclasses.dataclass and
63+ Works only for classes with `__annotations__`; typically manually annotated classes, dataclasses.dataclass and
5864 pydantic.BaseModel instances.
5965 """
6066
You can’t perform that action at this time.
0 commit comments