diff --git a/imap_processing/tests/ccsds/test_data/excel_to_xtce_test_file.xlsx b/imap_processing/tests/ccsds/test_data/excel_to_xtce_test_file.xlsx new file mode 100644 index 000000000..29f0910da Binary files /dev/null and b/imap_processing/tests/ccsds/test_data/excel_to_xtce_test_file.xlsx differ 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..93182b78c --- /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 - long desc + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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() diff --git a/poetry.lock b/poetry.lock index e24e2123e..4f8f4bb36 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1741,10 +1741,10 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [extras] dev = ["mypy", "pre-commit", "ruff"] doc = ["numpydoc", "pydata-sphinx-theme", "sphinx", "sphinxcontrib-openapi"] -test = ["pytest", "pytest-cov"] +test = ["openpyxl", "pytest", "pytest-cov"] tools = ["openpyxl", "pandas"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<4" -content-hash = "894f6f0effe557a84748490901981b131754feca8c9204894901b391b8ef6461" +content-hash = "28cbb877e15c362c80541a8cebd35f12575cd86802c902505b4db1f65640d37e" diff --git a/pyproject.toml b/pyproject.toml index a84c2e0ef..24fddad61 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,7 +56,7 @@ mypy = {version="^1.10.1", optional=true} [tool.poetry.extras] dev = ["pre-commit", "ruff", "mypy"] doc = ["numpydoc", "pydata-sphinx-theme", "sphinx", "sphinxcontrib-openapi"] -test = ["pytest", "pytest-cov"] +test = ["openpyxl", "pytest", "pytest-cov"] tools= ["openpyxl", "pandas"] [project.urls]