add error messages
Some checks failed
Mypy / mypy (push) Failing after 1m10s
Pytest / pytest (3.12) (push) Successful in 1m17s
Pytest / pytest (3.13) (push) Successful in 1m12s
Pytest / pytest (3.14) (push) Successful in 1m13s
Ruff / ruff (push) Successful in 1m1s

This commit is contained in:
Justus Kuhlmann 2026-03-23 15:21:34 +01:00
commit 110ddaf3a1
Signed by: jkuhl
GPG key ID: 00ED992DD79B85A6
2 changed files with 14 additions and 3 deletions

View file

@ -119,6 +119,8 @@ def get_db_file(path: Path) -> str:
config = ConfigParser()
if os.path.exists(config_path):
config.read(config_path)
else:
raise FileNotFoundError("Configuration file not found.")
db_file = config.get('paths', 'db', fallback='backlogger.db')
return db_file
@ -142,6 +144,10 @@ def cache_enabled(path: Path) -> bool:
config = ConfigParser()
if os.path.exists(config_path):
config.read(config_path)
else:
raise FileNotFoundError("Configuration file not found.")
cached_str = config.get('core', 'cached', fallback='True')
if cached_str not in ['True', 'False']:
raise ValueError(f"String {cached_str} is not a valid option, only True and False are allowed!")
cached_bool = cached_str == ('True')
return cached_bool

View file

@ -2,6 +2,7 @@ from corrlib import tools as tl
from configparser import ConfigParser
import os
from pathlib import Path
import pytest
def test_m2k() -> None:
@ -74,7 +75,11 @@ def test_get_db_file(tmp_path: Path) -> None:
def test_cache_enabled(tmp_path: Path) -> None:
section = "core"
option = "cached"
value = "True"
# config is not yet available
tl.set_config(tmp_path, section, option, value)
assert tl.get_db_file(tmp_path)
tl.set_config(tmp_path, section, option, "True")
assert tl.cache_enabled(tmp_path)
tl.set_config(tmp_path, section, option, "False")
assert not tl.cache_enabled(tmp_path)
tl.set_config(tmp_path, section, option, "lalala")
with pytest.raises(ValueError) as e_info:
tl.cache_enabled(tmp_path)