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

Improvement test_client can accept instance object. #1083

Merged
merged 7 commits into from
Aug 16, 2016
Merged

Improvement test_client can accept instance object. #1083

merged 7 commits into from
Aug 16, 2016

Conversation

ppiyakk2
Copy link
Contributor

@ppiyakk2 ppiyakk2 commented Aug 15, 2016

What do these changes do?

Improvement test_client can accept instance object as parameter.

Are there changes in behavior for the user?

No

Related issue number

#1066

Checklist

  • [O] I think the code is well written
  • [O] Unit tests for the changes exist
  • [O] Documentation reflects the changes

@ppiyakk2 ppiyakk2 changed the title Improvement test_client that can accept instance object. Improvement test_client can accept instance object. Aug 15, 2016
@codecov-io
Copy link

codecov-io commented Aug 15, 2016

Current coverage is 97.64% (diff: 100%)

Merging #1083 into master will increase coverage by <.01%

@@             master      #1083   diff @@
==========================================
  Files            28         28          
  Lines          6397       6403     +6   
  Methods           0          0          
  Messages          0          0          
  Branches       1085       1086     +1   
==========================================
+ Hits           6246       6252     +6   
  Misses           79         79          
  Partials         72         72          

Powered by Codecov. Last update 1cf6c18...bc03bee

if not isinstance(app_factory, Application):
app = app_factory(loop, *args, **kwargs)
else:
app = app_factory
Copy link
Member

Choose a reason for hiding this comment

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

There must be assertion that app.loop is the same as used in test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It means that there must be assertion like this?

assert app.loop is loop

Copy link
Member

Choose a reason for hiding this comment

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

Yes!
Plus message like this "Application is attached to other event loop"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. Please check new commit.

Copy link
Member

Choose a reason for hiding this comment

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

Also please make sure that args and kwargs are both empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@asvetlov When I debug the test case, parameter as a create_app function also args and kwargs are both empty.

Copy link
Member

Choose a reason for hiding this comment

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

I mean

if isinstance(app_factory, Application):
    assert not args, "arg should be empty"
    assert not kwargs, "kwargs should be empty"
    ....

It will prevent cases like: yield from test_client(app, 1, 2, param=3).

@popravich
Copy link
Member

Looks good,
Can you also add a negative test -- passing to test_client application with wrong event loop
and checking assertion is raised

@ppiyakk2
Copy link
Contributor Author

@popravich How to check if assertion is raised? Just use try and except?

@popravich
Copy link
Member

with pytest.raises(AssertionError):
    test_client(web.Application(loop=fake_loop)

should work

@ppiyakk2
Copy link
Contributor Author

@popravich I added negative test case !

@@ -122,4 +131,4 @@ def make_app(loop):

""")
result = testdir.runpytest('-p', 'no:sugar')
result.assert_outcomes(passed=8, failed=1)
result.assert_outcomes(passed=8, failed=2)
Copy link
Member

Choose a reason for hiding this comment

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

But why is it failing? If it fails it means that assertion is not raised.

@asvetlov asvetlov merged commit b109fdf into aio-libs:master Aug 16, 2016
@asvetlov
Copy link
Member

Thanks!

@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants