1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00
pip/tests/functional/test_configuration.py
Jon Dufresne b0bf93f174 Remove unconditionally skipped test (fails if skip removed)
The test was introduced in f9990605dc (May
2017) and was unconditionally skipped in
6cf5d7db54. It remains skipped to this
day.

In commit bd850c0798, the patched_file
method was removed/renamed. So even if the skip were removed, it would
fail on the undefined attribute.

This was caught via mypy which emits an error due to the missing method.
2021-09-30 04:58:49 -07:00

143 lines
5.2 KiB
Python

"""Tests for the config command
"""
import re
import textwrap
from pip._internal.cli.status_codes import ERROR
from pip._internal.configuration import CONFIG_BASENAME, get_configuration_files
from tests.lib.configuration_helpers import ConfigurationMixin, kinds
def test_no_options_passed_should_error(script):
result = script.pip("config", expect_error=True)
assert result.returncode == ERROR
class TestBasicLoading(ConfigurationMixin):
def test_basic_modification_pipeline(self, script):
script.pip("config", "get", "test.blah", expect_error=True)
script.pip("config", "set", "test.blah", "1")
result = script.pip("config", "get", "test.blah")
assert result.stdout.strip() == "1"
script.pip("config", "unset", "test.blah")
script.pip("config", "get", "test.blah", expect_error=True)
def test_listing_is_correct(self, script):
script.pip("config", "set", "test.listing-beta", "2")
script.pip("config", "set", "test.listing-alpha", "1")
script.pip("config", "set", "test.listing-gamma", "3")
result = script.pip("config", "list")
lines = list(
filter(lambda x: x.startswith("test.listing-"), result.stdout.splitlines())
)
expected = """
test.listing-alpha='1'
test.listing-beta='2'
test.listing-gamma='3'
"""
assert lines == textwrap.dedent(expected).strip().splitlines()
def test_forget_section(self, script):
result = script.pip("config", "set", "isolated", "true", expect_error=True)
assert "global.isolated" in result.stderr
def test_env_var_values(self, script):
"""Test that pip configuration set with environment variables
is correctly displayed under "env_var".
"""
env_vars = {
"PIP_DEFAULT_TIMEOUT": "60",
"PIP_FIND_LINKS": "http://mirror.example.com",
}
script.environ.update(env_vars)
result = script.pip("config", "debug")
assert "PIP_DEFAULT_TIMEOUT='60'" in result.stdout
assert "PIP_FIND_LINKS='http://mirror.example.com'" in result.stdout
assert re.search(r"env_var:\n( .+\n)+", result.stdout)
def test_env_values(self, script):
"""Test that custom pip configuration using the environment variable
PIP_CONFIG_FILE is correctly displayed under "env". This configuration
takes place of per-user configuration file displayed under "user".
"""
config_file = script.scratch_path / "test-pip.cfg"
script.environ["PIP_CONFIG_FILE"] = str(config_file)
config_file.write_text(
textwrap.dedent(
"""\
[global]
timeout = 60
[freeze]
timeout = 10
"""
)
)
result = script.pip("config", "debug")
assert f"{config_file}, exists: True" in result.stdout
assert "global.timeout: 60" in result.stdout
assert "freeze.timeout: 10" in result.stdout
assert re.search(r"env:\n( .+\n)+", result.stdout)
def test_user_values(
self,
script,
):
"""Test that the user pip configuration set using --user
is correctly displayed under "user". This configuration takes place
of custom path location using the environment variable PIP_CONFIG_FILE
displayed under "env".
"""
# Use new config file
new_config_file = get_configuration_files()[kinds.USER][1]
script.pip("config", "--user", "set", "global.timeout", "60")
script.pip("config", "--user", "set", "freeze.timeout", "10")
result = script.pip("config", "debug")
assert f"{new_config_file}, exists: True" in result.stdout
assert "global.timeout: 60" in result.stdout
assert "freeze.timeout: 10" in result.stdout
assert re.search(r"user:\n( .+\n)+", result.stdout)
def test_site_values(self, script, virtualenv):
"""Test that the current environment configuration set using --site
is correctly displayed under "site".
"""
# Site config file will be inside the virtualenv
site_config_file = virtualenv.location / CONFIG_BASENAME
script.pip("config", "--site", "set", "global.timeout", "60")
script.pip("config", "--site", "set", "freeze.timeout", "10")
result = script.pip("config", "debug")
assert f"{site_config_file}, exists: True" in result.stdout
assert "global.timeout: 60" in result.stdout
assert "freeze.timeout: 10" in result.stdout
assert re.search(r"site:\n( .+\n)+", result.stdout)
def test_global_config_file(self, script):
"""Test that the system-wide configuration can be identified"""
# We cannot write to system-wide files which might have permissions
# defined in a way that the tox virtualenvcannot write to those
# locations. Additionally we cannot patch those paths since pip config
# commands runs inside a subprocess.
# So we just check if the file can be identified
global_config_file = get_configuration_files()[kinds.GLOBAL][0]
result = script.pip("config", "debug")
assert f"{global_config_file}, exists:" in result.stdout