Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.
Merged
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import inspect
import logging
from dataclasses import dataclass

Expand Down Expand Up @@ -50,11 +49,6 @@ def base():

for k, v in self.children.items():
if hasattr(v, "cli"):
# Check if the cli method accepts a click_group parameter
sig = inspect.signature(v.cli)
if "click_group" in sig.parameters:
base.add_command(v.cli(click_group=base), k)
else:
base.add_command(v.cli(), k)
base.add_command(v.cli(), k)

return base
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class SSHWrapperClient(CompositeClient):
This client provides methods to interact with SSH connections via CLI
"""

def cli(self, click_group):
@click_group.command(context_settings={"ignore_unknown_options": True})
def cli(self):
@click.command(context_settings={"ignore_unknown_options": True})
@click.option("--direct", is_flag=True, help="Use direct TCP address")
@click.argument("args", nargs=-1)
def ssh(direct, args):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class TMTClient(CompositeClient):
This client provides methods to interact with LocalTMT devices via SSH
"""

def cli(self, click_group):
def cli(self):

@click_group.command(context_settings={"ignore_unknown_options": True})
@click.command(context_settings={"ignore_unknown_options": True})
@click.option("--forward-ssh", is_flag=True)
@click.option("--tmt-username", default=None)
@click.option("--tmt-password", default=None)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from unittest.mock import MagicMock, patch

import click
import pytest
from click.testing import CliRunner
from jumpstarter_driver_network.driver import TcpNetwork
Expand All @@ -24,18 +23,18 @@ def test_drivers_tmt_cli():
with serve(instance) as client:
# Test the CLI tmt command without arguments
runner = CliRunner()
cli = client.cli(click.Group())
cli = client.cli()

with patch.object(client, '_run_tmt_local') as mock_run_tmt:
mock_run_tmt.return_value = 0 # Success return code
result = runner.invoke(cli, ["tmt"])
result = runner.invoke(cli, [])
assert result.exit_code == 0
mock_run_tmt.assert_called_once()

# Test the CLI tmt command with arguments
with patch.object(client, '_run_tmt_local') as mock_run_tmt:
mock_run_tmt.return_value = 0 # Success return code
result = runner.invoke(cli, ["tmt", "test", "arg1", "arg2"])
result = runner.invoke(cli, ["test", "arg1", "arg2"])
assert result.exit_code == 0
mock_run_tmt.assert_called_once()

Expand All @@ -46,28 +45,28 @@ def test_drivers_tmt_cli_with_options():

with serve(instance) as client:
runner = CliRunner()
cli = client.cli(click.Group())
cli = client.cli()

# Test with --forward-ssh flag
with patch.object(client, '_run_tmt_local') as mock_run_tmt:
mock_run_tmt.return_value = 0 # Success return code
result = runner.invoke(cli, ["tmt", "--forward-ssh", "test"])
result = runner.invoke(cli, ["--forward-ssh", "test"])
assert result.exit_code == 0
mock_run_tmt.assert_called_once()

# Test with custom username and password
with patch.object(client, '_run_tmt_local') as mock_run_tmt:
mock_run_tmt.return_value = 0 # Success return code
result = runner.invoke(
cli, ["tmt", "--tmt-username", "custom_user", "--tmt-password", "custom_pass", "test"]
cli, ["--tmt-username", "custom_user", "--tmt-password", "custom_pass", "test"]
)
assert result.exit_code == 0
mock_run_tmt.assert_called_once()

# Test with custom tmt command
with patch.object(client, '_run_tmt_local') as mock_run_tmt:
mock_run_tmt.return_value = 0 # Success return code
result = runner.invoke(cli, ["tmt", "--tmt-cmd", "custom-tmt", "test"])
result = runner.invoke(cli, ["--tmt-cmd", "custom-tmt", "test"])
assert result.exit_code == 0
mock_run_tmt.assert_called_once()

Expand All @@ -78,12 +77,12 @@ def test_drivers_tmt_cli_error_handling():

with serve(instance) as client:
runner = CliRunner()
cli = client.cli(click.Group())
cli = client.cli()

# Test CLI with non-zero return code
with patch.object(client, '_run_tmt_local') as mock_run_tmt:
mock_run_tmt.return_value = 1 # Error return code
result = runner.invoke(cli, ["tmt", "test"])
result = runner.invoke(cli, ["test"])
assert result.exit_code == 1
mock_run_tmt.assert_called_once()

Expand All @@ -94,10 +93,10 @@ def test_drivers_tmt_cli_tmt_on_exporter():

with serve(instance) as client:
runner = CliRunner()
cli = client.cli(click.Group())
cli = client.cli()

# Test CLI with --tmt-on-exporter flag (should abort)
result = runner.invoke(cli, ["tmt", "--tmt-on-exporter", "test"])
result = runner.invoke(cli, ["--tmt-on-exporter", "test"])
assert result.exit_code == 1 # click.Abort() returns exit code 1
assert "TMT will be run on the exporter" in result.output
assert "Aborted!" in result.output
Expand Down Expand Up @@ -428,11 +427,11 @@ def test_drivers_tmt_cli_logging():

with serve(instance) as client:
runner = CliRunner()
cli = client.cli(click.Group())
cli = client.cli()

with patch.object(client, '_run_tmt_local') as mock_run_tmt:
mock_run_tmt.return_value = 0
with patch.object(client.logger, 'debug') as mock_debug:
result = runner.invoke(cli, ["tmt", "test"])
result = runner.invoke(cli, ["test"])
assert result.exit_code == 0
mock_debug.assert_called_with("TMT result: 0")
4 changes: 3 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading