Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/cloudai/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ def common_options(f):
"--system-config",
"system_cfg",
required=True,
envvar="CLOUDAI_SYSTEM_CONFIG",
type=click.Path(exists=True, resolve_path=True, path_type=Path),
help="System config path.",
help="System config path. Can also be set via the CLOUDAI_SYSTEM_CONFIG environment variable.",
)(f)
f = click.option(
"--tests-dir",
Expand Down
41 changes: 41 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,47 @@ def test_tests_dir_is_optional(tmp_path: Path):
assert "Missing option '--tests-dir'" not in result.output


def test_system_config_can_be_set_via_env_var(tmp_path: Path):
system_cfg, scenario_cfg = tmp_path / "system.toml", tmp_path / "scenario.toml"
system_cfg.touch()
scenario_cfg.touch()
runner = CliRunner()
result = runner.invoke(
main,
["run", "--test-scenario", str(scenario_cfg)],
env={"CLOUDAI_SYSTEM_CONFIG": str(system_cfg)},
)
assert "Missing option '--system-config'" not in result.output

Comment thread
coderabbitai[bot] marked this conversation as resolved.

def test_system_config_flag_takes_precedence_over_env_var(tmp_path: Path):
system_cfg, other_cfg, scenario_cfg = (
tmp_path / "system.toml",
tmp_path / "other.toml",
tmp_path / "scenario.toml",
)
system_cfg.touch()
other_cfg.touch()
scenario_cfg.touch()
runner = CliRunner()
result = runner.invoke(
main,
["run", "--system-config", str(system_cfg), "--test-scenario", str(scenario_cfg)],
env={"CLOUDAI_SYSTEM_CONFIG": str(other_cfg)},
)
assert "Missing 'scheduler' key" in result.output
assert str(system_cfg) in result.output
assert str(other_cfg) not in result.output


@pytest.mark.parametrize("subcommand", ["install", "uninstall", "dry-run", "run", "generate-report"])
def test_system_config_env_var_documented_in_help(subcommand: str):
runner = CliRunner()
result = runner.invoke(main, [subcommand, "--help"])
assert result.exit_code == 0
assert "CLOUDAI_SYSTEM_CONFIG" in result.output


@pytest.mark.parametrize("subcommand", ["install", "uninstall", "dry-run", "run", "generate-report"])
def test_hook_dir_is_available_on_run_commands(subcommand: str):
runner = CliRunner()
Expand Down
Loading