Skip to content

Commit

Permalink
Add mocks for mirror_cover_locks_motion_state and update mirror cover…
Browse files Browse the repository at this point in the history
… unit tests.
  • Loading branch information
edennihy committed Nov 19, 2024
1 parent 876a1a5 commit fb920d5
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 40 deletions.
93 changes: 53 additions & 40 deletions python/lsst/ts/observatory/control/mock/mtcs_async_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ async def setup_types(self) -> None:
self._mtmount_evt_mirror_covers_motion_state = types.SimpleNamespace(
state=xml.enums.MTMount.DeployableMotionState.DEPLOYED
)

self._mtmount_evt_mirror_cover_locks_motion_state = types.SimpleNamespace(
state=xml.enums.MTMount.DeployableMotionState.DEPLOYED
)

self._mtmount_evt_mirror_covers_system_state = types.SimpleNamespace(
state=xml.enums.MTMount.PowerState.ON
)
Expand Down Expand Up @@ -225,6 +230,9 @@ async def setup_mtmount(self) -> None:
"evt_mirrorCoversSystemState.aget.side_effect": self.mtmount_evt_mirror_covers_system_state,
"cmd_closeMirrorCovers.start.side_effect": self.mtmount_cmd_close_mirror_covers,
"cmd_openMirrorCovers.set_start.side_effect": self.mtmount_cmd_open_mirror_covers,
"evt_mirrorCoverLocksMotionState.aget.side_effect": (
self.mtmount_evt_mirror_cover_locks_motion_state
),
}

self.mtcs.rem.mtmount.configure_mock(**mtmount_mocks)
Expand Down Expand Up @@ -285,59 +293,59 @@ async def setup_mtm1m3(self) -> None:

# Compatibility with xml>12
if "evt_appliedBalanceForces" in self.components_metadata["MTM1M3"].topics:
m1m3_mocks["evt_appliedBalanceForces.next.side_effect"] = (
self.mtm1m3_evt_applied_balance_forces
)
m1m3_mocks["evt_appliedBalanceForces.aget.side_effect"] = (
self.mtm1m3_evt_applied_balance_forces
)
m1m3_mocks[
"evt_appliedBalanceForces.next.side_effect"
] = self.mtm1m3_evt_applied_balance_forces
m1m3_mocks[
"evt_appliedBalanceForces.aget.side_effect"
] = self.mtm1m3_evt_applied_balance_forces
else:
m1m3_mocks["tel_appliedBalanceForces.next.side_effect"] = (
self.mtm1m3_evt_applied_balance_forces
)
m1m3_mocks["tel_appliedBalanceForces.aget.side_effect"] = (
self.mtm1m3_evt_applied_balance_forces
)
m1m3_mocks[
"tel_appliedBalanceForces.next.side_effect"
] = self.mtm1m3_evt_applied_balance_forces
m1m3_mocks[
"tel_appliedBalanceForces.aget.side_effect"
] = self.mtm1m3_evt_applied_balance_forces

# Compatibility with xml>16
if "evt_forceControllerState" in self.components_metadata["MTM1M3"].topics:
m1m3_mocks["evt_forceControllerState.aget.side_effect"] = (
self.mtm1m3_evt_force_actuator_state
)
m1m3_mocks["evt_forceControllerState.next.side_effect"] = (
self.mtm1m3_evt_force_actuator_state
)
m1m3_mocks[
"evt_forceControllerState.aget.side_effect"
] = self.mtm1m3_evt_force_actuator_state
m1m3_mocks[
"evt_forceControllerState.next.side_effect"
] = self.mtm1m3_evt_force_actuator_state

if "evt_boosterValveStatus" in self.components_metadata["MTM1M3"].topics:
m1m3_mocks["evt_boosterValveStatus.aget.side_effect"] = (
self.mtm1m3_evt_force_actuator_state
)
m1m3_mocks["evt_boosterValveStatus.next.side_effect"] = (
self.mtm1m3_evt_force_actuator_state
)
m1m3_mocks[
"evt_boosterValveStatus.aget.side_effect"
] = self.mtm1m3_evt_force_actuator_state
m1m3_mocks[
"evt_boosterValveStatus.next.side_effect"
] = self.mtm1m3_evt_force_actuator_state

if "cmd_setAirSlewFlag" in self.components_metadata["MTM1M3"].topics:
m1m3_mocks["cmd_setAirSlewFlag.set_start.side_effect"] = (
self.mtm1m3_cmd_set_air_slew_flag
)
m1m3_mocks[
"cmd_setAirSlewFlag.set_start.side_effect"
] = self.mtm1m3_cmd_set_air_slew_flag

if "cmd_setSlewFlag" in self.components_metadata["MTM1M3"].topics:
m1m3_mocks["cmd_setSlewFlag.set_start.side_effect"] = (
self.mtm1m3_cmd_set_slew_flag
)
m1m3_mocks[
"cmd_setSlewFlag.set_start.side_effect"
] = self.mtm1m3_cmd_set_slew_flag

if "cmd_clearSlewFlag" in self.components_metadata["MTM1M3"].topics:
m1m3_mocks["cmd_clearSlewFlag.set_start.side_effect"] = (
self.mtm1m3_cmd_clear_slew_flag
)
m1m3_mocks[
"cmd_clearSlewFlag.set_start.side_effect"
] = self.mtm1m3_cmd_clear_slew_flag

if "cmd_boosterValveOpen" in self.components_metadata["MTM1M3"].topics:
m1m3_mocks["cmd_boosterValveOpen.start.side_effect"] = (
self.mtm1m3_cmd_booster_valve_open
)
m1m3_mocks["cmd_boosterValveClose.start.side_effect"] = (
self.mtm1m3_cmd_booster_valve_close
)
m1m3_mocks[
"cmd_boosterValveOpen.start.side_effect"
] = self.mtm1m3_cmd_booster_valve_open
m1m3_mocks[
"cmd_boosterValveClose.start.side_effect"
] = self.mtm1m3_cmd_booster_valve_close

self.mtcs.rem.mtm1m3.configure_mock(**m1m3_mocks)

Expand Down Expand Up @@ -389,7 +397,6 @@ async def setup_mthexapod_2(self) -> None:
self.mtcs.rem.mthexapod_2.configure_mock(**hexapod_2_mocks)

async def setup_mtaos(self) -> None:

