Skip to content

Commit 0d33a34

Browse files
usermatthewhughes934
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. This currently affects only 3.12 and 3.13 but there are other backports for that change in review upstream, so we'll likely need to update this in the future. [1] python/cpython#113563
1 parent 2753c77 commit 0d33a34

1 file changed

Lines changed: 61 additions & 20 deletions

File tree

tests/unit/test_collector.py

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import os
55
import re
6+
import sys
67
import uuid
78
from pathlib import Path
89
from textwrap import dedent
@@ -377,33 +378,13 @@ def test_clean_url_path_with_local_path(path: str, expected: str) -> None:
377378
"git+https://example.com/repo.git@at%40 space#egg=my-package-1.0",
378379
"git+https://example.com/repo.git@at%40%20space#egg=my-package-1.0",
379380
),
380-
# URL with Windows drive letter. The `:` after the drive
381-
# letter should not be quoted. The trailing `/` should be
382-
# removed.
383-
pytest.param(
384-
"file:///T:/path/with spaces/",
385-
"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-
),
390-
),
391381
# URL with Windows drive letter, running on non-windows
392382
# platform. The `:` after the drive should be quoted.
393383
pytest.param(
394384
"file:///T:/path/with spaces/",
395385
"file:///T%3A/path/with%20spaces/",
396386
marks=pytest.mark.skipif("sys.platform == 'win32'"),
397387
),
398-
# Test a VCS URL with a Windows drive letter and revision.
399-
pytest.param(
400-
"git+file:///T:/with space/repo.git@1.0#egg=my-package-1.0",
401-
"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-
),
406-
),
407388
# Test a VCS URL with a Windows drive letter and revision,
408389
# running on non-windows platform.
409390
pytest.param(
@@ -417,6 +398,66 @@ def test_ensure_quoted_url(url: str, clean_url: str) -> None:
417398
assert _ensure_quoted_url(url) == clean_url
418399

419400

401+
# versions containing fix/backport from https://github.com/python/cpython/pull/113563
402+
has_new_urlun_behaviour = (
403+
# https://github.com/python/cpython/commit/387ff96e95b9f8a8cc7e646523ba3175b1350669
404+
(sys.version_info[:2] == (3, 12) and sys.version_info >= (3, 12, 4))
405+
or
406+
# https://github.com/python/cpython/commit/872000606271c52d989e53fe4cc9904343d81855
407+
(sys.version_info[:2] == (3, 13) and sys.version_info >= (3, 13, 0, "beta", 3))
408+
)
409+
410+
411+
@pytest.mark.skipif(
412+
sys.platform != "win32" or has_new_urlun_behaviour,
413+
reason="testing windows behaviour on older CPython",
414+
)
415+
@pytest.mark.parametrize(
416+
("url", "clean_url"),
417+
(
418+
(
419+
# URL with Windows drive letter. The `:` after the drive
420+
# letter should not be quoted. The trailing `/` should be
421+
# removed.
422+
"file:///T:/path/with spaces/",
423+
"file:///T:/path/with%20spaces",
424+
),
425+
(
426+
# Test a VCS URL with a Windows drive letter and revision.
427+
"git+file:///T:/with space/repo.git@1.0#egg=my-package-1.0",
428+
"git+file:///T:/with%20space/repo.git@1.0#egg=my-package-1.0",
429+
),
430+
),
431+
)
432+
def test_ensure_quoted_url_windows_old(url: str, clean_url: str) -> None:
433+
assert _ensure_quoted_url(url) == clean_url
434+
435+
436+
@pytest.mark.skipif(
437+
sys.platform != "win32" or not has_new_urlun_behaviour,
438+
reason="testing windows behaviour on newer cpython",
439+
)
440+
@pytest.mark.parametrize(
441+
("url", "clean_url"),
442+
(
443+
(
444+
# URL with Windows drive letter. The `:` after the drive
445+
# letter should not be quoted. The trailing `/` should be
446+
# removed.
447+
"file:///T:/path/with spaces/",
448+
"file://///T:/path/with%20spaces",
449+
),
450+
(
451+
# Test a VCS URL with a Windows drive letter and revision.
452+
"git+file:///T:/with space/repo.git@1.0#egg=my-package-1.0",
453+
"git+file://///T:/with%20space/repo.git@1.0#egg=my-package-1.0",
454+
),
455+
),
456+
)
457+
def test_ensure_quoted_url_windows_new(url: str, clean_url: str) -> None:
458+
assert _ensure_quoted_url(url) == clean_url
459+
460+
420461
def _test_parse_links_data_attribute(
421462
anchor_html: str, attr: str, expected: Optional[str]
422463
) -> Link:

0 commit comments

Comments
 (0)