blob: 893d967b2ec63bf8c97466c9fc53273324cea9c7 [file]
import re
import sys
import pytest
from pip._vendor.packaging.version import Version
from pip._internal.commands.debug import create_vendor_txt_map
from pip._internal.utils import compatibility_tags
from tests.lib import PipTestEnvironment
@pytest.mark.parametrize(
"expected_text",
[
"sys.executable: ",
"sys.getdefaultencoding: ",
"sys.getfilesystemencoding: ",
"locale.getencoding: ",
"sys.platform: ",
"sys.implementation:",
"'cert' config value: ",
"REQUESTS_CA_BUNDLE: ",
"CURL_CA_BUNDLE: ",
"pip._vendor.certifi.where(): ",
"pip._vendor.DEBUNDLED: ",
"vendored library versions:",
],
)
def test_debug(script: PipTestEnvironment, expected_text: str) -> None:
"""
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
def test_debug__library_versions(script: PipTestEnvironment) -> None:
"""
Check the library versions normal output.
"""
args = ["debug"]
result = script.pip(*args, allow_stderr_warning=True)
print(result.stdout)
vendored_versions = create_vendor_txt_map()
for name, value in vendored_versions.items():
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)
@pytest.mark.parametrize(
"args",
[
[],
["--verbose"],
],
)
def test_debug__tags(script: PipTestEnvironment, args: list[str]) -> None:
"""
Check the compatible tag output.
"""
args = ["debug"] + args
result = script.pip(*args, allow_stderr_warning=True)
stdout = result.stdout
tags = compatibility_tags.get_supported()
expected_tag_header = f"Compatible tags: {len(tags)}"
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')"),
],
)
def test_debug__target_options(
script: PipTestEnvironment, args: list[str], expected: str
) -> None:
"""
Check passing target-related options.
"""
args = ["debug"] + args
result = script.pip(*args, allow_stderr_warning=True)
stdout = result.stdout
assert "Compatible tags: " in stdout
assert expected in stdout
@pytest.mark.skipif(
sys.version_info < (3, 11), reason="locale.getencoding requires Python 3.11+"
)
def test_no_encoding_warning_under_utf8_mode(script: PipTestEnvironment) -> None:
"""
Verify that running pip with PYTHONUTF8=1 and PYTHONWARNDEFAULTENCODING=1
does not emit an EncodingWarning from locale.getpreferredencoding().
"""
script.environ["PYTHONUTF8"] = "1"
script.environ["PYTHONWARNDEFAULTENCODING"] = "1"
result = script.pip(
"debug",
allow_stderr_warning=True,
expect_stderr=True,
)
assert "EncodingWarning" not in result.stderr
assert "EncodingWarning" not in result.stdout
def test_debug__unexpected_argument(script: PipTestEnvironment) -> None:
result = script.pip("debug", "unexpected_arg", expect_error=True)
assert result.stdout == ""
assert "ERROR: Too many arguments" in result.stderr.splitlines()