1515
1616from dodal .devices .robot import (
1717 SAMPLE_LOCATION_EMPTY ,
18- WAIT_FOR_NEW_PIN_MSG ,
19- WAIT_FOR_OLD_PIN_MSG ,
18+ WAIT_FOR_BEAMLINE_DISABLE_MSG ,
19+ WAIT_FOR_BEAMLINE_ENABLE_MSG ,
2020 BartRobot ,
21+ BeamlineStatus ,
2122 PinMounted ,
2223 RobotLoadError ,
2324 SampleLocation ,
@@ -36,14 +37,18 @@ async def robot_for_unload():
3637
3738 async def finish_later ():
3839 await drying_complete .wait ()
40+ await asyncio .sleep (0.1 )
3941 set_mock_value (device .program_running , False )
42+ set_mock_value (device .beamline_disabled , BeamlineStatus .ENABLED .value )
4043
4144 async def fake_unload (* args , ** kwargs ):
4245 set_mock_value (device .program_running , True )
46+ set_mock_value (device .beamline_disabled , BeamlineStatus .DISABLED .value )
4347 await trigger_complete .wait ()
4448 asyncio .create_task (finish_later ())
4549
4650 get_mock_put (device .unload ).side_effect = fake_unload
51+ # device.unload.trigger = AsyncMock(side_effect=fake_unload)
4752 return device , trigger_complete , drying_complete
4853
4954
@@ -52,6 +57,7 @@ async def _get_bart_robot() -> BartRobot:
5257 device .LOAD_TIMEOUT = 1 # type: ignore
5358 device .NOT_BUSY_TIMEOUT = 1 # type: ignore
5459 await device .connect (mock = True )
60+ # set_mock_value(device.beamline_disabled, BeamlineStatus.DISABLED.value)
5561 return device
5662
5763
@@ -109,7 +115,7 @@ async def test_given_program_not_running_but_pin_not_unmounting_when_load_pin_th
109115 await device .set (SampleLocation (15 , 10 ))
110116 device .load .trigger .assert_called_once () # type:ignore
111117 last_log = patch_logger .mock_calls [1 ].args [0 ]
112- assert "Waiting on old pin unloaded" in last_log
118+ assert WAIT_FOR_BEAMLINE_DISABLE_MSG in last_log
113119
114120
115121@patch ("dodal.devices.robot.LOGGER" )
@@ -127,34 +133,34 @@ async def test_given_program_not_running_and_pin_unmounting_but_new_pin_not_moun
127133 try :
128134 device .load .trigger .assert_called_once () # type:ignore
129135 last_log = patch_logger .mock_calls [1 ].args [0 ]
130- assert "Waiting on new pin loaded" in last_log
136+ assert WAIT_FOR_BEAMLINE_DISABLE_MSG in last_log
131137 except AssertionError :
132138 traceback .print_exception (exc_info .value )
133139 raise
134140
135141
136- def _set_pin_sensor_on_log_messages (device : BartRobot , msg : str ):
137- if msg == WAIT_FOR_OLD_PIN_MSG :
138- set_mock_value (device .gonio_pin_sensor , PinMounted . NO_PIN_MOUNTED )
139- elif msg == WAIT_FOR_NEW_PIN_MSG :
140- set_mock_value (device .gonio_pin_sensor , PinMounted . PIN_MOUNTED )
142+ def _set_beamline_enabled_on_log_messages (device : BartRobot , msg : str ):
143+ if msg == WAIT_FOR_BEAMLINE_DISABLE_MSG :
144+ set_mock_value (device .beamline_disabled , BeamlineStatus . DISABLED . value )
145+ elif msg == WAIT_FOR_BEAMLINE_ENABLE_MSG :
146+ set_mock_value (device .beamline_disabled , BeamlineStatus . ENABLED . value )
141147
142148
143149def _error_on_unload_log_messages (device : BartRobot , msg : str ):
144- if msg == WAIT_FOR_OLD_PIN_MSG :
150+ if msg == WAIT_FOR_BEAMLINE_DISABLE_MSG :
145151 set_mock_value (device .prog_error .code , 40 )
146152 set_mock_value (device .prog_error .str , "Test error" )
147153
148154
149- # Use log info messages to determine when to set the gonio_pin_sensor , so we don't have to use any sleeps during testing
155+ # Use log info messages to determine when to set the beamline enable , so we don't have to use any sleeps during testing
150156async def set_with_happy_path (
151157 device : BartRobot , mock_log_info : MagicMock
152158) -> AsyncStatus :
153159 """Mocks the logic that the robot would do on a successful load"""
154160
155- mock_log_info .side_effect = partial (_set_pin_sensor_on_log_messages , device )
161+ mock_log_info .side_effect = partial (_set_beamline_enabled_on_log_messages , device )
156162 set_mock_value (device .program_running , False )
157- set_mock_value (device .gonio_pin_sensor , PinMounted . PIN_MOUNTED )
163+ set_mock_value (device .beamline_disabled , BeamlineStatus . ENABLED . value )
158164 status = device .set (SampleLocation (15 , 10 ))
159165 return status
160166
@@ -166,7 +172,7 @@ async def set_with_unhappy_path(
166172
167173 mock_log_info .side_effect = partial (_error_on_unload_log_messages , device )
168174 set_mock_value (device .program_running , False )
169- set_mock_value (device .gonio_pin_sensor , PinMounted . PIN_MOUNTED )
175+ set_mock_value (device .beamline_disabled , BeamlineStatus . ENABLED . value )
170176 status = device .set (SampleLocation (15 , 10 ))
171177 return status
172178
@@ -187,15 +193,16 @@ async def test_given_program_not_running_and_pin_unmounts_then_mounts_when_load_
187193async def test_given_waiting_for_pin_to_mount_when_no_pin_mounted_then_error_raised ():
188194 device = await _get_bart_robot ()
189195 set_mock_value (device .prog_error .code , 25 )
190- status = device .pin_state_or_error ()
196+ set_mock_value (device .beamline_disabled , BeamlineStatus .DISABLED .value )
197+ status = device .beamline_status_or_error (BeamlineStatus .ENABLED )
191198 with pytest .raises (RobotLoadError ):
192199 await status
193200
194201
195- async def test_given_waiting_for_pin_to_mount_when_pin_mounted_then_no_error_raised ():
202+ async def test_given_waiting_for_beamline_to_enable_when_beamline_enabled_then_no_error_raised ():
196203 device = await _get_bart_robot ()
197- status = create_task (device .pin_state_or_error ( ))
198- set_mock_value (device .gonio_pin_sensor , PinMounted . PIN_MOUNTED )
204+ status = create_task (device .beamline_status_or_error ( BeamlineStatus . ENABLED ))
205+ set_mock_value (device .beamline_disabled , BeamlineStatus . ENABLED . value )
199206 await status
200207
201208
0 commit comments