File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,9 @@ def get_value(self, key: str) -> Any:
147
147
try :
148
148
return self ._dictionary [key ]
149
149
except KeyError :
150
+ # disassembling triggers a more useful error message than simply
151
+ # "No such key" in the case that the key isn't in the form command.option
152
+ _disassemble_key (key )
150
153
raise ConfigurationError (f"No such key - { orig_key } " )
151
154
152
155
def set_value (self , key : str , value : Any ) -> None :
Original file line number Diff line number Diff line change 1
1
"""Tests for all things related to the configuration
2
2
"""
3
3
4
+ import re
4
5
from unittest .mock import MagicMock
5
6
6
7
import pytest
@@ -87,6 +88,25 @@ def test_environment_config_errors_if_malformed(
87
88
err .value
88
89
)
89
90
91
+ def test_no_such_key_error_message_no_command (self ) -> None :
92
+ self .configuration .load_only = kinds .GLOBAL
93
+ self .configuration .load ()
94
+ expected_msg = (
95
+ "Key does not contain dot separated section and key. "
96
+ "Perhaps you wanted to use 'global.index-url' instead?"
97
+ )
98
+ pat = f"^{ re .escape (expected_msg )} $"
99
+ with pytest .raises (ConfigurationError , match = pat ):
100
+ self .configuration .get_value ("index-url" )
101
+
102
+ def test_no_such_key_error_message_missing_option (self ) -> None :
103
+ self .configuration .load_only = kinds .GLOBAL
104
+ self .configuration .load ()
105
+ expected_msg = "No such key - global.index-url"
106
+ pat = f"^{ re .escape (expected_msg )} $"
107
+ with pytest .raises (ConfigurationError , match = pat ):
108
+ self .configuration .get_value ("global.index-url" )
109
+
90
110
91
111
class TestConfigurationPrecedence (ConfigurationMixin ):
92
112
# Tests for methods to that determine the order of precedence of
You can’t perform that action at this time.
0 commit comments