-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Added get_client and get_server methods to AioHTTPTestCase #2074
Conversation
ac9b865
to
202e3f6
Compare
Codecov Report
@@ Coverage Diff @@
## master #2074 +/- ##
==========================================
- Coverage 97.08% 97.04% -0.04%
==========================================
Files 38 38
Lines 7689 7692 +3
Branches 1344 1342 -2
==========================================
Hits 7465 7465
- Misses 102 103 +1
- Partials 122 124 +2
Continue to review full report at Codecov.
|
I'm ok with adding |
I think you're right.... My point is mostly for the unittest's TestCase where it makes much more sense and also makes the code simple (if you compare the TestClient class before and after, it's clearly just easier). But I completely ignored the test_ methods. I'm giving it another try. |
You proposal for Hmm. We could change |
Yes that's what I just realized. I need to make the tests in test_test_utils.py files more elegant but it's getting closer. |
Actually no I can't make it look better because the purpose of the I just made the passing of argument loop more explicit. @asvetlov do you think this PR looks much better now? |
This change is needed if we want a clear distinction in the unittest.TestCase between "app" (the application) and "server" the actual test server. This will also allow a developer to override these methods to use their own TestServer and TestClient.
if isinstance(__param, Application): | ||
server = TestServer(__param, loop=loop, **server_kwargs) | ||
client = TestClient(server, loop=loop, **kwargs) | ||
elif isinstance(__param, BaseTestServer): |
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.
I dropped here the duplicated test on TestServer and RawTestServer. The argument to TestClient must now be a BaseTestServer instance which includes both. Maybe someone would want to make a TestServer not based on TestServer but on BaseTestServer. That also reflects better the first argument of TestClient.
if isinstance(__param, collections.Callable) and \ | ||
not isinstance(__param, (Application, BaseTestServer)): | ||
__param = __param(loop, *args, **kwargs) | ||
kwargs = {} |
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.
This reproduces the exact behavior than before but a little more strict:
- __param must be a callable, in the previous code it was the "else" case
- kwargs is reset just after because we don't want them to be passed to the client or server (identical than before)
- by extension, the result of the callable must be an instance of Application or BaseTestServer or it would complain explicitly about it
I just added setUpAsync and tearDownAsync. They are very useful in development because you don't need to write synchronous methods for the setUp and tearDown anymore, you can simply override those. (If you want I have made tests cases for those in particular, it instantiate the test case in a test and check that both functions executed.) That was my last change for this PR, thanks for your time. |
@asvetlov this is ready for your review. |
Thanks! |
This change is needed if we want a clear distinction in the
unittest.TestCase between "app" (the application) and "server" the
actual test server. This will also allow a developer to override these
methods to use their own TestServer and TestClient.
What do these changes do?
_get_client()
of AioHTTPTestCase to a public method (inviting the developer to override it)get_server()
to AioHTTPTestCase that will, by default, instantiate the default TestServerapp_or_server
toserver
onlyAre there changes in behavior for the user?
get_application
.get_application
must only return an Application instance.get_server
.get_client
method because it is now a public method (you always could but... now it's more obvious that you actually should)._get_client
has change of name.Related issue number
#2032
Checklist
CONTRIBUTORS.txt
changes
folder<issue_id>.<type>
for example (588.bug)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.