Skip to content

Commit

Permalink
add unit test for case of text input with list of file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfromearth committed Aug 8, 2024
1 parent 3d69bca commit c0efe9e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 19 deletions.
28 changes: 28 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import numpy as np
import pytest

test_path = Path(__file__).parents[0].resolve()
data_path = test_path.joinpath("data")
harmony_path = data_path.joinpath("harmony")
granules_path = harmony_path.joinpath("granules")


class DataDirs(typing.NamedTuple):
test_path: Path
Expand Down Expand Up @@ -160,3 +165,26 @@ def ds_3dims_3vars_4coords_1group_part3(temp_toy_data_dir):
f.close()

return filepath


@pytest.fixture(scope="function")
def text_file_with_three_paths(temp_toy_data_dir) -> Path:
filepath = temp_toy_data_dir / "text_file_with_paths.txt"

paths = [
path_str(granules_path, x)
for x in [
"TEMPO_NO2_L2_V03_20240601T210934Z_S012G01_subsetted.nc4",
"TEMPO_NO2_L2_V03_20240601T211614Z_S012G02_subsetted.nc4",
"TEMPO_NO2_L2_V03_20240601T212254Z_S012G03_subsetted.nc4",
]
]

contents = f"""{paths[0]}
{paths[1]}
{paths[2]}
"""
with open(filepath, "w") as f:
f.write(contents)

return filepath
44 changes: 25 additions & 19 deletions tests/unit/test_run_stitchee.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import sys
from pathlib import Path
from unittest.mock import patch

import pytest

import concatenator
from concatenator.run_stitchee import parse_args

from ..conftest import path_str
from ..conftest import granules_path, path_str


def test_parser():
Expand All @@ -24,23 +23,13 @@ def test_parser():

@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_three_filepaths(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"
),
path_str(granules_path, "TEMPO_NO2_L2_V03_20240601T210934Z_S012G01_subsetted.nc4"),
path_str(granules_path, "TEMPO_NO2_L2_V03_20240601T211614Z_S012G02_subsetted.nc4"),
path_str(granules_path, "TEMPO_NO2_L2_V03_20240601T212254Z_S012G03_subsetted.nc4"),
"--copy_input_files",
"--verbose",
"-o",
Expand All @@ -57,7 +46,7 @@ def test_run_stitchee_cli_with_three_filepaths(self, temp_output_dir):
def test_run_stitchee_cli_with_one_directorypath(self, temp_output_dir):
test_args = [
concatenator.run_stitchee.__file__,
str(self.__granules_path),
str(granules_path),
"--copy_input_files",
"--verbose",
"-o",
Expand All @@ -74,9 +63,26 @@ def test_run_stitchee_cli_with_one_directorypath(self, temp_output_dir):
def test_run_stitchee_cli_with_one_netCDFpath(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(granules_path, "TEMPO_NO2_L2_V03_20240601T210934Z_S012G01_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()

def test_run_stitchee_cli_with_one_path_to_text_listing_of_three_files(
self, temp_output_dir, text_file_with_three_paths
):
test_args = [
concatenator.run_stitchee.__file__,
str(text_file_with_three_paths),
"--copy_input_files",
"--verbose",
"-o",
Expand Down

0 comments on commit c0efe9e

Please sign in to comment.