feat: add environment variables and docs
ref: N25B-352
This commit is contained in:
45
test/unit/test_get_config.py
Normal file
45
test/unit/test_get_config.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from robot_interface.utils.get_config import get_config
|
||||
|
||||
|
||||
def test_get_config_prefers_explicit_value(monkeypatch):
|
||||
"""
|
||||
When a direct value is provided it should be returned without reading the environment.
|
||||
"""
|
||||
monkeypatch.setenv("GET_CONFIG_TEST", "from-env")
|
||||
|
||||
result = get_config("explicit", "GET_CONFIG_TEST", "default")
|
||||
|
||||
assert result == "explicit"
|
||||
|
||||
|
||||
def test_get_config_returns_env_value(monkeypatch):
|
||||
"""
|
||||
If value is None the environment variable should be used.
|
||||
"""
|
||||
monkeypatch.setenv("GET_CONFIG_TEST", "from-env")
|
||||
|
||||
result = get_config(None, "GET_CONFIG_TEST", "default")
|
||||
|
||||
assert result == "from-env"
|
||||
|
||||
|
||||
def test_get_config_casts_env_value(monkeypatch):
|
||||
"""
|
||||
The env value should be cast when a cast function is provided.
|
||||
"""
|
||||
monkeypatch.setenv("GET_CONFIG_PORT", "1234")
|
||||
|
||||
result = get_config(None, "GET_CONFIG_PORT", 0, int)
|
||||
|
||||
assert result == 1234
|
||||
|
||||
|
||||
def test_get_config_casts_default_when_env_missing(monkeypatch):
|
||||
"""
|
||||
When the env var is missing it should fall back to the default and still apply the cast.
|
||||
"""
|
||||
monkeypatch.delenv("GET_CONFIG_MISSING", raising=False)
|
||||
|
||||
result = get_config(None, "GET_CONFIG_MISSING", "42", int)
|
||||
|
||||
assert result == 42
|
||||
Reference in New Issue
Block a user