Skip to content

Commit 7caaf5d

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 7caaf5d

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

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

Whitespace-only changes.

tests/unit/test_urls.py

Lines changed: 5 additions & 4 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'")
@@ -38,8 +38,9 @@ def test_unc_path_to_url_win() -> None:
3838

3939
@pytest.mark.skipif("sys.platform != 'win32'")
4040
def test_relative_path_to_url_win() -> None:
41-
resolved_path = os.path.join(os.getcwd(), "file")
42-
assert path_to_url("file") == "file:" + urllib.request.pathname2url(resolved_path)
41+
resolved_path = os.path.join(os.getcwd(), "file").replace("\\", "/")
42+
quoted_path = urllib.parse.quote(resolved_path, safe="/:")
43+
assert path_to_url("file") == "file:///" + quoted_path
4344

4445

4546
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)