Skip to content

Commit

Permalink
adding unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
psferguson committed Oct 26, 2023
1 parent 6f8065d commit db55b36
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 9 deletions.
15 changes: 6 additions & 9 deletions python/lsst/ts/observatory/control/maintel/mtcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from lsst.ts.xml.tables.m1m3 import FATable
except ImportError:
from lsst.ts.criopy.M1M3FATable import FATABLE as FATable
from lsst.ts.xml.tables.m2 import M2FATable

from ..base_tcs import BaseTCS
from ..constants import mtcs_constants
Expand Down Expand Up @@ -159,9 +158,6 @@ def __init__(
self._m1m3_actuator_id_sindex_table: dict[int, int] = dict(
[(fa.actuator_id, fa.s_index) for fa in FATable if fa.s_index is not None]
)
self._m2_actuator_id_index_table: dict[int, int] = dict(
[(fa.actuator_id, fa.index) for fa in M2FATable]
)

try:
self._create_asyncio_events()
Expand Down Expand Up @@ -1407,15 +1403,15 @@ async def is_m1m3_in_engineering_mode(self) -> bool:

async def run_m2_actuator_bump_test(
self,
actuator_id: int,
actuator: int,
period: float,
force: float,
) -> None:
"""M2 actuator bump test.
Parameters
----------
actuator_id : `int`
actuator : `int`
Id of the actuator.
period : `float`,
There will be two bumps and each bump will wait for (2 * period)
Expand All @@ -1426,14 +1422,15 @@ async def run_m2_actuator_bump_test(
# check that actuator_id is not hardpoint
hardpoint_ids = await self.get_m2_hardpoints()

if actuator_id in hardpoint_ids:
# csc actuator id is 0 based and hardpoint id is 1 based
if actuator + 1 in hardpoint_ids:
raise Exception(
f"Cannot bump test one of the M2 hardpoints: actuator_id {actuator_id}"
f"Cannot bump test one of the M2 hardpoints: actuator = {actuator}"
)

# bump test single actuator
await self.rem.mtm2.cmd_actuatorBumpTest.set_start(
actuatorId=actuator_id,
actuator=actuator,
period=period,
force=force,
)
Expand Down
16 changes: 16 additions & 0 deletions python/lsst/ts/observatory/control/mock/mtcs_async_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ async def setup_types(self) -> None:

# MTM2 data
self._mtm2_evt_force_balance_system_status = types.SimpleNamespace(status=False)
self._mtm2_evt_hardpointList = types.SimpleNamespace(actuators=[6])

# Camera hexapod data
self._mthexapod_1_evt_compensation_mode = types.SimpleNamespace(enabled=False)
Expand Down Expand Up @@ -308,6 +309,8 @@ async def setup_mtm2(self) -> None:
"evt_forceBalanceSystemStatus.aget.side_effect": self.mtm2_evt_force_balance_system_status,
"evt_forceBalanceSystemStatus.next.side_effect": self.mtm2_evt_force_balance_system_status,
"cmd_switchForceBalanceSystem.set_start.side_effect": self.mtm2_cmd_switch_force_balance_system,
"cmd_actuatorBumpTest.set_start.side_effect": self.mtm2_cmd_actuator_bump_test,
"evt_hardpointList.aget.side_effect": self.mtm2_evt_hardpointList,
}

self.mtcs.rem.mtm2.configure_mock(**m2_mocks)
Expand Down Expand Up @@ -775,6 +778,19 @@ async def mtm2_cmd_switch_force_balance_system(
await asyncio.sleep(self.heartbeat_time)
self._mtm2_evt_force_balance_system_status.status = status

async def mtm2_cmd_actuator_bump_test(
self, *args: typing.Any, **kwargs: typing.Any
) -> None:
for key in ["actuator", "period", "force"]:
if key not in kwargs:
raise Exception(f"{key} not given in call")

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

async def mthexapod_1_evt_compensation_mode(
self, *args: typing.Any, **kwargs: typing.Any
) -> types.SimpleNamespace:
Expand Down
37 changes: 37 additions & 0 deletions tests/maintel/test_mtcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,43 @@ async def test_reset_m2_forces(self) -> None:
timeout=self.mtcs.long_timeout
)

async def test_run_m2_actuator_bump_test_default(self) -> None:
actuator = 55
period = 60
force = 10

await self.mtcs.run_m2_actuator_bump_test(
actuator=actuator,
period=period,
force=force,
)

self.mtcs.rem.mtm2.cmd_actuatorBumpTest.set_start.assert_awaited_with(
actuator=actuator,
period=period,
force=force,
)

async def test_run_m2_actuator_bump_test_hardpoint(self) -> None:
actuator = 5
period = 60
force = 10

with pytest.raises(Exception):
await self.mtcs.run_m2_actuator_bump_test(
actuator=actuator,
period=period,
force=force,
)

async def test_get_m2_hardpoints(self) -> None:
hardpoints = await self.mtcs.get_m2_hardpoints()
assert hardpoints == self._mtm2_evt_hardpointList.actuators

async def test_stop_m2_actuator_bump(self) -> None:
with pytest.raises(NotImplementedError):
await self.mtcs.stop_m2_bump_test()

async def test_enable_compensation_mode_for_hexapod_1(self) -> None:
self._mthexapod_1_evt_compensation_mode.enabled = False

Expand Down

0 comments on commit db55b36

Please sign in to comment.