diff --git a/news/7dab557a-8fb5-41c5-afae-a92c8ab02aba.trivial.rst b/news/7dab557a-8fb5-41c5-afae-a92c8ab02aba.trivial.rst new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/unit/test_urls.py b/tests/unit/test_urls.py index 2a56e459f1d..9a82f0f84f1 100644 --- a/tests/unit/test_urls.py +++ b/tests/unit/test_urls.py @@ -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="/:") @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: