Skip to content

Commit

Permalink
Merge pull request #1043 from haddocking/update-main-cli-description
Browse files Browse the repository at this point in the history
Update main cli description
  • Loading branch information
VGPReys authored Sep 24, 2024
2 parents 13d11cc + 1a9df1e commit f9dcc9b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
17 changes: 10 additions & 7 deletions src/haddock/clis/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@
ap = argparse.ArgumentParser()

ap.add_argument(
"recipe",
"workflow",
type=arg_file_exist,
help="The input recipe file path",
)
help=(
"The input configuration file path describing "
"the workflow to be performed"
),
)

add_restart_arg(ap)
add_extend_run(ap)
Expand Down Expand Up @@ -76,7 +79,7 @@ def maincli() -> None:


def main(
recipe: FilePath,
workflow: FilePath,
restart: Optional[int] = None,
extend_run: Optional[FilePath] = EXTEND_RUN_DEFAULT,
setup_only: bool = False,
Expand All @@ -87,8 +90,8 @@ def main(
Parameters
----------
recipe : str or pathlib.Path
The path to the recipe (config file).
workflow : str or pathlib.Path
The path to the workflow (config file).
restart : int
The step to restart the run from (inclusive).
Expand Down Expand Up @@ -145,7 +148,7 @@ def main(

with log_error_and_exit():
params, other_params = setup_run(
recipe,
workflow,
restart_from=restart,
extend_run=extend_run,
)
Expand Down
30 changes: 16 additions & 14 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from . import configs_data


recipe = Path(configs_data, 'recipe.cfg')
@pytest.fixture(name="workflow")
def fixture_workflow():
yield Path(configs_data, "recipe.cfg")


def test_cli_has_maincli():
Expand All @@ -21,29 +23,29 @@ def test_cli_has_maincli():


def test_ap_recipe_does_not_exist():
"""Test raise error if recipe does not exist."""
"""Test raise error if workflow does not exist."""
with pytest.raises(SystemExit) as exit:
cli.ap.parse_args('does_not_exit.cfg'.split())
assert exit.type == SystemExit
assert exit.value.code == 2


def test_ap_recipe_exists():
"""Test reading recipes."""
cmd = cli.ap.parse_args(str(recipe).split())
with open(cmd.recipe) as fin:
def test_ap_workflow_exists(workflow):
"""Test reading workflows."""
cmd = cli.ap.parse_args(str(workflow).split())
with open(cmd.workflow) as fin:
fin.readlines()


def test_ap_setup_true():
def test_ap_setup_true(workflow):
"""Test --setup flag."""
cmd = cli.ap.parse_args(f'{recipe} --setup'.split())
cmd = cli.ap.parse_args(f'{workflow} --setup'.split())
assert cmd.setup_only is True


def test_ap_setup_false():
def test_ap_setup_false(workflow):
"""Test setup only default."""
cmd = cli.ap.parse_args(str(recipe).split())
cmd = cli.ap.parse_args(str(workflow).split())
assert cmd.setup_only is False


Expand All @@ -59,15 +61,15 @@ def test_ap_version():
'level',
("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"),
)
def test_ap_log_level(level):
def test_ap_log_level(workflow, level):
"""Test --log-level correct."""
cmd = cli.ap.parse_args(f'{recipe} --log-level {level}'.split())
cmd = cli.ap.parse_args(f'{workflow} --log-level {level}'.split())
assert cmd.log_level == level


def test_ap_log_level_error():
def test_ap_log_level_error(workflow):
"""Test --log-level error with bad input."""
with pytest.raises(SystemExit) as exit:
cli.ap.parse_args(f'{recipe} --log-level BAD'.split())
cli.ap.parse_args(f'{workflow} --log-level BAD'.split())
assert exit.type == SystemExit
assert exit.value.code == 2

0 comments on commit f9dcc9b

Please sign in to comment.