Skip to content

Commit eec63cb

Browse files
committed
Update regex for RE_REFERENCE in BaseConfig and add tests for reference resolution in DummyConfig
1 parent 550b0f5 commit eec63cb

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

config/config/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class BaseConfig(ABC):
2828
This class provides methods to load, save, and manage configuration settings.
2929
It is designed to be subclassed for specific configuration formats (e.g., JSON, YAML).
3030
"""
31-
RE_REFERENCE = re.compile(r'^\$\{([a-zA-Z0-9_.]+)\}$')
31+
RE_REFERENCE = re.compile(r'\$\{([a-zA-Z0-9_.]+)\}')
3232

3333
def __init__(self):
3434
self._config : Dict[str, Any] = {}

config/tests/base_tests.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,26 @@ def test_remove_errors(initial, key, test_id):
174174

175175
with pytest.raises(KeyError):
176176
config.remove(key)
177+
178+
179+
def test_set_reference():
180+
# Arrange
181+
182+
config = DummyConfig({
183+
"foo": "${bar}",
184+
"bar": 42,
185+
"baz" : {
186+
"qux": "${foo}",
187+
"value": 69
188+
},
189+
"test": "${baz.value}",
190+
"complex": "${baz.value}.01"
191+
})
192+
193+
# Assert
194+
195+
assert config.get("foo") == "42"
196+
assert config.get("bar") == 42
197+
assert config.get("baz.qux") == "42"
198+
assert config.get("test") == "69"
199+
assert config.get("complex") == "69.01"

0 commit comments

Comments
 (0)