wish for invertible matchers

Bug #704219 reported by Martin Pool
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
testtools
Triaged
Wishlist
Unassigned

Bug Description

I can define ContainsRegexp(r'\d+') and match against it, and then also say Not(ContainsRegexp(r'\d+')) and this works. However, in the latter case, what I'd really like to get is something like

  "unexpectedly matched '\\d+' in 'route66' at '66'"

rather than just being told the matcher passed successfully.

I can just define NotContainsRegexp that has the same behavior but gives better mismatches. But I wonder if this should fall out in a cleaner way.

Tags: matchers
Jonathan Lange (jml)
Changed in testtools:
status: New → Triaged
importance: Undecided → Wishlist
Revision history for this message
Martin Pool (mbp) wrote : Re: [Bug 704219] Re: wish for invertible matchers

One idea on this:

Perhaps what I want is assertThat() to be a HOF that takes an
expression and evaluates it. If it evaluates to False, it will
display as much information is as is possible/useful about the
expression and its evaluation, so that we can understand the failure
without having to reproduce it or break into it with a debugger.

The problem with a crude Not that is simply given the evaluated value
of the inner expression is that it cannot say anything more about that
expression if it fails. However, if we instead printed the inner
expression including the variable bindings, then it would probably be
clear why there was a problem.

Revision history for this message
Robert Collins (lifeless) wrote :

Probably worth looking at what the java matchers do for this.

Jonathan Lange (jml)
tags: added: matchers
Revision history for this message
Jonathan Lange (jml) wrote :

FWIW, Hamcrest (Java) matchers append to a description, which might make this easier.

<http://www.google.com/codesearch#nmwoqoPm7yk/hamcrest-java/hamcrest-core/src/main/java/org/hamcrest/core/IsNot.java>

(Also, just discovered that there is a hamcrest Python port maintained by the hamcrest folk. Rather irritated by the news.)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.