add error messages
This commit is contained in:
parent
97e30fa27d
commit
110ddaf3a1
2 changed files with 14 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue