From c2a674f7928ab99d3ec53606bc7244cab399b8e4 Mon Sep 17 00:00:00 2001 From: user Date: Sun, 23 Jun 2024 10:07:03 +0100 Subject: [PATCH] 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] https://github.com/python/cpython/pull/113563 --- ...34-f9bf-4f17-a201-6546bdb9d5d2.trivial.rst | 0 tests/lib/__init__.py | 21 +++++++++++++++ tests/unit/test_collector.py | 27 ++++++++++++------- tests/unit/test_urls.py | 14 +++++++--- 4 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 news/5407ea34-f9bf-4f17-a201-6546bdb9d5d2.trivial.rst diff --git a/news/5407ea34-f9bf-4f17-a201-6546bdb9d5d2.trivial.rst b/news/5407ea34-f9bf-4f17-a201-6546bdb9d5d2.trivial.rst new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/lib/__init__.py b/tests/lib/__init__.py index bd31b59ff2f..822193f5c54 100644 --- a/tests/lib/__init__.py +++ b/tests/lib/__init__.py @@ -1375,3 +1375,24 @@ def __call__( CertFactory = Callable[[], str] + +# versions containing fix/backport from https://github.com/python/cpython/pull/113563 +# which changed the behavior of `urllib.parse.urlun{parse,split}` +has_new_urlun_behavior = ( + # https://github.com/python/cpython/commit/387ff96e95b9f8a8cc7e646523ba3175b1350669 + (sys.version_info[:2] == (3, 12) and sys.version_info >= (3, 12, 4)) + or + # https://github.com/python/cpython/commit/872000606271c52d989e53fe4cc9904343d81855 + (sys.version_info[:2] == (3, 13) and sys.version_info >= (3, 13, 0, "beta", 3)) +) + +# the above change seems to only impact tests on Windows, so just add skips for that +skip_needs_new_urlun_behavior_win = pytest.mark.skipif( + sys.platform != "win32" or not has_new_urlun_behavior, + reason="testing windows behavior for newer CPython", +) + +skip_needs_old_urlun_behavior_win = pytest.mark.skipif( + sys.platform != "win32" or has_new_urlun_behavior, + reason="testing windows behavior for older CPython", +) diff --git a/tests/unit/test_collector.py b/tests/unit/test_collector.py index e34104707ba..89da25b73d8 100644 --- a/tests/unit/test_collector.py +++ b/tests/unit/test_collector.py @@ -35,7 +35,12 @@ _ensure_quoted_url, ) from pip._internal.network.session import PipSession -from tests.lib import TestData, make_test_link_collector +from tests.lib import ( + TestData, + make_test_link_collector, + skip_needs_new_urlun_behavior_win, + skip_needs_old_urlun_behavior_win, +) ACCEPT = ", ".join( [ @@ -383,10 +388,12 @@ def test_clean_url_path_with_local_path(path: str, expected: str) -> None: pytest.param( "file:///T:/path/with spaces/", "file:///T:/path/with%20spaces", - marks=pytest.mark.skipif( - "sys.platform != 'win32' or " - "sys.version_info == (3, 13, 0, 'beta', 2)" - ), + marks=skip_needs_old_urlun_behavior_win, + ), + pytest.param( + "file:///T:/path/with spaces/", + "file://///T:/path/with%20spaces", + marks=skip_needs_new_urlun_behavior_win, ), # URL with Windows drive letter, running on non-windows # 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: pytest.param( "git+file:///T:/with space/repo.git@1.0#egg=my-package-1.0", "git+file:///T:/with%20space/repo.git@1.0#egg=my-package-1.0", - marks=pytest.mark.skipif( - "sys.platform != 'win32' or " - "sys.version_info == (3, 13, 0, 'beta', 2)" - ), + marks=skip_needs_old_urlun_behavior_win, + ), + pytest.param( + "git+file:///T:/with space/repo.git@1.0#egg=my-package-1.0", + "git+file://///T:/with%20space/repo.git@1.0#egg=my-package-1.0", + marks=skip_needs_new_urlun_behavior_win, ), # Test a VCS URL with a Windows drive letter and revision, # running on non-windows platform. diff --git a/tests/unit/test_urls.py b/tests/unit/test_urls.py index ba6bc6092a5..c4b8db681ff 100644 --- a/tests/unit/test_urls.py +++ b/tests/unit/test_urls.py @@ -5,6 +5,10 @@ import pytest from pip._internal.utils.urls import path_to_url, url_to_path +from tests.lib import ( + skip_needs_new_urlun_behavior_win, + skip_needs_old_urlun_behavior_win, +) @pytest.mark.skipif("sys.platform == 'win32'") @@ -23,12 +27,14 @@ def test_path_to_url_unix() -> None: pytest.param( r"\\unc\as\path", "file://unc/as/path", - marks=pytest.mark.skipif( - "sys.platform != 'win32' or " - "sys.version_info == (3, 13, 0, 'beta', 2)" - ), + marks=skip_needs_old_urlun_behavior_win, id="unc-path", ), + pytest.param( + r"\\unc\as\path", + "file:////unc/as/path", + marks=skip_needs_new_urlun_behavior_win, + ), ], ) def test_path_to_url_win(path: str, url: str) -> None: