Skip to content

Commit

Permalink
Improve coverage in register_sub_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
GDYendell committed Jul 24, 2024
1 parent df4bfad commit a31a9c2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/fastcs/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def _bind_attrs(self) -> None:
def register_sub_controller(self, name: str, sub_controller: SubController):
if name in self.__sub_controller_tree.keys():
raise ValueError(
f"Controller {self} already has a sub controller registered as {name}"
f"Controller {self} already has a SubController registered as {name}"
)
if sub_controller.path:
raise ValueError(
f"Sub controller is already registered under {sub_controller.path}"
f"SubController is already registered under {sub_controller.path}"
)

self.__sub_controller_tree[name] = sub_controller
Expand Down
12 changes: 12 additions & 0 deletions tests/test_controller.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from fastcs.controller import Controller, SubController
from fastcs.mapping import _get_single_mapping, _walk_mappings

Expand All @@ -17,3 +19,13 @@ def test_controller_nesting():
_get_single_mapping(sub_controller),
_get_single_mapping(sub_sub_controller),
]

with pytest.raises(
ValueError, match=r"Controller .* already has a SubController registered as .*"
):
controller.register_sub_controller("a", SubController())

with pytest.raises(
ValueError, match=r"SubController is already registered under .*"
):
controller.register_sub_controller("c", sub_controller)

0 comments on commit a31a9c2

Please sign in to comment.