6
6
from pvi .device import SignalR
7
7
from pydantic import ValidationError
8
8
9
- from fastcs .attributes import AttrR , AttrRW
9
+ from fastcs .attributes import Attribute , AttrR , AttrRW
10
10
from fastcs .backend import Backend
11
11
from fastcs .controller import Controller , SubController
12
12
from fastcs .datatypes import Bool , Enum , Float , Int , String
@@ -125,6 +125,15 @@ class ControllerWrongEnumClass(Controller):
125
125
"Expected 'MyEnum', got 'MyEnum2'."
126
126
)
127
127
128
+ class ControllerUnspecifiedAccessMode (Controller ):
129
+ hinted : Attribute [int ]
130
+
131
+ async def initialise (self ):
132
+ self .hinted = AttrR (Int ())
133
+
134
+ # no assertion thrown
135
+ Backend (ControllerUnspecifiedAccessMode (), loop )
136
+
128
137
129
138
def test_hinted_attributes_verified_on_subcontrollers ():
130
139
loop = asyncio .get_event_loop ()
@@ -142,3 +151,25 @@ async def initialise(self):
142
151
143
152
with pytest .raises (RuntimeError , match = "failed to introspect hinted attribute" ):
144
153
Backend (TopController (), loop )
154
+
155
+
156
+ def test_hinted_attribute_types_verified ():
157
+ # test verification works with non-GenericAlias type hints
158
+ loop = asyncio .get_event_loop ()
159
+
160
+ class ControllerAttrWrongAccessMode (Controller ):
161
+ read_attr : AttrR
162
+
163
+ async def initialise (self ):
164
+ self .read_attr = AttrRW (Int ())
165
+
166
+ with pytest .raises (RuntimeError , match = "does not match defined access mode" ):
167
+ Backend (ControllerAttrWrongAccessMode (), loop )
168
+
169
+ class ControllerUnspecifiedAccessMode (Controller ):
170
+ unspecified_access_mode : Attribute
171
+
172
+ async def initialise (self ):
173
+ self .unspecified_access_mode = AttrRW (Int ())
174
+
175
+ Backend (ControllerUnspecifiedAccessMode (), loop )
0 commit comments