-
Notifications
You must be signed in to change notification settings - Fork 6
Added additional unit tests #19
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
Changes from all commits
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 |
|---|---|---|
| @@ -1,13 +1,10 @@ | ||
| #!/usr/bin/env python3 | ||
| import urllib.parse | ||
| from pathlib import PurePosixPath | ||
| from typing import Any, cast | ||
|
|
||
| import pytest | ||
|
|
||
| try: | ||
| import webob | ||
| except ImportError: | ||
| webob = None | ||
| import webob | ||
|
|
||
| from urlpath import URL, JailedURL | ||
|
|
||
|
|
@@ -185,7 +182,6 @@ def test_trailing_sep() -> None: | |
| assert URL("htp://example.com/with/double-sep//").trailing_sep == "//" | ||
|
|
||
|
|
||
| @pytest.mark.skipif(webob is None, reason="webob not installed") | ||
| def test_webob() -> None: | ||
|
||
| base_url = "http://www.example.com" | ||
| url = URL(webob.Request.blank("/webob/request", base_url=base_url)) | ||
|
|
@@ -195,7 +191,6 @@ def test_webob() -> None: | |
| assert str(url / webob.Request.blank("/replaced/path")) == "http://localhost/replaced/path" | ||
|
|
||
|
|
||
| @pytest.mark.skipif(webob is None, reason="webob not installed") | ||
| def test_webob_jail() -> None: | ||
|
||
| request = webob.Request.blank("/path/to/filename.ext", {"SCRIPT_NAME": "/app/root"}) | ||
|
|
||
|
|
@@ -319,6 +314,38 @@ def test_pchar() -> None: | |
| assert str(url) == "s3://mybucket/some_folder/123_2017-10-30T18:43:11.csv.gz" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("raw", "expected"), | ||
| ( | ||
| (urllib.parse.urlsplit("http://example.com/from-split?x=1#frag"), "http://example.com/from-split?x=1#frag"), | ||
| (urllib.parse.urlparse("https://example.com/from-parse"), "https://example.com/from-parse"), | ||
| (b"http://example.com/from-bytes", "http://example.com/from-bytes"), | ||
| ), | ||
| ) | ||
| def test_constructor_canonicalizes_supported_types(raw: Any, expected: str) -> None: | ||
| class PathLike: | ||
| def __fspath__(self) -> str: | ||
| return "http://example.com/from-fspath" | ||
|
|
||
| assert str(URL(raw)) == expected | ||
|
|
||
| # PathLike objects should be accepted consistently regardless of other inputs | ||
| assert str(URL(PathLike())) == "http://example.com/from-fspath" | ||
|
|
||
|
|
||
| def test_multi_argument_constructor_matches_joinpath_semantics() -> None: | ||
| base = URL("http://example.com/base/") | ||
|
|
||
| combined = URL("http://example.com/base/", "child", "../final") | ||
| chained = base / "child" / "../final" | ||
|
|
||
| assert str(combined) == str(chained) | ||
| assert "\x00" not in "".join(combined.parts) | ||
|
|
||
| absolute_override = URL("http://example.com/base/", "https://other.com/override", "tail") | ||
| assert str(absolute_override) == "https://other.com/override/tail" | ||
|
|
||
|
|
||
| def test_percent_encoding_spaces() -> None: | ||
| """Test that %20 encoded spaces don't get double-encoded.""" | ||
| # Reported bug: URL with %20 in middle of path segment gets double-encoded to %2520 | ||
|
|
||
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.
Importing webob unconditionally but the tests previously had conditional import logic. This will cause test failures when webob is not installed, breaking the optional dependency pattern.