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
5 changes: 5 additions & 0 deletions codecarbon/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ def _external_config() -> dict:
)
def monitor(
ctx: typer.Context,
project_name: Annotated[
str,
typer.Option(help="Project name for the current experiment."),
] = None,
measure_power_secs: Annotated[
int,
typer.Option(help="Interval between two measures."),
Expand Down Expand Up @@ -427,6 +431,7 @@ def monitor(
# Only the options actually given are forwarded: the others are left to the
# tracker, which resolves them from the configuration file and environment.
cli_defaults = (
("project_name", project_name),
("measure_power_secs", measure_power_secs),
("api_call_interval", api_call_interval),
("log_level", log_level),
Expand Down
37 changes: 37 additions & 0 deletions tests/cli/test_cli_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,43 @@ def test_monitor_run_and_monitor(monkeypatch):
assert "Hello, World!" in result.output


def test_monitor_accepts_tracker_options(monkeypatch):
captured = {}

class FakeTracker:
def __init__(self, **kwargs):
captured.update(kwargs)

def start(self):
pass

def stop(self):
pass

monkeypatch.setattr(
"codecarbon.emissions_tracker.EmissionsTracker",
FakeTracker,
)
monkeypatch.setattr(cli_main, "get_existing_exp_id", lambda: "test-exp")

runner = CliRunner()
result = runner.invoke(
cli_main.codecarbon,
[
"monitor",
"--project-name",
"test-project",
"--no-api",
"--",
"echo",
"test",
],
)

assert result.exit_code == 0, result.output
assert captured["project_name"] == "test-project"


def test_show_config_handles_access_token_errors(monkeypatch, tmp_path, capsys):
class FakeApiClient:
def __init__(self, endpoint_url=None):
Expand Down
Loading