mirror of https://github.com/pypa/pip
provide a better error message for "pip config get index-url"
This commit is contained in:
parent
6efe70858c
commit
32f642d123
|
@ -147,6 +147,9 @@ class Configuration:
|
||||||
try:
|
try:
|
||||||
return self._dictionary[key]
|
return self._dictionary[key]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
# disassembling triggers a more useful error message than simply
|
||||||
|
# "No such key" in the case that the key isn't in the form command.option
|
||||||
|
_disassemble_key(key)
|
||||||
raise ConfigurationError(f"No such key - {orig_key}")
|
raise ConfigurationError(f"No such key - {orig_key}")
|
||||||
|
|
||||||
def set_value(self, key: str, value: Any) -> None:
|
def set_value(self, key: str, value: Any) -> None:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""Tests for all things related to the configuration
|
"""Tests for all things related to the configuration
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -87,6 +88,25 @@ class TestConfigurationLoading(ConfigurationMixin):
|
||||||
err.value
|
err.value
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_no_such_key_error_message_no_command(self) -> None:
|
||||||
|
self.configuration.load_only = kinds.GLOBAL
|
||||||
|
self.configuration.load()
|
||||||
|
expected_msg = (
|
||||||
|
"Key does not contain dot separated section and key. "
|
||||||
|
"Perhaps you wanted to use 'global.index-url' instead?"
|
||||||
|
)
|
||||||
|
pat = f"^{re.escape(expected_msg)}$"
|
||||||
|
with pytest.raises(ConfigurationError, match=pat):
|
||||||
|
self.configuration.get_value("index-url")
|
||||||
|
|
||||||
|
def test_no_such_key_error_message_missing_option(self) -> None:
|
||||||
|
self.configuration.load_only = kinds.GLOBAL
|
||||||
|
self.configuration.load()
|
||||||
|
expected_msg = "No such key - global.index-url"
|
||||||
|
pat = f"^{re.escape(expected_msg)}$"
|
||||||
|
with pytest.raises(ConfigurationError, match=pat):
|
||||||
|
self.configuration.get_value("global.index-url")
|
||||||
|
|
||||||
|
|
||||||
class TestConfigurationPrecedence(ConfigurationMixin):
|
class TestConfigurationPrecedence(ConfigurationMixin):
|
||||||
# Tests for methods to that determine the order of precedence of
|
# Tests for methods to that determine the order of precedence of
|
||||||
|
|
Loading…
Reference in New Issue