Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
avaldebe committed Feb 26, 2024
1 parent e7eb9d6 commit cfc9177
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pyaerocom/scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

import typer

from pyaerocom import __package__, __version__, const
from pyaerocom import __package__, __version__, change_verbosity, const
from pyaerocom.aeroval import EvalSetup, ExperimentProcessor
from pyaerocom.io.cachehandler_ungridded import list_cache_files
from pyaerocom.io.utils import browse_database

Expand Down Expand Up @@ -81,10 +82,8 @@ def aeroval(
verbosity: Verbosity = typer.Option(Verbosity.ERROR, help="console logger level"),
):
"""run AeroVal experiment as descried on config file"""
from pyaerocom import change_verbosity
from pyaerocom.aeroval import EvalSetup, ExperimentProcessor

if config.suffix != ".json":
if config.suffix != ".json": # pragma:no cover
typer.echo(f"{config.suffix=} != '.json'")
raise typer.Abort()

Check warning on line 88 in pyaerocom/scripts/cli.py

View check run for this annotation

Codecov / codecov/patch

pyaerocom/scripts/cli.py#L87-L88

Added lines #L87 - L88 were not covered by tests

Expand Down
23 changes: 23 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from importlib import metadata
from pathlib import Path

Expand Down Expand Up @@ -65,3 +66,25 @@ def test_browse():
def test_ppiaccess():
result = runner.invoke(main, ["ppiaccess"])
assert result.exit_code == 0


@pytest.fixture()
def config_json(monkeypatch, tmp_path: Path, eval_config: dict) -> Path:
def do_not_run(self, model_name=None, obs_name=None, var_list=None, update_interface=True):
assert model_name is None
assert obs_name is None
assert var_list is None
assert update_interface is True

monkeypatch.setattr("pyaerocom.scripts.cli.ExperimentProcessor.run", do_not_run)

path = tmp_path / "conf.json"
path.write_text(json.dumps(eval_config))
return path


@pytest.mark.parametrize("cfg", ("cfgexp1",))
def test_aeroval(config_json: Path):
assert config_json.is_file()
result = runner.invoke(main, ["aeroval", str(config_json)])
assert result.exit_code == 0

0 comments on commit cfc9177

Please sign in to comment.