← Back to team overview

testtools-dev team mailing list archive

Re: Questioning matchers

 

Some concrete suggestions:

   1. Give MatchesPredicateWithParams a better name and more examples
   2. Rewrite testtools matchers in terms of MatchesPredicateWithParams
   3. Create a helper that can be applied to simple functions to turn them
   into matchers, e.g.

def equals(matchee, expected):
    if not expected == observed:
        return '{} != {}'.format(expected, matchee)

Equals = simple_matcher(equals)
assert_that(2, Equals(4))

def path_exists(matchee):
    if not os.path.exists(matchee):
        return '{} does not exist'.format(matchee)

PathExists = simple_matcher(path_exists)
assert_that('/', PathExists())

   - The matchee (i.e. the parameter to `match`) would always be the first
   argument.
   - Returned strings would be converted into Mismatch objects
   - Possibly Mismatch objects could be returned too
   - `simple_matcher` could theoretically be used as a decorator, if you
   could stomach the way it changes signatures


On Sat, 7 Nov 2015 at 13:48 Jonathan Lange <jml@xxxxxxxxx> wrote:

> Hello all,
>
> While I *really* like matchers, I've got some niggling doubts about them.
> Basically, I wonder if they could be easier to define and easier to compose.
>
> I've written up my thoughts, half-formed as they are, at
> https://gist.github.com/jml/96480de504578e1dd783. I'd appreciate feedback.
>
> If they stay more-or-less as they are now, then that's also fine by me.
>
> cheers,
> jml
>

References