diff --git a/tangostationcontrol/setup.cfg b/tangostationcontrol/setup.cfg index 82d6efb049aa4dae8f7842518c20aea2f4ae1ba1..0fe48b128f13c2e09ccca534cf0b5fa609aee02b 100644 --- a/tangostationcontrol/setup.cfg +++ b/tangostationcontrol/setup.cfg @@ -51,7 +51,7 @@ console_scripts = l2ss-bst = tangostationcontrol.devices.sdp.bst:main l2ss-sst = tangostationcontrol.devices.sdp.sst:main l2ss-statistics-reader = tangostationcontrol.statistics_writer.statistics_reader:main - l2ss-statistics-writer = tangostationcontrol.statistics_writer.statistics_writer:main + l2ss-statistics-writer = tangostationcontrol.statistics.writer:main l2ss-unb2 = tangostationcontrol.devices.unb2:main l2ss-xst = tangostationcontrol.devices.sdp.xst:main l2ss-temperature-manager = tangostationcontrol.devices.temperature_manager:main diff --git a/tangostationcontrol/__init__.py b/tangostationcontrol/tangostationcontrol/integration_test/default/statistics/__init__.py similarity index 100% rename from tangostationcontrol/__init__.py rename to tangostationcontrol/tangostationcontrol/integration_test/default/statistics/__init__.py diff --git a/tangostationcontrol/tangostationcontrol/integration_test/default/statistics_writer/test_statistics_writer_sst.py b/tangostationcontrol/tangostationcontrol/integration_test/default/statistics/test_writer_sst.py similarity index 88% rename from tangostationcontrol/tangostationcontrol/integration_test/default/statistics_writer/test_statistics_writer_sst.py rename to tangostationcontrol/tangostationcontrol/integration_test/default/statistics/test_writer_sst.py index 5b2b8fae5c280cac3409bdcca4c70c6220066135..e2907240e772d0b21acd0abe18704bf40b8be940 100644 --- a/tangostationcontrol/tangostationcontrol/integration_test/default/statistics_writer/test_statistics_writer_sst.py +++ b/tangostationcontrol/tangostationcontrol/integration_test/default/statistics/test_writer_sst.py @@ -10,7 +10,9 @@ from tangostationcontrol.integration_test.base import BaseIntegrationTestCase from tangostationcontrol.integration_test.device_proxy import TestDeviceProxy from tangostationcontrol.statistics.statistics_collector import SSTCollector -from tangostationcontrol.statistics_writer import statistics_writer, statistics_reader +from tangostationcontrol.statistics_writer import statistics_reader +from tangostationcontrol.statistics import writer + import sys from os.path import dirname, isfile, join from tempfile import TemporaryDirectory @@ -18,6 +20,7 @@ from unittest import mock from tango import DevState + class TestStatisticsWriterSST(BaseIntegrationTestCase): def setUp(self): @@ -51,10 +54,10 @@ class TestStatisticsWriterSST(BaseIntegrationTestCase): self.assertListEqual(collector.parameters["rcu_dth_on"].tolist(), self.recv_proxy.rcu_dth_on_r.tolist()) with TemporaryDirectory() as tmpdir: - new_sys_argv = [sys.argv[0], "--mode", "SST", "--file", join(dirname(dirname(dirname(dirname(__file__)))), "test", "SDP_SST_statistics_packets.bin"), "--output_dir", tmpdir] - with mock.patch.object(statistics_writer.sys, 'argv', new_sys_argv): + new_sys_argv = [sys.argv[0], "--mode", "SST", "--file", join(dirname(dirname(dirname(dirname(__file__)))), "test/statistics", "SDP_SST_statistics_packets.bin"), "--output_dir", tmpdir] + with mock.patch.object(writer.sys, 'argv', new_sys_argv): with self.assertRaises(SystemExit): - statistics_writer.main() + writer.main() # check if file was written self.assertTrue(isfile(f"{tmpdir}/SST_2021-09-20-12-17-40.h5")) @@ -76,10 +79,10 @@ class TestStatisticsWriterSST(BaseIntegrationTestCase): def test_no_tango_SST_statistics(self): with TemporaryDirectory() as tmpdir: - new_sys_argv = [sys.argv[0], "--mode", "SST", "--no-tango", "--file", join(dirname(dirname(dirname(dirname(__file__)))), "test", "SDP_SST_statistics_packets.bin"), "--output_dir", tmpdir] - with mock.patch.object(statistics_writer.sys, 'argv', new_sys_argv): + new_sys_argv = [sys.argv[0], "--mode", "SST", "--no-tango", "--file", join(dirname(dirname(dirname(dirname(__file__)))), "test/statistics", "SDP_SST_statistics_packets.bin"), "--output_dir", tmpdir] + with mock.patch.object(writer.sys, 'argv', new_sys_argv): with self.assertRaises(SystemExit): - statistics_writer.main() + writer.main() # check if file was written self.assertTrue(isfile(f"{tmpdir}/SST_2021-09-20-12-17-40.h5")) @@ -104,10 +107,10 @@ class TestStatisticsWriterSST(BaseIntegrationTestCase): self.assertEqual(DevState.OFF, self.recv_proxy.state()) with TemporaryDirectory() as tmpdir: - new_sys_argv = [sys.argv[0], "--mode", "SST", "--file", join(dirname(dirname(dirname(dirname(__file__)))), "test", "SDP_SST_statistics_packets.bin"), "--output_dir", tmpdir] - with mock.patch.object(statistics_writer.sys, 'argv', new_sys_argv): + new_sys_argv = [sys.argv[0], "--mode", "SST", "--file", join(dirname(dirname(dirname(dirname(__file__)))), "test/statistics", "SDP_SST_statistics_packets.bin"), "--output_dir", tmpdir] + with mock.patch.object(writer.sys, 'argv', new_sys_argv): with self.assertRaises(SystemExit): - statistics_writer.main() + writer.main() # check if file was written self.assertTrue(isfile(f"{tmpdir}/SST_2021-09-20-12-17-40.h5")) diff --git a/tangostationcontrol/tangostationcontrol/integration_test/default/statistics_writer/__init__.py b/tangostationcontrol/tangostationcontrol/integration_test/default/statistics_writer/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/tangostationcontrol/tangostationcontrol/statistics_writer/statistics_writer.py b/tangostationcontrol/tangostationcontrol/statistics/writer.py similarity index 99% rename from tangostationcontrol/tangostationcontrol/statistics_writer/statistics_writer.py rename to tangostationcontrol/tangostationcontrol/statistics/writer.py index 49add415ca7905446488d56416c5437b994acf9e..cbc358be4389db42e21561fe6a4c6bf4fa6bd856 100644 --- a/tangostationcontrol/tangostationcontrol/statistics_writer/statistics_writer.py +++ b/tangostationcontrol/tangostationcontrol/statistics/writer.py @@ -10,6 +10,7 @@ import logging logging.basicConfig(level=logging.INFO, format = '%(asctime)s:%(levelname)s: %(message)s') logger = logging.getLogger("statistics_writer") + def _create_parser(): """Define the parser""" parser = argparse.ArgumentParser( @@ -55,6 +56,7 @@ def _create_parser(): ) return parser + def _create_receiver(filename, host, port): """ creates the TCP receiver that is given to the writer """ if filename: @@ -65,6 +67,7 @@ def _create_receiver(filename, host, port): logger.fatal("Must provide either a host and port, or a file to receive input from") sys.exit(1) + def _create_writer(mode, interval, output_dir, decimation): """Create the writer""" if mode == "XST": @@ -77,6 +80,7 @@ def _create_writer(mode, interval, output_dir, decimation): logger.fatal(f"Invalid mode: {mode}") sys.exit(1) + def _start_loop(receiver, writer, reconnect, filename, device): """Main loop""" try: @@ -106,6 +110,7 @@ def _start_loop(receiver, writer, reconnect, filename, device): finally: writer.close_writer() + def main(): parser = _create_parser() diff --git a/tangostationcontrol/tangostationcontrol/statistics_writer/udp_dev/udp_client.py b/tangostationcontrol/tangostationcontrol/statistics_writer/udp_dev/udp_client.py index cef6a079d17dc0fb45d71f181ee2be908e9bd091..ea5a644f10985257452b4d93249cea36c37708e9 100644 --- a/tangostationcontrol/tangostationcontrol/statistics_writer/udp_dev/udp_client.py +++ b/tangostationcontrol/tangostationcontrol/statistics_writer/udp_dev/udp_client.py @@ -30,7 +30,7 @@ class UDP_Client: time.sleep(1) - f = open("../../test/SDP_SST_statistics_packet.bin", "rb") + f = open("../../test/statistics/SDP_SST_statistics_packet.bin", "rb") send_data = f.read() s.sendto(send_data, (self.server_ip, self.server_port)) print("\n\n 1. Client Sent SST Packet at: ", datetime.now()) diff --git a/tangostationcontrol/tangostationcontrol/test/beam/test_delays.py b/tangostationcontrol/tangostationcontrol/test/beam/test_delays.py index a3b5779650217572dfeddb73eff324657acead2b..12d015774c933322495fc3aa7abe8d5c57052628 100644 --- a/tangostationcontrol/tangostationcontrol/test/beam/test_delays.py +++ b/tangostationcontrol/tangostationcontrol/test/beam/test_delays.py @@ -144,7 +144,6 @@ class TestDelays(base.TestCase): self.assertAlmostEqual(0.1, delays[0], 6, f"delays[0] = {delays[0]}") - def test_convert_bulk(self): d = delay_calculator([0, 0, 0]) timestamp = datetime.datetime(2022, 3, 1, 0, 0, 0) # timestamp does not actually matter, but casacore doesn't know that. diff --git a/tangostationcontrol/tangostationcontrol/test/SDP_BST_statistics_packets.bin b/tangostationcontrol/tangostationcontrol/test/statistics/SDP_BST_statistics_packets.bin similarity index 100% rename from tangostationcontrol/tangostationcontrol/test/SDP_BST_statistics_packets.bin rename to tangostationcontrol/tangostationcontrol/test/statistics/SDP_BST_statistics_packets.bin diff --git a/tangostationcontrol/tangostationcontrol/test/SDP_SST_statistics_packet.bin b/tangostationcontrol/tangostationcontrol/test/statistics/SDP_SST_statistics_packet.bin similarity index 100% rename from tangostationcontrol/tangostationcontrol/test/SDP_SST_statistics_packet.bin rename to tangostationcontrol/tangostationcontrol/test/statistics/SDP_SST_statistics_packet.bin diff --git a/tangostationcontrol/tangostationcontrol/test/SDP_SST_statistics_packets.bin b/tangostationcontrol/tangostationcontrol/test/statistics/SDP_SST_statistics_packets.bin similarity index 100% rename from tangostationcontrol/tangostationcontrol/test/SDP_SST_statistics_packets.bin rename to tangostationcontrol/tangostationcontrol/test/statistics/SDP_SST_statistics_packets.bin diff --git a/tangostationcontrol/tangostationcontrol/test/SDP_XST_statistics_packets.bin b/tangostationcontrol/tangostationcontrol/test/statistics/SDP_XST_statistics_packets.bin similarity index 100% rename from tangostationcontrol/tangostationcontrol/test/SDP_XST_statistics_packets.bin rename to tangostationcontrol/tangostationcontrol/test/statistics/SDP_XST_statistics_packets.bin diff --git a/tangostationcontrol/tangostationcontrol/test/SDP_XST_statistics_packets_multiple_subbands.bin b/tangostationcontrol/tangostationcontrol/test/statistics/SDP_XST_statistics_packets_multiple_subbands.bin similarity index 100% rename from tangostationcontrol/tangostationcontrol/test/SDP_XST_statistics_packets_multiple_subbands.bin rename to tangostationcontrol/tangostationcontrol/test/statistics/SDP_XST_statistics_packets_multiple_subbands.bin diff --git a/tangostationcontrol/tangostationcontrol/test/test_statistics_writer.py b/tangostationcontrol/tangostationcontrol/test/statistics/test_writer.py similarity index 79% rename from tangostationcontrol/tangostationcontrol/test/test_statistics_writer.py rename to tangostationcontrol/tangostationcontrol/test/statistics/test_writer.py index 37f3c2f1d96f2fa39d60241d406a1324f549b4ad..56d6d85e0d83c6b9ac1e35e981ade193ab90d317 100644 --- a/tangostationcontrol/tangostationcontrol/test/test_statistics_writer.py +++ b/tangostationcontrol/tangostationcontrol/test/statistics/test_writer.py @@ -8,12 +8,13 @@ # See LICENSE.txt for more info. from tangostationcontrol.test import base -from tangostationcontrol.statistics_writer import statistics_writer +from tangostationcontrol.statistics import writer import sys from os.path import dirname, isfile from tempfile import TemporaryDirectory from unittest import mock + class TestStatisticsWriter(base.TestCase): # test_sst --> moved to integration_test @@ -21,9 +22,9 @@ class TestStatisticsWriter(base.TestCase): def test_xst(self): with TemporaryDirectory() as tmpdir: new_sys_argv = [sys.argv[0], "--mode", "XST", "--file", dirname(__file__) + "/SDP_XST_statistics_packets.bin", "--output_dir", tmpdir] - with mock.patch.object(statistics_writer.sys, 'argv', new_sys_argv): + with mock.patch.object(writer.sys, 'argv', new_sys_argv): with self.assertRaises(SystemExit): - statistics_writer.main() + writer.main() # check if file was written self.assertTrue(isfile(f"{tmpdir}/XST_SB102_2021-09-13-13-21-32.h5")) @@ -31,9 +32,9 @@ class TestStatisticsWriter(base.TestCase): def test_xst_multiple_subbands(self): with TemporaryDirectory() as tmpdir: new_sys_argv = [sys.argv[0], "--mode", "XST", "--file", dirname(__file__) + "/SDP_XST_statistics_packets_multiple_subbands.bin", "--output_dir", tmpdir] - with mock.patch.object(statistics_writer.sys, 'argv', new_sys_argv): + with mock.patch.object(writer.sys, 'argv', new_sys_argv): with self.assertRaises(SystemExit): - statistics_writer.main() + writer.main() # check if files were written self.assertTrue(isfile(f"{tmpdir}/XST_SB102_2021-09-13-13-21-32.h5")) @@ -42,9 +43,9 @@ class TestStatisticsWriter(base.TestCase): def test_bst(self): with TemporaryDirectory() as tmpdir: new_sys_argv = [sys.argv[0], "--mode", "BST", "--file", dirname(__file__) + "/SDP_BST_statistics_packets.bin", "--output_dir", tmpdir] - with mock.patch.object(statistics_writer.sys, 'argv', new_sys_argv): + with mock.patch.object(writer.sys, 'argv', new_sys_argv): with self.assertRaises(SystemExit): - statistics_writer.main() + writer.main() # check if file was written self.assertTrue(isfile(f"{tmpdir}/BST_2022-05-20-11-08-44.h5"))