2021-09-13 00:31:12 +02:00
|
|
|
from typing import Iterable
|
2018-04-01 00:17:47 +02:00
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
from tests.lib import PipTestEnvironment, create_test_package_with_setup
|
2018-04-01 00:17:47 +02:00
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
|
|
|
|
def assert_contains_expected_lines(string: str, expected_lines: Iterable[str]) -> None:
|
2020-08-01 11:57:30 +02:00
|
|
|
for expected_line in expected_lines:
|
2021-08-13 15:23:45 +02:00
|
|
|
assert (expected_line + "\n") in string
|
2018-04-01 00:17:47 +02:00
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_check_install_canonicalization(script: PipTestEnvironment) -> None:
|
2018-04-01 00:17:47 +02:00
|
|
|
pkga_path = create_test_package_with_setup(
|
|
|
|
script,
|
2021-08-13 15:23:45 +02:00
|
|
|
name="pkgA",
|
|
|
|
version="1.0",
|
|
|
|
install_requires=["normal-missing", "SPECIAL.missing"],
|
2018-04-01 00:17:47 +02:00
|
|
|
)
|
|
|
|
normal_path = create_test_package_with_setup(
|
|
|
|
script,
|
2021-08-13 15:23:45 +02:00
|
|
|
name="normal-missing",
|
|
|
|
version="0.1",
|
2018-04-01 00:17:47 +02:00
|
|
|
)
|
2018-05-30 11:41:02 +02:00
|
|
|
special_path = create_test_package_with_setup(
|
|
|
|
script,
|
2021-08-13 15:23:45 +02:00
|
|
|
name="SPECIAL.missing",
|
|
|
|
version="0.1",
|
2018-05-30 11:41:02 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# Let's install pkgA without its dependency
|
2021-08-13 15:23:45 +02:00
|
|
|
result = script.pip("install", "--no-index", pkga_path, "--no-deps")
|
2018-05-30 11:41:02 +02:00
|
|
|
assert "Successfully installed pkgA-1.0" in result.stdout, str(result)
|
|
|
|
|
|
|
|
# Install the first missing dependency. Only an error for the
|
|
|
|
# second dependency should remain.
|
2018-04-01 00:17:47 +02:00
|
|
|
result = script.pip(
|
2021-08-13 15:23:45 +02:00
|
|
|
"install",
|
|
|
|
"--no-index",
|
2019-08-11 04:04:44 +02:00
|
|
|
normal_path,
|
2021-08-13 15:23:45 +02:00
|
|
|
"--quiet",
|
2019-08-11 04:04:44 +02:00
|
|
|
allow_stderr_error=True,
|
2018-04-01 00:17:47 +02:00
|
|
|
)
|
2018-05-30 11:41:02 +02:00
|
|
|
expected_lines = [
|
2020-07-27 15:55:19 +02:00
|
|
|
"pkga 1.0 requires SPECIAL.missing, which is not installed.",
|
2018-05-30 11:41:02 +02:00
|
|
|
]
|
2019-01-11 11:12:44 +01:00
|
|
|
# Deprecated python versions produce an extra warning on stderr
|
2020-08-01 11:57:30 +02:00
|
|
|
assert_contains_expected_lines(result.stderr, expected_lines)
|
2018-04-01 00:17:47 +02:00
|
|
|
assert result.returncode == 0
|
|
|
|
|
|
|
|
# Install the second missing package and expect that there is no warning
|
|
|
|
# during the installation. This is special as the package name requires
|
|
|
|
# name normalization (as in https://github.com/pypa/pip/issues/5134)
|
|
|
|
result = script.pip(
|
2021-08-13 15:23:45 +02:00
|
|
|
"install",
|
|
|
|
"--no-index",
|
|
|
|
special_path,
|
|
|
|
"--quiet",
|
2018-04-01 00:17:47 +02:00
|
|
|
)
|
2020-07-27 15:53:59 +02:00
|
|
|
assert "requires" not in result.stderr
|
2018-04-01 00:17:47 +02:00
|
|
|
assert result.returncode == 0
|
|
|
|
|
|
|
|
# Double check that all errors are resolved in the end
|
2021-08-13 15:23:45 +02:00
|
|
|
result = script.pip("check")
|
2018-05-30 11:41:02 +02:00
|
|
|
expected_lines = [
|
2018-04-01 00:17:47 +02:00
|
|
|
"No broken requirements found.",
|
2018-05-30 11:41:02 +02:00
|
|
|
]
|
2020-08-01 11:57:30 +02:00
|
|
|
assert_contains_expected_lines(result.stdout, expected_lines)
|
2018-04-01 00:17:47 +02:00
|
|
|
assert result.returncode == 0
|
2018-05-30 11:41:02 +02:00
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_check_install_does_not_warn_for_out_of_graph_issues(
|
|
|
|
script: PipTestEnvironment,
|
|
|
|
) -> None:
|
2018-05-30 11:41:02 +02:00
|
|
|
pkg_broken_path = create_test_package_with_setup(
|
|
|
|
script,
|
2021-08-13 15:23:45 +02:00
|
|
|
name="broken",
|
|
|
|
version="1.0",
|
|
|
|
install_requires=["missing", "conflict < 1.0"],
|
2018-05-30 11:41:02 +02:00
|
|
|
)
|
|
|
|
pkg_unrelated_path = create_test_package_with_setup(
|
|
|
|
script,
|
2021-08-13 15:23:45 +02:00
|
|
|
name="unrelated",
|
|
|
|
version="1.0",
|
2018-05-30 11:41:02 +02:00
|
|
|
)
|
|
|
|
pkg_conflict_path = create_test_package_with_setup(
|
|
|
|
script,
|
2021-08-13 15:23:45 +02:00
|
|
|
name="conflict",
|
|
|
|
version="1.0",
|
2018-05-30 11:41:02 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# Install a package without it's dependencies
|
2021-08-13 15:23:45 +02:00
|
|
|
result = script.pip("install", "--no-index", pkg_broken_path, "--no-deps")
|
2020-07-27 15:53:59 +02:00
|
|
|
assert "requires" not in result.stderr
|
2018-05-30 11:41:02 +02:00
|
|
|
|
|
|
|
# Install conflict package
|
|
|
|
result = script.pip(
|
2021-08-13 15:23:45 +02:00
|
|
|
"install",
|
|
|
|
"--no-index",
|
|
|
|
pkg_conflict_path,
|
|
|
|
allow_stderr_error=True,
|
|
|
|
)
|
|
|
|
assert_contains_expected_lines(
|
|
|
|
result.stderr,
|
|
|
|
[
|
|
|
|
"broken 1.0 requires missing, which is not installed.",
|
|
|
|
"broken 1.0 requires conflict<1.0, "
|
|
|
|
"but you have conflict 1.0 which is incompatible.",
|
|
|
|
],
|
2018-05-30 11:41:02 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# Install unrelated package
|
|
|
|
result = script.pip(
|
2021-08-13 15:23:45 +02:00
|
|
|
"install",
|
|
|
|
"--no-index",
|
|
|
|
pkg_unrelated_path,
|
|
|
|
"--quiet",
|
2018-05-30 11:41:02 +02:00
|
|
|
)
|
|
|
|
# should not warn about broken's deps when installing unrelated package
|
2020-07-27 15:53:59 +02:00
|
|
|
assert "requires" not in result.stderr
|
2018-05-30 11:41:02 +02:00
|
|
|
|
2021-08-13 15:23:45 +02:00
|
|
|
result = script.pip("check", expect_error=True)
|
2018-05-30 11:41:02 +02:00
|
|
|
expected_lines = [
|
|
|
|
"broken 1.0 requires missing, which is not installed.",
|
|
|
|
"broken 1.0 has requirement conflict<1.0, but you have conflict 1.0.",
|
|
|
|
]
|
2020-08-01 11:57:30 +02:00
|
|
|
assert_contains_expected_lines(result.stdout, expected_lines)
|