offset_dof_field_info = self.get_sample("MTAOS", "cmd_offsetDOF")
mtaos_mocks = {
"cmd_offsetDOF.DataType.return_value": types.SimpleNamespace(
Expand Down Expand Up @@ -450,6 +457,12 @@ async def mtmount_evt_mirror_covers_motion_state(
await asyncio.sleep(self.heartbeat_time)
return self._mtmount_evt_mirror_covers_motion_state

async def mtmount_evt_mirror_cover_locks_motion_state(
self, *args: typing.Any, **kwargs: typing.Any
) -> types.SimpleNamespace:
await asyncio.sleep(self.heartbeat_time)
return self._mtmount_evt_mirror_cover_locks_motion_state

async def mtmount_evt_mirror_covers_system_state(
self, *args: typing.Any, **kwargs: typing.Any
) -> types.SimpleNamespace:
Expand Down
32 changes: 32 additions & 0 deletions tests/maintel/test_mtcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,10 @@ async def test_close_m1_cover_when_deployed(self) -> None:
idl.enums.MTMount.DeployableMotionState.DEPLOYED
)

self._mtmount_evt_mirror_cover_locks_motion_state.state = (
idl.enums.MTMount.DeployableMotionState.DEPLOYED
)

await self.mtcs.close_m1_cover()

self.mtcs.rem.mtptg.cmd_azElTarget.set.assert_not_called()
Expand All @@ -903,6 +907,10 @@ async def test_close_m1_cover_when_retracted(self) -> None:
self._mtmount_evt_mirror_covers_motion_state.state = (
idl.enums.MTMount.DeployableMotionState.RETRACTED
)
self._mtmount_evt_mirror_cover_locks_motion_state.state = (
idl.enums.MTMount.DeployableMotionState.RETRACTED
)

# Safe elevation for mirror covers operation
self._mtmount_tel_elevation.actualPosition = (
self.mtcs.tel_operate_mirror_covers_el + 1.0
Expand All @@ -920,6 +928,10 @@ async def test_close_m1_cover_when_retracted_below_el_limit(self) -> None:
self._mtmount_evt_mirror_covers_motion_state.state = (
idl.enums.MTMount.DeployableMotionState.RETRACTED
)
self._mtmount_evt_mirror_cover_locks_motion_state.state = (
idl.enums.MTMount.DeployableMotionState.RETRACTED
)

# Unsafe elevation for mirror covers operation
self._mtmount_tel_elevation.actualPosition = (
self.mtcs.tel_operate_mirror_covers_el - 1.0
Expand Down Expand Up @@ -961,6 +973,7 @@ async def test_close_m1_cover_wrong_motion_state(self) -> None:
self._mtmount_evt_mirror_covers_motion_state.state = (
idl.enums.MTMount.DeployableMotionState.LOST
)

cover_state = self._mtmount_evt_mirror_covers_motion_state
exception_message = (
f"Mirror covers in {MTMount.DeployableMotionState(cover_state.state)!r} "
Expand All @@ -975,6 +988,9 @@ async def test_open_m1_cover_when_retracted(self) -> None:
self._mtmount_evt_mirror_covers_motion_state.state = (
idl.enums.MTMount.DeployableMotionState.RETRACTED
)
self._mtmount_evt_mirror_cover_locks_motion_state.state = (
idl.enums.MTMount.DeployableMotionState.RETRACTED
)

await self.mtcs.open_m1_cover()

Expand All @@ -985,6 +1001,10 @@ async def test_open_m1_cover_when_deployed(self) -> None:
self._mtmount_evt_mirror_covers_motion_state.state = (
idl.enums.MTMount.DeployableMotionState.DEPLOYED
)
self._mtmount_evt_mirror_cover_locks_motion_state.state = (
idl.enums.MTMount.DeployableMotionState.DEPLOYED
)

# Safe elevation for mirror covers operation
self._mtmount_tel_elevation.actualPosition = (
self.mtcs.tel_operate_mirror_covers_el + 1.0
Expand All @@ -1002,6 +1022,10 @@ async def test_open_m1_cover_when_deployed_below_el_limit(self) -> None:
self._mtmount_evt_mirror_covers_motion_state.state = (
idl.enums.MTMount.DeployableMotionState.DEPLOYED
)
self._mtmount_evt_mirror_cover_locks_motion_state.state = (
idl.enums.MTMount.DeployableMotionState.DEPLOYED
)

# Unsafe elevation for mirror covers operation
self._mtmount_tel_elevation.actualPosition = (
self.mtcs.tel_operate_mirror_covers_el - 1.0
Expand All @@ -1028,6 +1052,10 @@ async def test_open_m1_cover_wrong_system_state(self) -> None:
self._mtmount_evt_mirror_covers_motion_state.state = (
idl.enums.MTMount.DeployableMotionState.DEPLOYED
)
self._mtmount_evt_mirror_cover_locks_motion_state.state = (
idl.enums.MTMount.DeployableMotionState.DEPLOYED
)

self._mtmount_evt_mirror_covers_system_state.state = (
idl.enums.MTMount.PowerState.FAULT
)
Expand All @@ -1043,6 +1071,10 @@ async def test_open_m1_cover_wrong_motion_state(self) -> None:
self._mtmount_evt_mirror_covers_motion_state.state = (
idl.enums.MTMount.DeployableMotionState.LOST
)
self._mtmount_evt_mirror_cover_locks_motion_state.state = (
idl.enums.MTMount.DeployableMotionState.DEPLOYED
)

cover_state = self._mtmount_evt_mirror_covers_motion_state
exception_message = (
f"Mirror covers in {MTMount.DeployableMotionState(cover_state.state)!r} "
Expand Down

0 comments on commit fb920d5

Please sign in to comment.