Skip to content

Commit

Permalink
Add a more specific error type regarding the invalid config type names.
Browse files Browse the repository at this point in the history
Related #105
  • Loading branch information
aholmes committed Sep 9, 2024
1 parent 321431e commit 40c64c9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/programming/BL_Python/programming/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from BL_Python.programming.collections.dict import AnyDict, merge
from BL_Python.programming.config.exceptions import (
ConfigBuilderStateError,
InvalidConfigNameError,
NotEndsWithConfigError,
)

TConfig = TypeVar("TConfig")
Expand Down Expand Up @@ -44,7 +44,7 @@ def build(self) -> type[TConfig]:

for config in self._configs:
if not config.__name__.endswith("Config"):
raise InvalidConfigNameError(
raise NotEndsWithConfigError(
f"Class name '{config.__name__}' is not a valid config class. The name must end with 'Config'"
)

Expand Down
6 changes: 5 additions & 1 deletion src/programming/BL_Python/programming/config/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
class InvalidConfigNameError(Exception):
"""The class name used as a configuration type is invalid. The name must end with `Config`."""
"""The class name used as a configuration type is invalid."""


class NotEndsWithConfigError(InvalidConfigNameError):
"""The name must end with `Config`."""


class ConfigBuilderStateError(Exception):
Expand Down
4 changes: 2 additions & 2 deletions src/programming/test/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from BL_Python.programming.config import AbstractConfig, ConfigBuilder, load_config
from BL_Python.programming.config.exceptions import (
ConfigBuilderStateError,
InvalidConfigNameError,
NotEndsWithConfigError,
)
from pydantic import BaseModel
from pytest_mock import MockerFixture
Expand Down Expand Up @@ -72,7 +72,7 @@ def test__ConfigBuilder__build__raises_error_when_no_root_config_and_no_section_
def test__ConfigBuilder__build__raises_error_when_section_class_name_is_invalid():
config_builder = ConfigBuilder[TestConfig]()
_ = config_builder.with_configs([InvalidConfigClass])
with pytest.raises(InvalidConfigNameError):
with pytest.raises(NotEndsWithConfigError):
_ = config_builder.build()


Expand Down

0 comments on commit 40c64c9

Please sign in to comment.