diff --git a/tests/functional/test_download.py b/tests/functional/test_download.py index 3bc9a241ea4..ae20d52aef7 100644 --- a/tests/functional/test_download.py +++ b/tests/functional/test_download.py @@ -144,55 +144,29 @@ def test_download_should_download_wheel_deps( result.did_create(Path("scratch") / dep_filename) -@pytest.mark.network -def test_download_should_skip_existing_files(script: PipTestEnvironment) -> None: +def test_download_should_skip_existing_files( + script: PipTestEnvironment, data: TestData +) -> None: """ It should not download files already existing in the scratch dir """ - script.scratch_path.joinpath("test-req.txt").write_text( - textwrap.dedent( - """ - INITools==0.1 - """ - ) - ) - - result = script.pip( - "download", - "-r", - script.scratch_path / "test-req.txt", - "-d", - ".", - ) - result.did_create(Path("scratch") / "INITools-0.1.tar.gz") - result.did_not_create(script.site_packages / "initools") + req_file = script.temporary_file("reqs.txt", "simplewheel==1.0") + result = script.pip("download", "-r", req_file, "-f", data.packages, "--no-index") + result.did_create(Path("scratch") / "simplewheel-1.0-py2.py3-none-any.whl") + result.did_not_create(script.site_packages / "simplewheel") # adding second package to test-req.txt - script.scratch_path.joinpath("test-req.txt").write_text( - textwrap.dedent( - """ - INITools==0.1 - python-openid==2.2.5 - """ - ) - ) + script.temporary_file(req_file, "simplewheel==1.0\nsimple.dist") # only the second package should be downloaded - result = script.pip( - "download", - "-r", - script.scratch_path / "test-req.txt", - "-d", - ".", - ) - openid_tarball_prefix = str(Path("scratch") / "python-openid-") + result = script.pip("download", "-r", req_file, "-f", data.packages, "--no-index") assert any( - os.fspath(path).startswith(openid_tarball_prefix) + os.fspath(path).startswith(str(Path("scratch") / "simple.dist")) for path in result.files_created ) - result.did_not_create(Path("scratch") / "INITools-0.1.tar.gz") - result.did_not_create(script.site_packages / "initools") - result.did_not_create(script.site_packages / "openid") + result.did_not_create(Path("scratch") / "simplewheel-1.0-py2.py3-none-any.whl") + result.did_not_create(script.site_packages / "simplewheel") + result.did_not_create(script.site_packages / "simpledist") @pytest.mark.network diff --git a/tests/functional/test_install_upgrade.py b/tests/functional/test_install_upgrade.py index de52218e96f..96fee48f38b 100644 --- a/tests/functional/test_install_upgrade.py +++ b/tests/functional/test_install_upgrade.py @@ -17,14 +17,13 @@ from tests.lib.wheel import make_wheel -@pytest.mark.network def test_no_upgrade_unless_requested(script: PipTestEnvironment) -> None: """ No upgrade if not specifically requested. """ - script.pip("install", "INITools==0.1") - result = script.pip("install", "INITools") + script.pip_install_local("simplewheel==1.0") + result = script.pip_install_local("simplewheel") assert ( not result.files_created ), "pip install INITools upgraded when it should not have" @@ -135,29 +134,27 @@ def test_eager_does_upgrade_dependencies_when_no_longer_satisfied( ), "should have uninstalled simple==1.0" -@pytest.mark.network def test_upgrade_to_specific_version(script: PipTestEnvironment) -> None: """ It does upgrade to specific version requested. """ - script.pip("install", "INITools==0.1") - result = script.pip("install", "INITools==0.2") + script.pip_install_local("simplewheel==1.0") + result = script.pip_install_local("simplewheel==2.0") assert result.files_created, "pip install with specific version did not upgrade" - assert script.site_packages / "initools-0.1.dist-info" in result.files_deleted - result.did_create(script.site_packages / "initools-0.2.dist-info") + assert script.site_packages / "simplewheel-1.0.dist-info" in result.files_deleted + result.did_create(script.site_packages / "simplewheel-2.0.dist-info") -@pytest.mark.network def test_upgrade_if_requested(script: PipTestEnvironment) -> None: """ And it does upgrade if requested. """ - script.pip("install", "INITools==0.1") - result = script.pip("install", "--upgrade", "INITools") + script.pip_install_local("simplewheel==1.0") + result = script.pip_install_local("--upgrade", "simplewheel") assert result.files_created, "pip install --upgrade did not upgrade" - result.did_not_create(script.site_packages / "initools-0.1.dist-info") + result.did_not_create(script.site_packages / "simplewheel-1.0.dist-info") def test_upgrade_with_newest_already_installed( @@ -192,31 +189,29 @@ def test_upgrade_with_newest_already_installed( assert msg in result.stdout, result.stdout -@pytest.mark.network def test_upgrade_force_reinstall_newest(script: PipTestEnvironment) -> None: """ Force reinstallation of a package even if it is already at its newest version if --force-reinstall is supplied. """ - result = script.pip("install", "INITools") - result.did_create(script.site_packages / "initools") - result2 = script.pip("install", "--upgrade", "--force-reinstall", "INITools") - assert result2.files_updated, "upgrade to INITools 0.3 failed" - result3 = script.pip("uninstall", "initools", "-y") + result = script.pip_install_local("simplewheel") + result.did_create(script.site_packages / "simplewheel") + result2 = script.pip_install_local("--upgrade", "--force-reinstall", "simplewheel") + assert result2.files_updated, "upgrade to simplewheel 2.0 failed" + result3 = script.pip("uninstall", "simplewheel", "-y") assert_all_changes(result, result3, [script.venv / "build", "cache"]) -@pytest.mark.network def test_uninstall_before_upgrade(script: PipTestEnvironment) -> None: """ Automatic uninstall-before-upgrade. """ - result = script.pip("install", "INITools==0.2") - result.did_create(script.site_packages / "initools") - result2 = script.pip("install", "INITools==0.3") - assert result2.files_created, "upgrade to INITools 0.3 failed" - result3 = script.pip("uninstall", "initools", "-y") + result = script.pip_install_local("simplewheel==1.0") + result.did_create(script.site_packages / "simplewheel") + result2 = script.pip_install_local("simplewheel==2.0") + assert result2.files_created, "upgrade to simplewheel 2.0 failed" + result3 = script.pip("uninstall", "simplewheel", "-y") assert_all_changes(result, result3, [script.venv / "build", "cache"]) @@ -329,30 +324,30 @@ def test_uninstall_rollback(script: PipTestEnvironment, data: TestData) -> None: ) -@pytest.mark.network -def test_should_not_install_always_from_cache(script: PipTestEnvironment) -> None: +def test_should_not_install_always_from_cache( + script: PipTestEnvironment, data: TestData +) -> None: """ If there is an old cached package, pip should download the newer version Related to issue #175 """ - script.pip("install", "INITools==0.2") - script.pip("uninstall", "-y", "INITools") - result = script.pip("install", "INITools==0.1") - result.did_not_create(script.site_packages / "initools-0.2.dist-info") - result.did_create(script.site_packages / "initools-0.1.dist-info") + script.pip_install_local("simplewheel==2.0") + script.pip("uninstall", "-y", "simplewheel") + result = script.pip_install_local("simplewheel==1.0") + result.did_not_create(script.site_packages / "simplewheel-2.0.dist-info") + result.did_create(script.site_packages / "simplewheel-1.0.dist-info") -@pytest.mark.network def test_install_with_ignoreinstalled_requested(script: PipTestEnvironment) -> None: """ Test old conflicting package is completely ignored """ - script.pip("install", "INITools==0.1") - result = script.pip("install", "-I", "INITools==0.3") + script.pip_install_local("simplewheel==1.0") + result = script.pip_install_local("-I", "simplewheel==2.0") assert result.files_created, "pip install -I did not install" # both the old and new metadata should be present. - assert os.path.exists(script.site_packages_path / "initools-0.1.dist-info") - assert os.path.exists(script.site_packages_path / "initools-0.3.dist-info") + assert os.path.exists(script.site_packages_path / "simplewheel-1.0.dist-info") + assert os.path.exists(script.site_packages_path / "simplewheel-2.0.dist-info") @pytest.mark.network diff --git a/tests/functional/test_list.py b/tests/functional/test_list.py index f058439279f..45eb0fd65c1 100644 --- a/tests/functional/test_list.py +++ b/tests/functional/test_list.py @@ -130,36 +130,32 @@ def test_multiple_exclude_and_normalization( assert "pip" not in result.stdout -@pytest.mark.network @pytest.mark.usefixtures("enable_user_site") def test_user_flag(script: PipTestEnvironment, data: TestData) -> None: """ Test the behavior of --user flag in the list command """ - script.pip("download", "setuptools", "wheel", "-d", data.packages) - script.pip("install", "-f", data.find_links, "--no-index", "simple==1.0") - script.pip("install", "-f", data.find_links, "--no-index", "--user", "simple2==2.0") + script.pip_install_local("simplewheel==1.0") + script.pip_install_local("--user", "simple.dist==0.1") result = script.pip("list", "--user", "--format=json") - assert {"name": "simple", "version": "1.0"} not in json.loads(result.stdout) - assert {"name": "simple2", "version": "2.0"} in json.loads(result.stdout) + assert {"name": "simplewheel", "version": "1.0"} not in json.loads(result.stdout) + assert {"name": "simple.dist", "version": "0.1"} in json.loads(result.stdout) -@pytest.mark.network @pytest.mark.usefixtures("enable_user_site") def test_user_columns_flag(script: PipTestEnvironment, data: TestData) -> None: """ Test the behavior of --user --format=columns flags in the list command """ - script.pip("download", "setuptools", "wheel", "-d", data.packages) - script.pip("install", "-f", data.find_links, "--no-index", "simple==1.0") - script.pip("install", "-f", data.find_links, "--no-index", "--user", "simple2==2.0") + script.pip_install_local("simplewheel==1.0") + script.pip_install_local("--user", "simple.dist==0.1") result = script.pip("list", "--user", "--format=columns") assert "Package" in result.stdout assert "Version" in result.stdout - assert "simple2 (2.0)" not in result.stdout - assert "simple2 2.0" in result.stdout, str(result) + assert "simple.dist (2.0)" not in result.stdout + assert "simple.dist 0.1" in result.stdout, str(result) @pytest.mark.network diff --git a/tests/lib/__init__.py b/tests/lib/__init__.py index ac47291cdbc..64bfc67bd47 100644 --- a/tests/lib/__init__.py +++ b/tests/lib/__init__.py @@ -758,7 +758,9 @@ def assert_installed_editable(self, dist_name: str) -> None: and x.get("editable_project_location") ) - def temporary_file(self, filename: str, contents: str) -> pathlib.Path: + def temporary_file( + self, filename: str | pathlib.Path, contents: str + ) -> pathlib.Path: """Create a temporary file with the given filename and contents.""" path = self.scratch_path.joinpath(filename) create_file(path, contents)