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
Utility for providing a sequence of requests/responses to StubTreq #106
Conversation
…n be reverted in a future PR to add this functionality back in." This reverts commit 75b49b1.
Couple questions for the reviewer:
|
Current coverage is
|
1 similar comment
Current coverage is
|
Current coverage is
|
That's odd - why did codecov comment 3 times on the same commit? |
I like Hynek's suggestion, except for the fact that it gives the interfaces the wrong module name; they are relocated in the docs, but they So you might also want to set >>> from zope.interface import Interface
>>>
>>> class ISomething(Interface):
... pass
...
>>> ISomething
<InterfaceClass __main__.ISomething>
>>> __name__ = 'hello'
>>> class ISomething(Interface):
... pass
...
>>> ISomething
<InterfaceClass hello.ISomething> |
Clearly we should have a higher-level utility function. But we can add those later; I think that trying to block this on committing to something higher level would really slow down progress. |
I think that burdening the caller with performing this check themselves every time is indeed the wrong thing to do: anywhere you say "and then the caller must..." is an opportunity for a mistake to be made. What do you think of this, instead: require a You can pass the |
Explicit is better than implicit, so, "yes". |
Sorry, to be clear, when I said " |
…n the cleanup Thanks @glyph
… codecov, so add it to coverage run too.
So is this a bogus report? https://codecov.io/github/twisted/treq/treq/test/test_testing.py?ref=d5b7c708f9e7794b6964f8202a9b6cde39ad67e3#l-235 The tests pass, so it should have gone through everything in that loop - what coverage am I missing? |
Hey @hynek - crappy as coveralls has been, it at least has a coverage delta browser. Figuring out why codecov is unhappy with this code is really obscure, since it increases coverage. I'm inclined to put treq back on coveralls based on the experience in this PR. Is there some part of the UI that I'm missing? |
Apparently you can't use for loops in tests if we want branch coverage on the tests also? Is there any way we can get branch coverage on the source but line coverage on the tests themselves? |
I filed https://bitbucket.org/ned/coveragepy/issues/383/ to hopefully address one of the issues here. |
Treq never was on coveralls. If you have particular problems it might be worth to bring it upstream. @dstufft or @reaperhulk told me the devs are receptive (contrary to coveralls which appears to be abandonware) |
class IStringResponseStubs(Interface): | ||
""" | ||
An interface that :class:`StringStubbingResource` expects to provide it | ||
with a response based on what the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docstring cut off here
Personally I think the whole interface is overkill and it's unnecessary. It only has one method, so you can just instead take a function as an argument. |
@radix: Good point, thanks - it went through several iterations where it had maybe failure reporting, but you're right, as it stands there is no reason to have an interface. |
…elp with codecov, so add it to coverage run too." This reverts commit 3bd122c.
Python doesn't really have a way to describe the signature of a function that's expected except for |
@glyph Can we just describe it in the StringStubbingResource docstring? It's not like we do enforcement of the interface anyway. |
@cyli - Sure, if you like it better, I'm not going to be picky about it. The main thing that bothers me is that neither epytext nor ReST has a way to nest |
I hear @radix likes haskell, maybe he will port haskell to python so we can use the eminently readable notation |
…_for to __call__ - thanks @radix
…have it take failure reporters for now.
Note to reviewer: I plan on adding a utility like: @contextmanager
def stub_request_sequence(sequence, failure_reporter=None, assert_consumed=True):
"""
Convenience context manager that returns a stubbed treq. Once the context
exits, any async stubbing errors are reported. By default, also fails
if not all requests were consumed.
Usage::
with stub_request_sequence([]) as stubtreq:
stubtreq.get(...)
""" in the next PR, and the default failure reporter is to raise an |
@cyli - is the recent codecov result bogus? |
@glyph I think so? I've only edited two files in this PR: |
https://codecov.io/github/twisted/treq says 95.84%, so this result doesn't make sense. Why is it comparing to 96.25%? |
Hey @codecov-io - can you help us out with this? |
Can you make an empty commit ( |
@stevepeak Done |
@cyli thank you! The system was taking the project coverage from an incorrect reference point. I've fixed this issue. Posted a successful status for this build to reflect that. Thank you and I apologize for the issue. |
@stevepeak was this a systemic issue you've corrected? We've been seeing this on pyca/cryptography as well :) |
Thanks @stevepeak for the quick response and fix! |
@reaperhulk for a window of about 2 days I was tying a new technique for the Project status and fetching the previous commit's coverage because there was a root issue: the first commit on a new branch could not find its "previous" coverage. My attempt to fix this caused this issue. Furthermore I'm working on improving the Project status to have an option of not setting the "minimum" coverage, instead the status would simply be: Did it lower coverage at all? A success would be the coverage of this commit did not lower coverage. |
|
||
def __init__(self, get_response_for): | ||
""" | ||
:param get_response_for: A callable that takes 5 parameters: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than re-describing this parameter, I'd just say "See ``StringStubbingResource``.
", since the parameter is already described in detail there.
@cyli - modulo the documentation nitpicking, I am fairly happy with this. Address and land, please? |
|
||
sequence_stubs = RequestSequence([...]) | ||
stub_treq = StubTreq(StringStubbingResource(sequence_stubs)) | ||
with sequence_stubs.consume(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! This example is wrong. sequence_stubs.consume()
requires a sync_failure_reporter
and this doesn't pass one.
This PR is cursed. :| Some brokenness with travis and cryptography. |
Cryptography builds an empty wheel on pypy < 2.6 due to a too-old version of cffi; this wheel then gets cached on Travis making all other builds break. The next cryptography release will error out instead, thus only breaking the build on PyPy (Travis has a too-old version) rather than everywhere. Something will still need to be done about the PyPy builds, though. |
It's not just this PR. I think that all treq builds will start failing now; we need to figure this out just to un-block development. Frankly I think the solution might be to de-support PyPy for now, pending Travis adding a more recent version, or at least someone submitting a travis config that acquires a more recent one. |
Utility for providing a sequence of requests/responses to StubTreq
This was originally in #96, and removed to make review easier. This undoes that remove.
Part of addressing #27.
Again, planning on writing docs in another PR, as this PR is fairly large already and may get slightly larger depending on review comments.