pip/tests/functional/test_configuration.py

59 lines
1.7 KiB
Python
Raw Normal View History

"""Tests for the config command
"""
2017-05-14 09:15:22 +02:00
import pytest
import textwrap
from pip.status_codes import ERROR
from tests.lib.configuration_helpers import kinds, ConfigurationFileIOMixin
def test_no_options_passed_should_error(script):
result = script.pip('config', expect_error=True)
assert result.returncode == ERROR
class TestBasicLoading(ConfigurationFileIOMixin):
2017-05-14 09:15:22 +02:00
@pytest.mark.skip("Can't modify underlying file for any mode")
def test_reads_file_appropriately(self, script):
contents = """
[test]
hello = 1
"""
with self.patched_file(kinds.USER, contents):
2017-05-14 09:15:22 +02:00
result = script.pip("config", "list")
assert "test.hello=1" in result.stdout
def test_modification_pipeline(self, script):
2017-05-14 09:27:39 +02:00
script.pip("config", "get", "test.blah", expect_error=True)
2017-05-14 09:15:22 +02:00
script.pip("config", "set", "test.blah", "1")
2017-05-14 09:27:39 +02:00
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)
2017-05-14 09:15:22 +02:00
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'
"""
2017-05-14 09:15:22 +02:00
assert lines == textwrap.dedent(expected).strip().splitlines()