From 5084bb7b509393d2364714b3020911c973c0ce45 Mon Sep 17 00:00:00 2001 From: Zain Sohail Date: Tue, 14 Jan 2025 12:30:35 +0100 Subject: [PATCH] use value error --- src/sed/core/config.py | 15 ++------------- tests/test_config.py | 9 ++++----- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/sed/core/config.py b/src/sed/core/config.py index 5cf8b2c8..d686a891 100644 --- a/src/sed/core/config.py +++ b/src/sed/core/config.py @@ -24,17 +24,6 @@ logger = setup_logging("config") -class ConfigError(Exception): - """Exception raised for errors in the config file.""" - - def __init__(self, message: str): - self.message = message - super().__init__(self.message) - - def __str__(self): - return self.message - - def parse_config( config: dict | str = None, folder_config: dict | str = None, @@ -73,7 +62,7 @@ def parse_config( Raises: TypeError: Raised if the provided file is neither *json* nor *yaml*. FileNotFoundError: Raised if the provided file is not found. - ConfigError: Raised if there is a validation error in the config file. + ValueError: Raised if there is a validation error in the config file. Returns: dict: Loaded and completed config dict, possibly verified by pydantic config model. @@ -171,7 +160,7 @@ def parse_config( for error in e.errors(): error_msg += f"\n- {' -> '.join(str(loc) for loc in error['loc'])}: {error['msg']}" logger.error(error_msg) - raise ConfigError(error_msg) from e + raise ValueError(error_msg) from e def load_config(config_path: str) -> dict: diff --git a/tests/test_config.py b/tests/test_config.py index a6569246..8545f64b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -10,7 +10,6 @@ import pytest from sed.core.config import complete_dictionary -from sed.core.config import ConfigError from sed.core.config import load_config from sed.core.config import parse_config from sed.core.config import save_config @@ -168,7 +167,7 @@ def test_invalid_config_extra_field(): ) invalid_config = default_config.copy() invalid_config["extra_field"] = "extra_value" - with pytest.raises(ConfigError): + with pytest.raises(ValueError): parse_config( invalid_config, folder_config={}, @@ -188,7 +187,7 @@ def test_invalid_config_missing_field(): ) invalid_config = default_config.copy() del invalid_config["core"]["loader"] - with pytest.raises(ConfigError): + with pytest.raises(ValueError): parse_config( folder_config={}, user_config={}, @@ -208,7 +207,7 @@ def test_invalid_config_wrong_values(): ) invalid_config = default_config.copy() invalid_config["core"]["loader"] = "nonexistent" - with pytest.raises(ConfigError) as e: + with pytest.raises(ValueError) as e: parse_config( folder_config={}, user_config={}, @@ -222,7 +221,7 @@ def test_invalid_config_wrong_values(): invalid_config["core"]["copy_tool"]["source"] = "./" invalid_config["core"]["copy_tool"]["dest"] = "./" invalid_config["core"]["copy_tool"]["gid"] = 9999 - with pytest.raises(ConfigError) as e: + with pytest.raises(ValueError) as e: parse_config( folder_config={}, user_config={},