Merge lp:~rvb/testtools/testtools-contains-all into lp:~testtools-committers/testtools/trunk
| Status: | Merged |
|---|---|
| Merged at revision: | 261 |
| Proposed branch: | lp:~rvb/testtools/testtools-contains-all |
| Merge into: | lp:~testtools-committers/testtools/trunk |
| Diff against target: |
72 lines (+29/-1) 2 files modified
testtools/matchers.py (+11/-0) testtools/tests/test_matchers.py (+18/-1) |
| To merge this branch: | bzr merge lp:~rvb/testtools/testtools-contains-all |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Jonathan Lange | 2012-04-30 | Needs Fixing on 2012-04-30 | |
|
Review via email:
|
|||
Commit Message
New matcher ContainsAll.
Description of the Change
This branch adds a new (shortcut) matcher ContainsAll. ContainsAll(items) that can be used instead of using MatchesAll(
Drive-by fix: removed unused import.
| Raphaël Badin (rvb) wrote : | # |
> Thanks for the patch, Raphaël.
>
> I don't quite understand the matcher though. From the docstring and the name,
> I would have guess something like this::
>
> self.assertThat([1, 2, 3], ContainsAll([3, 1]))
>
> That is, self.assertThat(Y, ContainsAll(X)) would pass if and only if X is a
> subset of Y.
Indeed, that's precisely what this matcher does. Again, it's simply a shortcut, it uses existing functionality.
> As it is, self.assertThat(Y, ContainsAll(X)) passes iff for all y in Y, for
> all x in X, x in y. (i.e. ∀ y ∊ Y, ∀ x ∊ X, 'x in y')
Maybe I'm missing something but that's not what this matcher does. I can't resist using these nice utf8 characters:
self.assertThat(y, ContainsAll(X)) passes iff for all x in X, x in y. (i.e. ∀ x ∊ X, 'x in y')
| Jonathan Lange (jml) wrote : | # |
OK, so this does behave as like a subset matcher. Oops.
<jml> rvba: the problem was that I read this:
+ matches_matches = ['foobar', 'foozbar', 'bar foo']
as this:
+ matches_matches = [['foobar', 'foozbar', 'bar foo']]
Raphaël, could you please update the tests to not rely on string containment -- I think that would be clearer. e.g.
+ matches_matches = [['foo', 'bar'], ['foo', 'z', 'bar'], ['bar', 'foo']]
Also if you could add another sentence to the class docstring using the word 'subset' somewhere that'd be great.
jml
- 259. By Raphaël Badin on 2012-04-30
-
Refactor tests. Improve doc.
| Raphaël Badin (rvb) wrote : | # |
> Raphaël, could you please update the tests to not rely on string containment
> -- I think that would be clearer. e.g.
>
> + matches_matches = [['foo', 'bar'], ['foo', 'z', 'bar'], ['bar', 'foo']]
Sure, I've refactored matches_matches and matches_mismatches in TestContainsAll
> Also if you could add another sentence to the class docstring using the word
> 'subset' somewhere that'd be great.
Done. Feel free to suggest something else for the docstring if the one I put doesn't suit you.
| Raphaël Badin (rvb) wrote : | # |
Hi Jonathan,
If you think this is worth it, could you please have another look at this? I think I've made all the improvements you requested.
R.

Thanks for the patch, Raphaël.
I don't quite understand the matcher though. From the docstring and the name, I would have guess something like this::
self. assertThat( [1, 2, 3], ContainsAll([3, 1]))
That is, self.assertThat(Y, ContainsAll(X)) would pass if and only if X is a subset of Y.
As it is, self.assertThat(Y, ContainsAll(X)) passes iff for all y in Y, for all x in X, x in y. (i.e. ∀ y ∊ Y, ∀ x ∊ X, 'x in y')
So, to me, the name is confusing and my lazy imagination isn't leaping to actual use cases.
Where to from here?
* Demonstrate use cases
* Pick a better name, maybe EachContainsAll
Follow up work for testtools more generally:
* some kind of more generic helper might be interesting, e.g. *[matcher( item) for item in items], first_only=False)
lambda matcher, items: MatchesAll(
I don't really know what it ought to be called. Sorry.
* MatchesAll is really an "And"-style function. It would probably be better if its name reflected that.
* More generally, thinking a little bit more about predicate & set algebra might provide us with some better combinators
Thanks,
jml