Add matcher for length of a sequence
Bug #900567 reported by
Andrew Bennetts
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
testtools |
Triaged
|
Wishlist
|
Unassigned |
Bug Description
bzrlib has a nice assertLength helper which helpfully shows the contents of the sequence if the length is not the expected value. But it's not a matcher, so for more complex cases tests resort to ad hoc assertions that look like:
if len(self.
% (len(self.
It would be nice if there were a matcher for this, so that could be written like:
self.
(And so get the nice formatted errors etc for free.)
Changed in testtools: | |
status: | New → Triaged |
importance: | Undecided → Wishlist |
tags: | added: matchers |
To post a comment you must log in.
On Tue, Dec 6, 2011 at 2:11 AM, Andrew Bennetts hpss_calls) < 34 and len(self. hpss_calls) > 47: hpss_calls) , self.hpss_calls)) MatchesAny( LessThan( 34), GreaterThan(47))))
<email address hidden> wrote:
> Public bug reported:
>
> bzrlib has a nice assertLength helper which helpfully shows the contents
> of the sequence if the length is not the expected value. But it's not a
> matcher, so for more complex cases tests resort to ad hoc assertions
> that look like:
>
> if len(self.
> self.fail("Expected hpss_calls to have between 34 and 47 elements, got %d (%r)"
> % (len(self.
>
> It would be nice if there were a matcher for this, so that could be
> written like:
>
> self.assertThat(
> self.hpss_calls, Length(
>
> (And so get the nice formatted errors etc for free.)
Cheapest way to do this:
Length = lambda matcher: AfterPreprocess ing(len, matcher)
jml