Bug #900567 “Add matcher for length of a sequence” : Bugs : testtools (original) (raw)
Add matcher for length of a sequence
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.hpss_calls) < 34 and len(self.hpss_calls) > 47:
self.fail("Expected hpss_calls to have between 34 and 47 elements, got %d (%r)"
% (len(self.hpss_calls), self.hpss_calls))
It would be nice if there were a matcher for this, so that could be written like:
self.assertThat(
self.hpss_calls, Length(MatchesAny(LessThan(34), GreaterThan(47))))
(And so get the nice formatted errors etc for free.)