hamcrest / PyHamcrest

Hamcrest matchers for Python
http://hamcrest.org/
Other
773 stars 112 forks source link

describe_to vs describe_mismatch vs describe_match #158

Closed dz0 closed 3 years ago

dz0 commented 3 years ago

in BaseMatcher there are:

in custom matcher example https://github.com/hamcrest/PyHamcrest#writing-custom-matchers there is

I'd expect the example to have sth like this

    ...
    day_as_string = [
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday",
        "Sunday",
    ]

    def describe_mismatch(self, description):
        description.append_text("calendar date falling on ").append_text(self.day_as_string[self.day])

    def describe_to(self, description):
        description.append_text("calendar date on ").append_text(self.day_as_string[self.day])
dz0 commented 3 years ago

ps.: py 3.6 allows f-string style -- which is less clumsy description.append_text(f"calendar date on {self.day_as_string[self.day]}")

brunns commented 3 years ago

I think the example in the readme is intentionally pretty minimal. The docs do extend to mentioning describe_mismatch() - see Writing Custom Matchers.

offbyone commented 3 years ago

The README is, per Simon's comment, intentionally minimal and doesn't try to capture the custom matcher authoring case in detail.

The f-string case is definitely a "we will get around to that at some point" change :)