Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/tests/test_cli.py
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
def _write_usage(command, args, max_width=80): | def _write_usage(command, args, max_width=80): | ||||
hf = HelpFormatter(width=max_width) | hf = HelpFormatter(width=max_width) | ||||
hf.write_usage(command, args) | hf.write_usage(command, args) | ||||
return hf.getvalue()[:-1] | return hf.getvalue()[:-1] | ||||
def test_run_help(swh_config): | def test_run_help(swh_config): | ||||
"""Help message should be ok | """Usage message should contain list of available loaders | ||||
""" | """ | ||||
runner = CliRunner() | runner = CliRunner() | ||||
result = runner.invoke(loader_cli, ["run", "-h"]) | result = runner.invoke(loader_cli, ["run", "-h"]) | ||||
assert result.exit_code == 0 | assert result.exit_code == 0 | ||||
usage_prefix = _write_usage( | usage_prefix = _write_usage( | ||||
"loader", f"run [OPTIONS] [{'|'.join(SUPPORTED_LOADERS)}]\n" | "loader run", f"[OPTIONS] [{'|'.join(SUPPORTED_LOADERS)}]\n" | ||||
) | ) | ||||
assert result.output.startswith(usage_prefix) | assert result.output.startswith(usage_prefix) | ||||
def test_run_with_configuration_failure(tmp_path): | def test_run_with_configuration_failure(tmp_path): | ||||
"""Triggering a load should fail since configuration is incomplete | """Triggering a load should fail since configuration is incomplete | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | mock_loader.assert_called_once_with( | ||||
"npm", | "npm", | ||||
storage={"cls": "memory"}, | storage={"cls": "memory"}, | ||||
url="https://some-url", | url="https://some-url", | ||||
visit_date=expected_parsed_date, | visit_date=expected_parsed_date, | ||||
) | ) | ||||
def test_list_help(mocker, swh_config): | def test_list_help(mocker, swh_config): | ||||
"""Triggering a load should be ok | """Usage message should contain list of available loaders | ||||
""" | """ | ||||
runner = CliRunner() | runner = CliRunner() | ||||
result = runner.invoke(loader_cli, ["list", "--help"]) | result = runner.invoke(loader_cli, ["list", "--help"]) | ||||
assert result.exit_code == 0 | assert result.exit_code == 0 | ||||
usage_prefix = _write_usage("loader", "list [OPTIONS]\n") | usage_prefix = _write_usage( | ||||
"loader list", f"[OPTIONS] [[{'|'.join(['all'] + SUPPORTED_LOADERS)}]]" | |||||
) | |||||
expected_help_msg = f"""{usage_prefix} | expected_help_msg = f"""{usage_prefix} | ||||
[[{'|'.join(['all'] + SUPPORTED_LOADERS)}]] | |||||
List supported loaders and optionally their arguments | List supported loaders and optionally their arguments | ||||
Options: | Options: | ||||
-h, --help Show this message and exit. | -h, --help Show this message and exit. | ||||
""" | """ | ||||
assert result.output.startswith(expected_help_msg) | assert result.output.startswith(expected_help_msg) | ||||
Show All 12 Lines |