Skip to content

Commit 9572b92

Browse files
committed
Improve path_to_url() tests
Use `urllib.parse.quote()` rather than `urllib.request.pathname2url()` to generate expected URLs in tests for `path_to_url()`. This makes expectations a little more explicit. (The implementation of `path_to_url()` itself calls `pathname2url()`, and so we were marking our own homework!)
1 parent a4b40f6 commit 9572b92

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

news/7dab557a-8fb5-41c5-afae-a92c8ab02aba.trivial.rst

Whitespace-only changes.

tests/unit/test_urls.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import sys
3-
import urllib.request
3+
import urllib.parse
44

55
import pytest
66

@@ -11,7 +11,7 @@
1111
def test_path_to_url_unix() -> None:
1212
assert path_to_url("/tmp/file") == "file:///tmp/file"
1313
path = os.path.join(os.getcwd(), "file")
14-
assert path_to_url("file") == "file://" + urllib.request.pathname2url(path)
14+
assert path_to_url("file") == "file://" + urllib.parse.quote(path)
1515

1616

1717
@pytest.mark.skipif("sys.platform != 'win32'")
@@ -39,7 +39,7 @@ def test_unc_path_to_url_win() -> None:
3939
@pytest.mark.skipif("sys.platform != 'win32'")
4040
def test_relative_path_to_url_win() -> None:
4141
resolved_path = os.path.join(os.getcwd(), "file")
42-
assert path_to_url("file") == "file:" + urllib.request.pathname2url(resolved_path)
42+
assert path_to_url("file") == "file:///" + urllib.parse.quote(resolved_path, safe='/:')
4343

4444

4545
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)