-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Improve path_to_url()
tests
#13496
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
Improve path_to_url()
tests
#13496
Changes from all commits
7caaf5d
d057064
781d452
508998b
aa8f0a1
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,6 +1,6 @@ | ||
import os | ||
import sys | ||
import urllib.request | ||
import urllib.parse | ||
|
||
import pytest | ||
|
||
|
@@ -11,15 +11,15 @@ | |
def test_path_to_url_unix() -> None: | ||
assert path_to_url("/tmp/file") == "file:///tmp/file" | ||
path = os.path.join(os.getcwd(), "file") | ||
assert path_to_url("file") == "file://" + path | ||
assert path_to_url("file") == "file://" + urllib.parse.quote(path) | ||
|
||
|
||
@pytest.mark.skipif("sys.platform != 'win32'") | ||
@pytest.mark.parametrize( | ||
"path, url", | ||
[ | ||
pytest.param("c:/tmp/file", "file:///C:/tmp/file", id="posix-path"), | ||
pytest.param("c:\\tmp\\file", "file:///C:/tmp/file", id="nt-path"), | ||
pytest.param("C:/tmp/file", "file:///C:/tmp/file", id="posix-path"), | ||
pytest.param("C:\\tmp\\file", "file:///C:/tmp/file", id="nt-path"), | ||
], | ||
) | ||
def test_path_to_url_win(path: str, url: str) -> None: | ||
|
@@ -38,21 +38,21 @@ def test_unc_path_to_url_win() -> None: | |
|
||
@pytest.mark.skipif("sys.platform != 'win32'") | ||
def test_relative_path_to_url_win() -> None: | ||
resolved_path = os.path.join(os.getcwd(), "file") | ||
assert path_to_url("file") == "file:" + urllib.request.pathname2url(resolved_path) | ||
path = os.path.join(os.getcwd(), "file").replace("\\", "/") | ||
assert path_to_url("file") == "file:///" + urllib.parse.quote(path, safe="/:") | ||
Comment on lines
+41
to
+42
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. Just to be sure, 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. Also, on Windows, does 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.
That's correct.
It does for the drive, yes: https://github.com/python/cpython/blob/6784ef7da7cbf1a944fd0685630ced54e4a0066c/Lib/urllib/request.py#L1711 (NTFS allows colons in other parts of the path, but Windows does not.) |
||
|
||
|
||
@pytest.mark.parametrize( | ||
"url,win_expected,non_win_expected", | ||
[ | ||
("file:tmp", "tmp", "tmp"), | ||
("file:c:/path/to/file", r"C:\path\to\file", "c:/path/to/file"), | ||
("file:C:/path/to/file", r"C:\path\to\file", "C:/path/to/file"), | ||
("file:/path/to/file", r"\path\to\file", "/path/to/file"), | ||
("file://localhost/tmp/file", r"\tmp\file", "/tmp/file"), | ||
("file://localhost/c:/tmp/file", r"C:\tmp\file", "/c:/tmp/file"), | ||
("file://localhost/C:/tmp/file", r"C:\tmp\file", "/C:/tmp/file"), | ||
("file://somehost/tmp/file", r"\\somehost\tmp\file", None), | ||
("file:///tmp/file", r"\tmp\file", "/tmp/file"), | ||
("file:///c:/tmp/file", r"C:\tmp\file", "/c:/tmp/file"), | ||
("file:///C:/tmp/file", r"C:\tmp\file", "/C:/tmp/file"), | ||
], | ||
) | ||
def test_url_to_path(url: str, win_expected: str, non_win_expected: str) -> None: | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
Without this change, tests will fail if the working directory contains a non-urlsafe character.