diff --git a/corrlib/tools.py b/corrlib/tools.py index 72112c5..727ed30 100644 --- a/corrlib/tools.py +++ b/corrlib/tools.py @@ -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 diff --git a/tests/tools_test.py b/tests/tools_test.py index 0399be0..9be88b4 100644 --- a/tests/tools_test.py +++ b/tests/tools_test.py @@ -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)