diff --git a/lofar_station_client/observation/multi_station_observation.py b/lofar_station_client/observation/multi_station_observation.py index eeb37f673f337bfdb74a8a64217eeb03bd0e98d2..ff74255b4aa23d073c7a69fd782c1aee1324c2f0 100644 --- a/lofar_station_client/observation/multi_station_observation.py +++ b/lofar_station_client/observation/multi_station_observation.py @@ -101,7 +101,12 @@ class MultiStationObservation: Value is None if the host is not connected """ - return {station.get_host: station.get_observation_poxy if station.is_connected else None for station in self._stations} + return { + station.get_host: station.get_observation_poxy + if station.is_connected + else None + for station in self._stations + } @property def is_running(self) -> dict: @@ -135,4 +140,3 @@ class MultiStationObservation: Returns "{hostname}": bool per station """ return {station.get_host: station.is_connected for station in self._stations} - diff --git a/lofar_station_client/observation/station.py b/lofar_station_client/observation/station.py index d4f17fe95e09c9219468a98fdc6ac1cfd2bc5f38..ffc03eb5665daa186e38dbc02bc2f4d7aca58910 100644 --- a/lofar_station_client/observation/station.py +++ b/lofar_station_client/observation/station.py @@ -13,6 +13,7 @@ import concurrent.futures from json import dumps from tango import DeviceProxy, GreenMode + class Station: """ Container class station and observation data and acccess @@ -36,7 +37,9 @@ class Station: def start(self) -> concurrent.futures: """Start the observation with the given specification on this station""" - return self._control_proxy.start_observation(self._json_specification, wait=False) + return self._control_proxy.start_observation( + self._json_specification, wait=False + ) def stop(self) -> concurrent.futures: """Stop the observation with the given ID on this station""" @@ -70,4 +73,3 @@ class Station: def get_observation_poxy(self) -> DeviceProxy: """get the observation proxy of this station""" return self._control_proxy - diff --git a/tests/observation/test_multi_station_observation.py b/tests/observation/test_multi_station_observation.py index b51e60e27d98aff0eb4633cfb5d9782c028b3c82..36cd5035efe2f162ec5455442eeef5e88913cdff 100644 --- a/tests/observation/test_multi_station_observation.py +++ b/tests/observation/test_multi_station_observation.py @@ -43,67 +43,52 @@ class FakeFuture: class TestMultiStationObservation(base.TestCase): - def setUp(self): + @mock.patch( + "lofar_station_client.observation.multi_station_observation.Station", + autospec=True, + ) + def setUp(self, M_station): self.station_mocks = [mock.Mock(), mock.Mock(), mock.Mock()] for i in self.station_mocks: i.start.return_value = FakeFuture() i.stop.return_value = FakeFuture() - i.is_running.return_value = FakeFuture() - i.is_connected.return_value = True - i.get_control_poxy.return_value = "A_real_control_proxy" - - self.station_mocks[ - 0 - ].get_observation_poxy.return_value = "A_real_observation_proxy1" - self.station_mocks[ - 1 - ].get_observation_poxy.return_value = "A_real_observation_proxy2" - self.station_mocks[ - 2 - ].get_observation_poxy.return_value = "A_real_observation_proxy3" - - self.station_mocks[0].get_host.return_value = "host1" - self.station_mocks[1].get_host.return_value = "host2" - self.station_mocks[2].get_host.return_value = "host3" - - @mock.patch( - "lofar_station_client.observation.multi_station_observation.Station", - autospec=True, - ) - def test_start(self, M_station): - M_station.side_effect = self.station_mocks - self.observation = MultiStationObservation( - specification=SPEC_DICT, hosts=HOST_LIST + type(i).is_running = mock.PropertyMock(return_value=FakeFuture()) + type(i).is_connected = mock.PropertyMock(return_value=True) + type(i).get_control_poxy = mock.PropertyMock( + return_value="A_real_control_proxy" + ) + + type(self.station_mocks[0]).get_observation_poxy = mock.PropertyMock( + return_value="A_real_observation_proxy1" + ) + type(self.station_mocks[1]).get_observation_poxy = mock.PropertyMock( + return_value="A_real_observation_proxy2" + ) + type(self.station_mocks[2]).get_observation_poxy = mock.PropertyMock( + return_value="A_real_observation_proxy3" ) - self.observation.start() - self.assertEqual(M_station.call_count, 3) + type(self.station_mocks[0]).get_host = mock.PropertyMock(return_value="host1") + type(self.station_mocks[1]).get_host = mock.PropertyMock(return_value="host2") + type(self.station_mocks[2]).get_host = mock.PropertyMock(return_value="host3") - @mock.patch( - "lofar_station_client.observation.multi_station_observation.Station", - autospec=True, - ) - def test_stop(self, M_station): + # apply the mock M_station.side_effect = self.station_mocks + self.M_station = M_station self.observation = MultiStationObservation( specification=SPEC_DICT, hosts=HOST_LIST ) - self.observation.stop() - self.assertEqual(M_station.call_count, 3) - - @mock.patch( - "lofar_station_client.observation.multi_station_observation.Station", - autospec=True, - ) - def test_proxies(self, M_station): + def test_start(self): + self.observation.start() + self.assertEqual(self.M_station.call_count, 3) - M_station.side_effect = self.station_mocks - self.observation = MultiStationObservation( - specification=SPEC_DICT, hosts=HOST_LIST - ) + def test_stop(self): + self.observation.stop() + self.assertEqual(self.M_station.call_count, 3) + def test_proxies(self): expected = { "host1": "A_real_observation_proxy1", "host2": "A_real_observation_proxy2", @@ -112,30 +97,12 @@ class TestMultiStationObservation(base.TestCase): results = self.observation.observation_proxies self.assertEqual(expected, results) - @mock.patch( - "lofar_station_client.observation.multi_station_observation.Station", - autospec=True, - ) - def test_is_running(self, M_station): - M_station.side_effect = self.station_mocks - self.observation = MultiStationObservation( - specification=SPEC_DICT, hosts=HOST_LIST - ) - + def test_is_running(self): expected = {"host1": True, "host2": True, "host3": True} results = self.observation.is_running self.assertEqual(expected, results) - @mock.patch( - "lofar_station_client.observation.multi_station_observation.Station", - autospec=True, - ) - def test_is_connected(self, M_station): - M_station.side_effect = self.station_mocks - self.observation = MultiStationObservation( - specification=SPEC_DICT, hosts=HOST_LIST - ) - + def test_is_connected(self): expected = {"host1": True, "host2": True, "host3": True} results = self.observation.is_connected self.assertEqual(expected, results)