From bb973e070affbe3846f9f04f4a519317f75c7697 Mon Sep 17 00:00:00 2001 From: danielfromearth Date: Mon, 1 Jul 2024 21:37:58 -0400 Subject: [PATCH] add three-granule cli run test --- tests/unit/test_cli.py | 13 -------- tests/unit/test_run_stitchee.py | 57 +++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 13 deletions(-) delete mode 100644 tests/unit/test_cli.py create mode 100644 tests/unit/test_run_stitchee.py diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py deleted file mode 100644 index ab911be..0000000 --- a/tests/unit/test_cli.py +++ /dev/null @@ -1,13 +0,0 @@ -from concatenator.run_stitchee import parse_args - - -def test_parser(): - parsed = parse_args( - ["ncfile1", "ncfile2", "ncfile3", "-o", "outfile", "--concat_dim", "mirror_step"] - ) - - assert parsed.input == ["ncfile1", "ncfile2", "ncfile3"] - assert parsed.output_path == "outfile" - assert parsed.concat_dim == "mirror_step" - assert parsed.concat_method == "xarray-concat" - assert parsed.verbose is False diff --git a/tests/unit/test_run_stitchee.py b/tests/unit/test_run_stitchee.py new file mode 100644 index 0000000..42f5ec4 --- /dev/null +++ b/tests/unit/test_run_stitchee.py @@ -0,0 +1,57 @@ +import sys +from pathlib import Path +from unittest.mock import patch + +import pytest + +import concatenator +from concatenator.run_stitchee import parse_args + + +def path_str(dir_path: Path, filename: str) -> str: + return str(dir_path.joinpath(filename)) + + +def test_parser(): + parsed = parse_args( + ["ncfile1", "ncfile2", "ncfile3", "-o", "outfile", "--concat_dim", "mirror_step"] + ) + + assert parsed.input == ["ncfile1", "ncfile2", "ncfile3"] + assert parsed.output_path == "outfile" + assert parsed.concat_dim == "mirror_step" + assert parsed.concat_method == "xarray-concat" + assert parsed.verbose is False + + +@pytest.mark.usefixtures("pass_options") +class TestBatching: + __test_path = Path(__file__).parents[1].resolve() + __data_path = __test_path.joinpath("data") + __harmony_path = __data_path.joinpath("harmony") + __granules_path = __harmony_path.joinpath("granules") + + def test_run_stitchee_cli_with_no_error(self, temp_output_dir): + test_args = [ + concatenator.run_stitchee.__file__, + path_str( + self.__granules_path, "TEMPO_NO2_L2_V03_20240601T210934Z_S012G01_subsetted.nc4" + ), + path_str( + self.__granules_path, "TEMPO_NO2_L2_V03_20240601T211614Z_S012G02_subsetted.nc4" + ), + path_str( + self.__granules_path, "TEMPO_NO2_L2_V03_20240601T212254Z_S012G03_subsetted.nc4" + ), + "--copy_input_files", + "--verbose", + "-o", + path_str(temp_output_dir, "test_run_stitchee_output.nc"), + "--concat_method", + "xarray-concat", + "--concat_dim", + "mirror_step", + ] + + with patch.object(sys, "argv", test_args): + concatenator.run_stitchee.main()