Skip to content

Commit 16f0617

Browse files
usermatthewhughes934
user
authored andcommitted
Split up Windows tests relying on urlunparse behaviour
There was a behavioural change to `urllib.parse.urlunparse`[1] that affects some of our tests on Windows. With the understanding that the new behaviour is indeed desired, split up some tests relying on this behaviour depending on the version of Python. The sample URL used to check this behaviour was taken from a test in the upstream change (with the new behaviour this URL will round-trip parsing) [1] python/cpython#113563
1 parent 67e2a56 commit 16f0617

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

news/5407ea34-f9bf-4f17-a201-6546bdb9d5d2.trivial.rst

Whitespace-only changes.

tests/lib/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
Union,
2929
cast,
3030
)
31+
from urllib.parse import urlparse, urlunparse
3132
from zipfile import ZipFile
3233

3334
import pytest
@@ -1375,3 +1376,19 @@ def __call__(
13751376

13761377

13771378
CertFactory = Callable[[], str]
1379+
1380+
# versions containing fix/backport from https://github.com/python/cpython/pull/113563
1381+
# which changed the behavior of `urllib.parse.urlun{parse,split}`
1382+
url = "////path/to/file"
1383+
has_new_urlun_behavior = url == urlunparse(urlparse(url))
1384+
1385+
# the above change seems to only impact tests on Windows, so just add skips for that
1386+
skip_needs_new_urlun_behavior_win = pytest.mark.skipif(
1387+
sys.platform != "win32" or not has_new_urlun_behavior,
1388+
reason="testing windows behavior for newer CPython",
1389+
)
1390+
1391+
skip_needs_old_urlun_behavior_win = pytest.mark.skipif(
1392+
sys.platform != "win32" or has_new_urlun_behavior,
1393+
reason="testing windows behavior for older CPython",
1394+
)

tests/unit/test_collector.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@
3535
_ensure_quoted_url,
3636
)
3737
from pip._internal.network.session import PipSession
38-
from tests.lib import TestData, make_test_link_collector
38+
from tests.lib import (
39+
TestData,
40+
make_test_link_collector,
41+
skip_needs_new_urlun_behavior_win,
42+
skip_needs_old_urlun_behavior_win,
43+
)
3944

4045
ACCEPT = ", ".join(
4146
[
@@ -383,10 +388,12 @@ def test_clean_url_path_with_local_path(path: str, expected: str) -> None:
383388
pytest.param(
384389
"file:///T:/path/with spaces/",
385390
"file:///T:/path/with%20spaces",
386-
marks=pytest.mark.skipif(
387-
"sys.platform != 'win32' or "
388-
"sys.version_info == (3, 13, 0, 'beta', 2)"
389-
),
391+
marks=skip_needs_old_urlun_behavior_win,
392+
),
393+
pytest.param(
394+
"file:///T:/path/with spaces/",
395+
"file://///T:/path/with%20spaces",
396+
marks=skip_needs_new_urlun_behavior_win,
390397
),
391398
# URL with Windows drive letter, running on non-windows
392399
# platform. The `:` after the drive should be quoted.
@@ -399,10 +406,12 @@ def test_clean_url_path_with_local_path(path: str, expected: str) -> None:
399406
pytest.param(
400407
"git+file:///T:/with space/repo.git@1.0#egg=my-package-1.0",
401408
"git+file:///T:/with%20space/repo.git@1.0#egg=my-package-1.0",
402-
marks=pytest.mark.skipif(
403-
"sys.platform != 'win32' or "
404-
"sys.version_info == (3, 13, 0, 'beta', 2)"
405-
),
409+
marks=skip_needs_old_urlun_behavior_win,
410+
),
411+
pytest.param(
412+
"git+file:///T:/with space/repo.git@1.0#egg=my-package-1.0",
413+
"git+file://///T:/with%20space/repo.git@1.0#egg=my-package-1.0",
414+
marks=skip_needs_new_urlun_behavior_win,
406415
),
407416
# Test a VCS URL with a Windows drive letter and revision,
408417
# running on non-windows platform.

tests/unit/test_urls.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import pytest
66

77
from pip._internal.utils.urls import path_to_url, url_to_path
8+
from tests.lib import (
9+
skip_needs_new_urlun_behavior_win,
10+
skip_needs_old_urlun_behavior_win,
11+
)
812

913

1014
@pytest.mark.skipif("sys.platform == 'win32'")
@@ -23,12 +27,14 @@ def test_path_to_url_unix() -> None:
2327
pytest.param(
2428
r"\\unc\as\path",
2529
"file://unc/as/path",
26-
marks=pytest.mark.skipif(
27-
"sys.platform != 'win32' or "
28-
"sys.version_info == (3, 13, 0, 'beta', 2)"
29-
),
30+
marks=skip_needs_old_urlun_behavior_win,
3031
id="unc-path",
3132
),
33+
pytest.param(
34+
r"\\unc\as\path",
35+
"file:////unc/as/path",
36+
marks=skip_needs_new_urlun_behavior_win,
37+
),
3238
],
3339
)
3440
def test_path_to_url_win(path: str, url: str) -> None:

0 commit comments

Comments
 (0)