|
6 | 6 | from pydantic import ValidationError |
7 | 7 |
|
8 | 8 | from fastcs.attributes import AttrR, AttrRW |
| 9 | +from fastcs.backend import Backend |
9 | 10 | from fastcs.controller import Controller |
10 | 11 | from fastcs.datatypes import Bool, Enum, Float, Int, String |
11 | 12 | from fastcs.util import ( |
@@ -136,3 +137,26 @@ class ControllerWrongEnumClass(Controller): |
136 | 137 | "'hinted_enum' does not match defined datatype. " |
137 | 138 | "Expected 'MyEnum', got 'MyEnum2'." |
138 | 139 | ) |
| 140 | + |
| 141 | + |
| 142 | +def test_hinted_attributes_verified_on_subcontrollers(): |
| 143 | + loop = asyncio.get_event_loop() |
| 144 | + |
| 145 | + class ControllerWithWrongType(SubController): |
| 146 | + hinted_missing: AttrR[int] |
| 147 | + |
| 148 | + async def connect(self): |
| 149 | + return |
| 150 | + |
| 151 | + class TopController(Controller): |
| 152 | + async def initialise(self): |
| 153 | + subcontroller = ControllerWithWrongType() |
| 154 | + self.register_sub_controller("MySubController", subcontroller) |
| 155 | + |
| 156 | + with pytest.raises(RuntimeError) as excinfo: |
| 157 | + Backend(TopController(), loop) |
| 158 | + |
| 159 | + assert str(excinfo.value) == ( |
| 160 | + "Controller `ControllerWithWrongType` failed to introspect hinted attribute " |
| 161 | + "`hinted_missing` during initialisation" |
| 162 | + ) |
0 commit comments