-
Notifications
You must be signed in to change notification settings - Fork 12
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
Exact URL Matching. Allow Syntactically Correct Patterns. Better Tests #25
base: master
Are you sure you want to change the base?
Changes from 18 commits
c9b3e26
445f146
02f531a
91c94b1
045d5d8
d875572
a4496bb
2cd8a88
a391633
c425491
00dacef
869dfc1
8c82184
9dc4627
6c86b57
dc7ab99
5e1bb33
c92945d
be8c654
3b17bfc
cfcb323
2e91ce2
fe210f3
c0b4552
8115f32
078ac25
2c7be81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,15 +56,15 @@ def test_url_for(plugin): | |
|
||
|
||
def test_url_for_kwargs(plugin): | ||
f = lambda a, b: None | ||
plugin.route("/foo/<a>/<b>")(f) | ||
assert plugin.url_for(f, a=1, b=2) == plugin.base_url + "/foo/1/2" | ||
f = lambda a, b2: None | ||
plugin.route("/foo/<a>/<b2>")(f) | ||
assert plugin.url_for(f, a=1, b2=2) == plugin.base_url + "/foo/1/2" | ||
|
||
|
||
def test_url_for_args(plugin): | ||
f = lambda a, b: None | ||
plugin.route("/<a>/<b>")(f) | ||
assert plugin.url_for(f, 1, 2) == plugin.base_url + "/1/2" | ||
f = lambda a, b2, c, d: None | ||
plugin.route("/<a>/<b2>/<c>/<d>")(f) | ||
assert plugin.url_for(f, 1, 2.6, True, 'baz') == plugin.base_url + "/1/2.6/True/baz" | ||
|
||
|
||
def test_route_for(plugin): | ||
|
@@ -75,8 +75,14 @@ def test_route_for(plugin): | |
|
||
def test_route_for_args(plugin): | ||
f = lambda: None | ||
plugin.route("/foo/<a>/<b>")(f) | ||
assert plugin.route_for(plugin.base_url + "/foo/1/2") is f | ||
g = lambda: (None, None) # just to make sure that they are easily different | ||
plugin.route("/foo/<a>/<b2>")(f) | ||
plugin.route("/foo/a/b")(g) | ||
|
||
# due to the unpredictable sorting of dict, just do it 100 times to see if it fails | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I doubt this is needed, dict-ordering is not guaranteed (in Python 3.5 or older) but it is deterministic. It is not random. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe not in Py3, but it was an issue before this PR, so it's there to prove that it's fixed with the PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I don't think this is a problem on Python 2 either. Again, the ordering is not guaranteed, but it is deterministic. So every single run for the 100 runs will be identical. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You would think, right? I expected that, since every other language I've worked with is like that. I can tell you that, in my attempts just to find this issue, I proved the opposite on Python 2.7. When it says that it can't guarantee order there, for the first time I've seen, it really means it. Just for the sake of it, I'll write up a test case and run it. If it yields consistent results, then I'll concede. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You win. I don't know what was different before that was giving unreliable results, but it definitely was. That was a long time ago, a different installation of Windows, etc. |
||
for _ in range(0, 100): | ||
assert plugin.route_for(plugin.base_url + "/foo/1/2") is f | ||
assert plugin.route_for(plugin.base_url + "/foo/a/b") is g | ||
|
||
|
||
def test_dispatch(plugin): | ||
|
@@ -111,8 +117,9 @@ def test_no_route(plugin): | |
def test_arg_parsing(plugin): | ||
f = mock.create_autospec(lambda: None) | ||
plugin.route("/foo")(f) | ||
plugin.run(['plugin://py.test/foo', '0', '?bar=baz']) | ||
assert plugin.args['bar'][0] == 'baz' | ||
plugin.run(['plugin://py.test/foo', '0', '?bar=baz&bar2=baz2']) | ||
assert plugin.args['bar'][0] == 'baz' and plugin.args['bar2'][0] == 'baz2' | ||
|
||
|
||
def test_trailing_slash_in_route_definition(plugin): | ||
""" Should call registered route with trailing slash. """ | ||
|
@@ -121,13 +128,15 @@ def test_trailing_slash_in_route_definition(plugin): | |
plugin.run(['plugin://py.test/foo', '0']) | ||
assert f.call_count == 1 | ||
|
||
|
||
def test_trailing_slashes_in_run(plugin): | ||
""" Should call registered route without trailing slash. """ | ||
f = mock.create_autospec(lambda: None) | ||
plugin.route("/foo")(f) | ||
plugin.run(['plugin://py.test/foo/', '0']) | ||
assert f.call_count == 1 | ||
|
||
|
||
def test_trailing_slash_handling_for_root(plugin): | ||
f = mock.create_autospec(lambda: None) | ||
plugin.route("/<a>")(lambda: None) | ||
|
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.
Not sure what the relevance is of renaming b to b2 in these tests ;-)