2020-01-13 10:57:39 +01:00
|
|
|
import os
|
2017-10-24 00:03:20 +02:00
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
from tests.lib import PipTestEnvironment, assert_all_changes
|
2017-10-24 00:03:20 +02:00
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def check_installed_version(
|
|
|
|
script: PipTestEnvironment, package: str, expected: str
|
|
|
|
) -> None:
|
2017-10-24 00:03:20 +02:00
|
|
|
result = script.pip("show", package)
|
|
|
|
lines = result.stdout.splitlines()
|
|
|
|
version = None
|
|
|
|
for line in lines:
|
|
|
|
if line.startswith("Version: "):
|
|
|
|
version = line.split()[-1]
|
|
|
|
break
|
2020-12-23 20:25:12 +01:00
|
|
|
assert version == expected, f"version {version} != {expected}"
|
2017-10-24 00:03:20 +02:00
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def check_force_reinstall(
|
|
|
|
script: PipTestEnvironment, specifier: str, expected: str
|
|
|
|
) -> None:
|
2017-10-24 00:03:20 +02:00
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
specifier: the requirement specifier to force-reinstall.
|
|
|
|
expected: the expected version after force-reinstalling.
|
|
|
|
"""
|
|
|
|
result = script.pip_install_local("simplewheel==1.0")
|
|
|
|
check_installed_version(script, "simplewheel", "1.0")
|
|
|
|
|
2020-01-13 10:57:39 +01:00
|
|
|
# Remove an installed file to test whether --force-reinstall fixes it.
|
2020-01-14 14:56:23 +01:00
|
|
|
to_fix = script.site_packages_path.joinpath("simplewheel", "__init__.py")
|
|
|
|
to_fix.unlink()
|
2020-01-13 10:57:39 +01:00
|
|
|
|
2017-10-24 00:03:20 +02:00
|
|
|
result2 = script.pip_install_local("--force-reinstall", specifier)
|
|
|
|
check_installed_version(script, "simplewheel", expected)
|
|
|
|
|
2020-01-14 14:56:23 +01:00
|
|
|
# site_packages_path is absolute, but files_created mapping uses
|
|
|
|
# relative paths as key.
|
|
|
|
fixed_key = os.path.relpath(to_fix, script.base_path)
|
2020-06-02 14:08:55 +02:00
|
|
|
result2.did_create(fixed_key, message="force-reinstall failed")
|
2020-01-14 14:56:23 +01:00
|
|
|
|
2019-08-11 04:04:44 +02:00
|
|
|
result3 = script.pip("uninstall", "simplewheel", "-y")
|
2017-10-24 00:03:20 +02:00
|
|
|
assert_all_changes(result, result3, [script.venv / "build", "cache"])
|
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_force_reinstall_with_no_version_specifier(script: PipTestEnvironment) -> None:
|
2017-10-24 00:03:20 +02:00
|
|
|
"""
|
|
|
|
Check --force-reinstall when there is no version specifier and the
|
|
|
|
installed version is not the newest version.
|
|
|
|
"""
|
|
|
|
check_force_reinstall(script, "simplewheel", "2.0")
|
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_force_reinstall_with_same_version_specifier(
|
|
|
|
script: PipTestEnvironment,
|
|
|
|
) -> None:
|
2017-10-24 00:03:20 +02:00
|
|
|
"""
|
|
|
|
Check --force-reinstall when the version specifier equals the installed
|
|
|
|
version and the installed version is not the newest version.
|
|
|
|
"""
|
|
|
|
check_force_reinstall(script, "simplewheel==1.0", "1.0")
|