From c593f9f9cefcdb1fae70ea6d68a2ecfae7ab2e00 Mon Sep 17 00:00:00 2001 From: Greg Lucas Date: Thu, 25 Jul 2024 12:14:21 -0600 Subject: [PATCH] TST: Add tests for Excel to XTCE XML Add a simple excel file with variable types we want to test and assert against a known XML file we have produced. --- .../tests/ccsds/test_data/expected_output.xml | 160 ++++++++++++++++++ .../tests/ccsds/test_excel_to_xtce.py | 25 ++- 2 files changed, 180 insertions(+), 5 deletions(-) create mode 100644 imap_processing/tests/ccsds/test_data/expected_output.xml diff --git a/imap_processing/tests/ccsds/test_data/expected_output.xml b/imap_processing/tests/ccsds/test_data/expected_output.xml new file mode 100644 index 000000000..42471b469 --- /dev/null +++ b/imap_processing/tests/ccsds/test_data/expected_output.xml @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CCSDS Packet Version Number (always 0) + + + CCSDS Packet Type Indicator (0=telemetry) + + + CCSDS Packet Secondary Header Flag (always 1) + + + CCSDS Packet Application Process ID + + + CCSDS Packet Grouping Flags (3=not part of group) + + + CCSDS Packet Sequence Count (increments with each new packet) + + + CCSDS Packet Length (number of bytes after Packet length minus 1) + + + Mission elapsed time + + + Unsgned integer data with conversion + + + Integer data + + + Signed integer data + + + Binary data - variable length + + + Fill data + + + Float data + + + Mission elapsed time + + + Variable 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/imap_processing/tests/ccsds/test_excel_to_xtce.py b/imap_processing/tests/ccsds/test_excel_to_xtce.py index efecee5ad..062a1074c 100644 --- a/imap_processing/tests/ccsds/test_excel_to_xtce.py +++ b/imap_processing/tests/ccsds/test_excel_to_xtce.py @@ -12,21 +12,36 @@ @pytest.fixture() -def filepath(tmpdir): - p = Path(tmpdir / "test_file.xlsx").resolve() - p.touch() +def excel_file(): + p = Path(__file__).parent / "test_data" / "excel_to_xtce_test_file.xlsx" return p +def test_generated_xml(excel_file, tmp_path): + """Make sure we are producing the expected contents within the XML file. + + To produce a new expected output file the following command can be used. + imap_xtce imap_processing/tests/ccsds/test_data/excel_to_xtce_test_file.xlsx + --output imap_processing/tests/ccsds/test_data/expected_output.xml + """ + generator = excel_to_xtce.XTCEGenerator(excel_file) + output_file = tmp_path / "output.xml" + generator.to_xml(output_file) + + expected_file = excel_file.parent / "expected_output.xml" + with open(output_file) as f, open(expected_file) as f_expected: + assert f.read() == f_expected.read() + + # General test @mock.patch("imap_processing.ccsds.excel_to_xtce.XTCEGenerator") -def test_main_general(mock_input, filepath): +def test_main_general(mock_input, excel_file): """Testing base main function.""" test_args = [ "test_script", "--output", "swe.xml", - f"{filepath}", + f"{excel_file}", ] with mock.patch.object(sys, "argv", test_args): excel_to_xtce.main()