2023-01-28 23:35:25 +01:00
|
|
|
import re
|
2021-09-13 00:31:12 +02:00
|
|
|
from typing import List
|
|
|
|
|
2019-06-23 17:54:38 +02:00
|
|
|
import pytest
|
2023-01-28 23:35:25 +01:00
|
|
|
from pip._vendor.packaging.version import Version
|
2019-06-23 17:54:38 +02:00
|
|
|
|
2020-03-25 16:47:45 +01:00
|
|
|
from pip._internal.commands.debug import create_vendor_txt_map
|
2020-02-26 19:24:43 +01:00
|
|
|
from pip._internal.utils import compatibility_tags
|
2021-09-13 00:31:12 +02:00
|
|
|
from tests.lib import PipTestEnvironment
|
2019-06-23 17:54:38 +02:00
|
|
|
|
|
|
|
|
2019-07-20 03:52:54 +02:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"expected_text",
|
|
|
|
[
|
|
|
|
"sys.executable: ",
|
|
|
|
"sys.getdefaultencoding: ",
|
|
|
|
"sys.getfilesystemencoding: ",
|
|
|
|
"locale.getpreferredencoding: ",
|
|
|
|
"sys.platform: ",
|
|
|
|
"sys.implementation:",
|
2019-10-17 09:01:49 +02:00
|
|
|
"'cert' config value: ",
|
2019-10-15 11:24:34 +02:00
|
|
|
"REQUESTS_CA_BUNDLE: ",
|
|
|
|
"CURL_CA_BUNDLE: ",
|
|
|
|
"pip._vendor.certifi.where(): ",
|
2020-03-23 18:54:26 +01:00
|
|
|
"pip._vendor.DEBUNDLED: ",
|
|
|
|
"vendored library versions:",
|
2019-07-20 03:52:54 +02:00
|
|
|
],
|
|
|
|
)
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_debug(script: PipTestEnvironment, expected_text: str) -> None:
|
2019-07-20 03:52:54 +02:00
|
|
|
"""
|
|
|
|
Check that certain strings are present in the output.
|
|
|
|
"""
|
|
|
|
args = ["debug"]
|
|
|
|
result = script.pip(*args, allow_stderr_warning=True)
|
|
|
|
stdout = result.stdout
|
|
|
|
|
|
|
|
assert expected_text in stdout
|
|
|
|
|
|
|
|
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_debug__library_versions(script: PipTestEnvironment) -> None:
|
2020-03-25 16:47:45 +01:00
|
|
|
"""
|
|
|
|
Check the library versions normal output.
|
|
|
|
"""
|
|
|
|
args = ["debug"]
|
|
|
|
result = script.pip(*args, allow_stderr_warning=True)
|
2020-07-22 07:55:24 +02:00
|
|
|
print(result.stdout)
|
|
|
|
|
2020-03-25 16:47:45 +01:00
|
|
|
vendored_versions = create_vendor_txt_map()
|
|
|
|
for name, value in vendored_versions.items():
|
2023-01-28 23:35:25 +01:00
|
|
|
match = re.search(rf"{name}==(\S+)", result.stdout)
|
|
|
|
assert match is not None, f"Could not find {name} in output"
|
|
|
|
assert Version(match.group(1)) == Version(value)
|
2020-03-25 16:47:45 +01:00
|
|
|
|
|
|
|
|
2019-06-23 17:54:38 +02:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"args",
|
|
|
|
[
|
|
|
|
[],
|
|
|
|
["--verbose"],
|
|
|
|
],
|
|
|
|
)
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_debug__tags(script: PipTestEnvironment, args: List[str]) -> None:
|
2019-06-23 17:54:38 +02:00
|
|
|
"""
|
2019-07-20 03:52:54 +02:00
|
|
|
Check the compatible tag output.
|
2019-06-23 17:54:38 +02:00
|
|
|
"""
|
|
|
|
args = ["debug"] + args
|
2019-07-18 11:32:26 +02:00
|
|
|
result = script.pip(*args, allow_stderr_warning=True)
|
2019-06-23 17:54:38 +02:00
|
|
|
stdout = result.stdout
|
|
|
|
|
2020-02-26 19:24:43 +01:00
|
|
|
tags = compatibility_tags.get_supported()
|
2023-11-07 10:14:56 +01:00
|
|
|
expected_tag_header = f"Compatible tags: {len(tags)}"
|
2019-06-23 17:54:38 +02:00
|
|
|
assert expected_tag_header in stdout
|
|
|
|
|
|
|
|
show_verbose_note = "--verbose" not in args
|
|
|
|
assert (
|
|
|
|
"...\n [First 10 tags shown. Pass --verbose to show all.]" in stdout
|
|
|
|
) == show_verbose_note
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"args, expected",
|
|
|
|
[
|
|
|
|
(["--python-version", "3.7"], "(target: version_info='3.7')"),
|
|
|
|
],
|
|
|
|
)
|
2021-09-13 00:31:12 +02:00
|
|
|
def test_debug__target_options(
|
|
|
|
script: PipTestEnvironment, args: List[str], expected: str
|
|
|
|
) -> None:
|
2019-06-23 17:54:38 +02:00
|
|
|
"""
|
|
|
|
Check passing target-related options.
|
|
|
|
"""
|
|
|
|
args = ["debug"] + args
|
2019-07-18 11:32:26 +02:00
|
|
|
result = script.pip(*args, allow_stderr_warning=True)
|
2019-06-23 17:54:38 +02:00
|
|
|
stdout = result.stdout
|
|
|
|
|
|
|
|
assert "Compatible tags: " in stdout
|
|
|
|
assert expected in stdout
|