41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
import tomllib
|
|
|
|
import tomli_w
|
|
|
|
from delta_barth import config
|
|
|
|
|
|
def test_CfgLoader_Init(pth_cfg):
|
|
loader = config.LazyCfgLoader(pth_cfg)
|
|
|
|
assert loader.path == pth_cfg
|
|
assert loader._cfg is None
|
|
|
|
|
|
def test_CfgLoader_Get(pth_cfg):
|
|
loader = config.LazyCfgLoader(pth_cfg)
|
|
|
|
parsed_cfg = loader.get()
|
|
assert isinstance(parsed_cfg, config.Config)
|
|
assert parsed_cfg.forecast.threshold_month_data_points == 28
|
|
|
|
|
|
def test_CfgLoader_Reload(pth_cfg):
|
|
loader = config.LazyCfgLoader(pth_cfg)
|
|
|
|
parsed_cfg = loader.get()
|
|
assert isinstance(parsed_cfg, config.Config)
|
|
assert parsed_cfg.forecast.threshold_month_data_points == 28
|
|
# modify config and reload
|
|
with open(pth_cfg, "rb") as file:
|
|
cfg_data = tomllib.load(file)
|
|
cfg_data["forecast"]["threshold_month_data_points"] = 30
|
|
with open(pth_cfg, "wb") as file:
|
|
tomli_w.dump(cfg_data, file)
|
|
|
|
assert parsed_cfg.forecast.threshold_month_data_points == 28
|
|
loader.reload()
|
|
parsed_cfg = loader.get()
|
|
assert isinstance(parsed_cfg, config.Config)
|
|
assert parsed_cfg.forecast.threshold_month_data_points == 30
|