From 0c65eb116326d4830f0aef3df30fc0fb66834934 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. --- .../test_data/excel_to_xtce_test_file.xlsx | Bin 0 -> 13983 bytes .../tests/ccsds/test_data/expected_output.xml | 160 ++++++++++++++++++ .../tests/ccsds/test_excel_to_xtce.py | 25 ++- poetry.lock | 4 +- pyproject.toml | 2 +- 5 files changed, 183 insertions(+), 8 deletions(-) create mode 100644 imap_processing/tests/ccsds/test_data/excel_to_xtce_test_file.xlsx create mode 100644 imap_processing/tests/ccsds/test_data/expected_output.xml 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 0000000000000000000000000000000000000000..29f0910da8a4e0049d60c73e20c45be08042a716 GIT binary patch literal 13983 zcmeHuWmFtnx_09l+}+&*1lQp19$bREy99?I0fJkw;7)K4?(S~E-J7qIGc)H*=FHFg z{kgYTt7_4^-e-01dS2W6DMc9wNDKfp02TlMkOCxy-wrx}0RWZI0024w7F&WG!`{?Mm&x76nj{wzoF*Fp4!ZyUj{n6oFq}AK+r@$+cANNs9M_;`l#Q&086ZYH zg!T0bV%hyI1HsY-4!qx5xJOa3G79)tYa`0c##@u^<*U$0ZEB~pqS65^&cjMbS;KtR zPw75U`jcKs1}Nh2Hm|m=;rc^@h9ZIP2LSXR9LY6wkhdM&SeVn`Y=<4=@)kaf;42Ss zZn?=3aA$gjPJIYg;K{Ke;z6$-6ci&;kOnRTi7F)d%uNQiiYw0tQ|#qS-a?Y?IFb7` z=2?YC@fg2SAKbt+WLf<&e)MEhdE)hD!kv;77mip@Ob*98=l=8cl!8^^f^8g@v`$hn zz#>vh4!wWe0|kxVU-6KkT#GSb!T$6trni4**mvml0?Nr5R`!u+;!WaFcpY&#vy)+UHgO|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H + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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]