diff --git a/python/lsst/ts/standardscripts/maintel/set_dof.py b/python/lsst/ts/standardscripts/maintel/set_dof.py index 89773b7b..618762dd 100644 --- a/python/lsst/ts/standardscripts/maintel/set_dof.py +++ b/python/lsst/ts/standardscripts/maintel/set_dof.py @@ -56,7 +56,7 @@ class SetDOF(ApplyDOF): """ def __init__(self, index): - super().__init__(index=index, descr="Set DOF absolute state") + super().__init__(index=index) @classmethod def get_schema(cls): @@ -145,8 +145,7 @@ async def get_last_issued_state(self): State of the system. """ - efd_name = await self.get_efd_name() - client = EfdClient(efd_name) + client = await self.get_efd_client() end_time = self.get_image_time(client, self.day, self.seq) topics = [f"aggregatedDoF{i}" for i in range(50)] @@ -165,13 +164,13 @@ async def get_last_issued_state(self): self.log.warning("No state found.") return np.zeros(50) - async def get_efd_name(self) -> str: + async def get_efd_client(self) -> str: """Get the EFD name. Returns ------- - efd_name : `str` - EFD name. + EfdClient + Client instance to query the EFD. Raises ------ @@ -187,7 +186,7 @@ async def get_efd_name(self) -> str: ) raise RuntimeError("Wrong EFD name: " + message) else: - return EFD_NAMES[site] + return EfdClient(EFD_NAMES[site]) async def run(self) -> None: """Run script. diff --git a/tests/test_maintel_set_dof.py b/tests/test_maintel_set_dof.py index 453e7040..cb36b8c7 100644 --- a/tests/test_maintel_set_dof.py +++ b/tests/test_maintel_set_dof.py @@ -24,6 +24,7 @@ import unittest import numpy as np +import pandas as pd from lsst.ts import standardscripts from lsst.ts.observatory.control.maintel.mtcs import MTCS, MTCSUsages from lsst.ts.observatory.control.utils.enums import DOFName @@ -55,8 +56,32 @@ async def basic_make_script(self, index): self.script.mtcs.assert_all_enabled = unittest.mock.AsyncMock() + self.script.get_efd_client = self.mock_get_efd_client() + return (self.script,) + async def mock_get_efd_client(self): + mock_efd_client = unittest.mock.AsyncMock() + + mock_efd_client.configure_mock( + **{ + "select_time_series.side_effect": self.mock_select_time_series, + "influx_client.query.side_effect": self.mock_query, + }, + ) + + return mock_efd_client + + async def mock_query(): + return pd.DataFrame(index=[pd.Timestamp("2024-01-01T00:00:00Z")]) + + async def mock_select_time_series(): + return pd.DataFrame( + data=[np.arange(50)], # A row with 50 sequential values (0 to 49) + columns=[f"value_{i}" for i in range(50)], + index=[pd.Timestamp("2024-01-01T00:00:00Z")], + ) + async def mock_get_degrees_of_freedom(self, **kwargs): return types.SimpleNamespace(aggregatedDoF=np.zeros(len(DOFName)))