Skip to content

Commit

Permalink
Adding unit tests and minor fixes on set_dof structure
Browse files Browse the repository at this point in the history
  • Loading branch information
gmegh committed Dec 5, 2024
1 parent dbffd4a commit b9f57b7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
13 changes: 6 additions & 7 deletions python/lsst/ts/standardscripts/maintel/set_dof.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)]
Expand All @@ -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
------
Expand All @@ -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.
Expand Down
25 changes: 25 additions & 0 deletions tests/test_maintel_set_dof.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))

Expand Down

0 comments on commit b9f57b7

Please sign in to comment.