tests: improve tests / error handling
This commit is contained in:
@@ -18,3 +18,6 @@ class GuiOption(str, Enum):
|
||||
NEW = "new"
|
||||
EXISTING = "existing"
|
||||
NONE = "none"
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.value
|
||||
|
||||
@@ -2,3 +2,9 @@ class UVError(Exception):
|
||||
"""Raised when running uv yields an exception"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class InvalidCliOptions(Exception):
|
||||
"""Raised when running a CLI command with invalid CLI Options"""
|
||||
|
||||
pass
|
||||
|
||||
@@ -3,6 +3,7 @@ from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
|
||||
from core.enums import GuiOption
|
||||
from core.exceptions import InvalidCliOptions
|
||||
from models import ServiceRegistry
|
||||
|
||||
|
||||
@@ -22,6 +23,17 @@ class GuiConfig(BaseModel):
|
||||
|
||||
def assert_valid(self, service_registry: ServiceRegistry):
|
||||
if self.gui_option == GuiOption.EXISTING:
|
||||
service_registry.assert_service_exists(self.ui_filename)
|
||||
if self.raw_ui_filename is None:
|
||||
raise InvalidCliOptions(
|
||||
f"Must specify --ui-filename when --gui-option is {GuiOption.EXISTING}"
|
||||
)
|
||||
try:
|
||||
service_registry.assert_service_exists(self.ui_filename)
|
||||
except Exception as e:
|
||||
raise InvalidCliOptions(
|
||||
f"Could not find service with name {self.ui_filename} in service_registry."
|
||||
) from e
|
||||
if self.gui_option == GuiOption.NONE and self.raw_ui_filename:
|
||||
raise ValueError("Cannot specify --ui-filename when --gui-option is 'none'.")
|
||||
raise InvalidCliOptions(
|
||||
f"Cannot specify --ui-filename when --gui-option is {GuiOption.NONE}"
|
||||
)
|
||||
|
||||
@@ -9,6 +9,7 @@ from pytest_mock import MockerFixture
|
||||
from agebd.utils import get_git_root
|
||||
from config.paths import Paths
|
||||
from core.enums import GuiOption
|
||||
from core.exceptions import InvalidCliOptions
|
||||
from core.git import GitRepoManager
|
||||
from core.service_creator import ServiceCreator
|
||||
from models.context import ServicesContext
|
||||
@@ -99,7 +100,7 @@ def test_raise_if_gui_options_invalid(gui_option, raw_ui_filename, mocker):
|
||||
|
||||
gui_config = GuiConfig(gui_option=gui_option, raw_ui_filename=raw_ui_filename)
|
||||
creator = ServiceCreator(ctx=ctx, repo_manager=mocker.Mock(spec=GitRepoManager))
|
||||
with pytest.raises(ValueError):
|
||||
with pytest.raises(InvalidCliOptions):
|
||||
creator.add_service(
|
||||
name="BlaBla",
|
||||
ioc_owner="test_user",
|
||||
|
||||
Reference in New Issue
Block a user