Skip to content

Commit 4cf1a12

Browse files
author
James Souter
committed
fix tests after rebase
1 parent 3bc9bc4 commit 4cf1a12

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

tests/test_util.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import enum
23

34
import numpy as np
@@ -8,6 +9,7 @@
89
from fastcs.attributes import Attribute, AttrR, AttrRW
910
from fastcs.controller import Controller
1011
from fastcs.datatypes import Bool, Enum, Float, Int, String
12+
from fastcs.launch import FastCS
1113
from fastcs.util import (
1214
numpy_to_fastcs_datatype,
1315
snake_to_pascal,
@@ -137,15 +139,6 @@ class ControllerWrongEnumClass(Controller):
137139
"Expected 'MyEnum', got 'MyEnum2'."
138140
)
139141

140-
class ControllerUnspecifiedAccessMode(Controller):
141-
hinted: Attribute[int]
142-
143-
async def initialise(self):
144-
self.hinted = AttrR(Int())
145-
146-
# no assertion thrown
147-
FastCS(ControllerUnspecifiedAccessMode(), [], loop)
148-
149142

150143
def test_hinted_attributes_verified_on_subcontrollers():
151144
loop = asyncio.get_event_loop()
@@ -157,15 +150,16 @@ async def connect(self):
157150
return
158151

159152
class TopController(Controller):
160-
async def initialise(self):
153+
async def initialise(self): # why does this not get called?
161154
subcontroller = ControllerWithWrongType()
162-
self.register_sub_controller("MySubController", subcontroller)
155+
self.add_sub_controller("MySubController", subcontroller)
163156

157+
fastcs = FastCS(TopController(), [], loop)
164158
with pytest.raises(RuntimeError, match="failed to introspect hinted attribute"):
165-
FastCS(TopController(), [], loop)
159+
fastcs.run()
166160

167161

168-
def test_hinted_attribute_types_verified():
162+
def test_hinted_attribute_access_mode_verified():
169163
# test verification works with non-GenericAlias type hints
170164
loop = asyncio.get_event_loop()
171165

@@ -175,13 +169,20 @@ class ControllerAttrWrongAccessMode(Controller):
175169
async def initialise(self):
176170
self.read_attr = AttrRW(Int())
177171

172+
fastcs = FastCS(ControllerAttrWrongAccessMode(), [], loop)
178173
with pytest.raises(RuntimeError, match="does not match defined access mode"):
179-
FastCS(ControllerAttrWrongAccessMode(), [], loop)
174+
fastcs.run()
175+
180176

177+
@pytest.mark.asyncio
178+
async def test_hinted_attributes_with_unspecified_access_mode():
181179
class ControllerUnspecifiedAccessMode(Controller):
182180
unspecified_access_mode: Attribute
183181

184182
async def initialise(self):
185183
self.unspecified_access_mode = AttrRW(Int())
186184

187-
FastCS(ControllerUnspecifiedAccessMode(), [], loop)
185+
controller = ControllerUnspecifiedAccessMode()
186+
await controller.initialise()
187+
# no assertion thrown
188+
validate_hinted_attributes(controller)

0 commit comments

Comments
 (0)