Merge lp://qastaging/~lifeless/testtools/haslength into lp://qastaging/~testtools-committers/testtools/trunk

Proposed by Robert Collins
Status: Merged
Merged at revision: 312
Proposed branch: lp://qastaging/~lifeless/testtools/haslength
Merge into: lp://qastaging/~testtools-committers/testtools/trunk
Diff against target: 305 lines (+178/-1)
7 files modified
NEWS (+6/-0)
doc/for-test-authors.rst (+37/-0)
testtools/matchers/__init__.py (+4/-0)
testtools/matchers/_basic.py (+12/-1)
testtools/matchers/_higherorder.py (+76/-0)
testtools/tests/matchers/test_basic.py (+16/-0)
testtools/tests/matchers/test_higherorder.py (+27/-0)
To merge this branch: bzr merge lp://qastaging/~lifeless/testtools/haslength
Reviewer Review Type Date Requested Status
Vincent Ladeuil Approve
testtools committers Pending
Review via email: mp+144578@code.qastaging.launchpad.net

Description of the change

I keep wanting a HasLength. And MatchesWithPredicate can't do it well. So, new helper to do it well, and an implementation.

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

Nice, I was searching for the moral equivalent of bzr's assertLength and couldn't find it last week ;)

25 +HasLength
26 +~~~~~~~~~
27 +
28 +Check the length of a collection. For example::
29 +
30 + self.assertThat([1, 2, 3], HasLength(2))

I can see this assertion will fail but stating so in the text would be
clearer IMHO. The other examples in this file I've looked at are of the
form: "Matches if <...>: <example>"

160 + HasLength = MatchesPredicate(
161 + lambda x, y: len(x) == y, 'len({0}) is not {1}')
162 + self.assertThat([1, 2], HasLength(3))

Same here ?

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

Thanks for the review Vincent, I'll try to get back and improve the docs.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches