-
-
Notifications
You must be signed in to change notification settings - Fork 933
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
test: add tests in test_routing
#2676
base: master
Are you sure you want to change the base?
Conversation
with pytest.raises(NoMatchFound): | ||
mixed_hosts_app.url_path_for("api", path="whatever", foo="bar") |
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.
Testing the circumstance where there are some remaining parameters and an exception is expected.
https://github.com/encode/starlette/blob/master/starlette/routing.py#L532
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 passed an extra parameter foo
in this case. This will make the if
statement become False
and jump to this line:
raise NoMatchFound(name, path_params)
This behavior was not tested and covered in the other tests before.
mounted = Router([Mount("/users", ok, name="users")]) | ||
with pytest.raises(NoMatchFound): | ||
mounted.url_path_for("users", path="/a", foo="bar") | ||
|
||
mounted = Router([Mount("/users", ok, name="users")]) | ||
with pytest.raises(NoMatchFound): | ||
mounted.url_path_for("users") |
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.
Testing the cases where the if conditions in these two logic blocks are not true.
https://github.com/encode/starlette/blob/master/starlette/routing.py#L456
https://github.com/encode/starlette/blob/master/starlette/routing.py#L458
test_routing
Can you explain me what behavior is being tested? |
I've provided the code lines above. According to the coverage report, those if statements are always True with the other tests. The tests I added check if the logic can correctly jump to another branch, which should raise an exception in these cases. |
Summary
Add tests for some of the uncovered branches in
starlette.routing
, related to this issueChecklist