Skip to content
Snippets Groups Projects
  • Em Zhan's avatar
    102da6b5
    Add SIPSANC_DATA_DIR and SIPSANC_LOG_DIR env vars · 102da6b5
    Em Zhan authored
    Allows changing where `sipsanc init` saves its files and where any
    errors in all `sipsanc` subcommands are saved, respectively
    
    Uses these variables in tests to separate the test instance of `sipsanc`
    from the local install
    102da6b5
    History
    Add SIPSANC_DATA_DIR and SIPSANC_LOG_DIR env vars
    Em Zhan authored
    Allows changing where `sipsanc init` saves its files and where any
    errors in all `sipsanc` subcommands are saved, respectively
    
    Uses these variables in tests to separate the test instance of `sipsanc`
    from the local install
test_cli_output.py 1.34 KiB
import os
from pathlib import Path
from subprocess import run

import numpy as np
import pytest
import xarray as xr
from mvcm import get_expected, requires_docker

from sipsanc.cli import PRODUCTS

pytestmark = pytest.mark.skipif(
    os.environ.get("CI") is not None,
    reason="files not available yet in CI",
)


@requires_docker
@pytest.mark.parametrize(
    "product,version,date",
    [
        ("VNP03MOD", "3.1.0", "2019-01-01T06:06"),
    ],
)
def test_truth(product: str, version: str, date: str, tmp_path: Path):
    cmd = ["asipscli", "files"]
    opts = ["-p", product, "-v", version, "-s", date, "-e", date, "-d", str(tmp_path)]
    result = run(cmd + opts, capture_output=True, text=True)
    files = [
        tmp_path / s.split(" ")[0].split("/")[-1] for s in result.stdout.splitlines()
    ]
    assert len(files) == 1

    l1b_file = files[0]
    output = str(tmp_path / "out.nc")
    plots = str(tmp_path / "plots")

    cmd = ["sipsanc", "regrid", "all", l1b_file, "--output", output, "--plot", plots]
    run(cmd, check=True)

    actual = xr.open_dataset(output)
    expected = get_expected(tmp_path, l1b_file.name)

    assert [*actual.data_vars.keys()] == [p.name for p in PRODUCTS]

    for key, value in actual.data_vars.items():
        assert np.array_equal(value, expected[key])
        assert (tmp_path / "plots" / f"{key}.png").exists()