Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit interfaces for matchers and mismatches #211

Closed
wants to merge 3 commits into from

Conversation

jml
Copy link
Member

@jml jml commented Feb 5, 2016

  • Adds IMatcher and IMismatch
  • Updates their documentation as well as that in assert_that,
    assertThat, and expectThat to refer to these
  • Changes MismatchDecorator to explicitly subclass IMismatch

Another take on #181. This time, just using Python.

While this patch is not a huge improvement in and of itself, I want to start doing this (explicit abstract types) for the rest of testtools. I think cumulatively it will make a great improvement to the code base. (Already the work on #178 has helped me clarify much). Matchers are an easy place to start because they are so close to this already.

Review on Reviewable

Describes the protocol that mismatches are required to implement.
"""

# XXX: jml would like to extend this interface to include the thing that
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I'm +1 on this - I frequently find myself writing a test that fails, then adding the matchee as the third parameter to the assertion so it gets printed out, then fixing the test and removing that third parameter. Annoying. I'm not sure if that should go in the matchers themselves, or in (assert|expect)That.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, interesting. I mostly want it for composition, e.g. to help with Not. ISTR wanting it for https://github.com/ClusterHQ/flocker/blob/master/flocker/testtools/matchers.py but looking at it, I can't see what was essential.

Whether we or not we extend the interface this way, I want second opinions on whether it should be done in this patch / this release.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rbtcollins Any thoughts on this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jml Just for extra clarity, does "include the thing that" mean "the matchee argument passed to match()"?

From a very quick look at the code it seems that implementations of IMatcher typically pass or could pass the matchee object to the constructor of an IMismatch, in order to have describe() take it into account.

Why do we need to pass it to describe()?

An example of the "composition" use case you allude to would be appreciated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does "include the thing that" mean "the matchee argument passed to match()"

Yes.

Why do we need to pass it to describe()?

Did I propose this?

An example of the "composition" use case you allude to would be appreciated.

Sorry, the intervening 13 months have somehow scrubbed it from my memory. However, looking at the file linked to in my comment provides just such an example. You'll have to figure out what it does, I'm afraid.

@thomir
Copy link
Member

thomir commented Feb 6, 2016

A few comments above. Probably worth getting @rbtcollins opinion as well, but I'm +1 anyway.

@jml
Copy link
Member Author

jml commented Feb 7, 2016

Thanks. I'll wait for @rbtcollins, because he had opinions about #181.


:param matchee: An object to match with ``matcher``.
:param IMatcher matcher: An object meeting the testtools.Matcher protocol.
:raises MismatchError: When ``matcher`` does not match ``matchee``.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spurious VWS

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@rbtcollins
Copy link
Member

This looks much saner to me.

jml added 3 commits March 7, 2016 18:18
* Adds `IMatcher` and `IMismatch`
* Updates their documentation as well as that in `assert_that`,
  `assertThat`, and `expectThat` to refer to these
* Changes `MismatchDecorator` to explicitly subclass `IMismatch`
@jml
Copy link
Member Author

jml commented Mar 7, 2016

Updated based on review comments. Need clarification on a couple of points before I land.

@jml
Copy link
Member Author

jml commented Jul 13, 2016

Don't want this on my Github dashboard. Others are free to re-submit if they'd like.

@freeekanayaka
Copy link
Member

freeekanayaka commented Mar 15, 2017 via email

@jml
Copy link
Member Author

jml commented Mar 15, 2017

A public mismatched attribute, as exemplified in the linked flocker/matchers.py.

Regrettably, this is my last update to this PR. I don't use Python at home and I don't use testtools at work, so I'm not going to make time to pursue this further.

@freeekanayaka
Copy link
Member

@jml thanks for the input

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants