53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
This program has been developed by students from the bachelor Computer Science at Utrecht
|
|
University within the Software Project course.
|
|
© Copyright Utrecht University (Department of Information and Computing Sciences)
|
|
"""
|
|
|
|
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
|