Skip to content
Merged
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
121 changes: 44 additions & 77 deletions tests/test_kcidev.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,90 +212,58 @@ def test_kcidev_results_summary_history_import():
assert "/" in result # Should contain separators


def test_kcidev_results_hardware_list():
"""Test that hardware list command works and returns expected output format"""
command = [
"poetry",
"run",
"kci-dev",
"results",
"hardware",
"list",
"--origin",
"maestro",
]
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)

print("returncode: " + str(result.returncode))
print("#### stdout ####")
print(result.stdout)
print("#### stderr ####")
print(result.stderr)

# Test should succeed
assert result.returncode == 0

# Should contain hardware entries with expected format
output_lines = result.stdout.strip().split("\n")

# Should have at least some hardware entries
assert len(output_lines) > 0

# Check format: lines should contain "- name:" and "compatibles:"
name_lines = [line for line in output_lines if line.strip().startswith("- name:")]
compatible_lines = [
line for line in output_lines if line.strip().startswith("compatibles:")
]

# Should have matching number of name and compatible lines
assert len(name_lines) > 0
assert len(compatible_lines) > 0
assert len(name_lines) == len(compatible_lines)

def test_kcidev_results_hardware_list(monkeypatch):
"""Test hardware list formatting without relying on dashboard network access."""
import importlib

from click.testing import CliRunner

hardware_module = importlib.import_module("kcidev.subcommands.results.hardware")

monkeypatch.setattr(
hardware_module,
"dashboard_fetch_hardware_list",
lambda origin, use_json: {
"hardware": [
{"hardware": "qemu-arm64", "platform": "linux,dummy"},
{"hardware": "qemu-x86", "platform": "linux,pc"},
]
},
)

def test_kcidev_results_hardware_list_json():
"""Test that hardware list command works with JSON output"""
command = [
"poetry",
"run",
"kci-dev",
"results",
"hardware",
"list",
"--origin",
"maestro",
"--json",
]
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
result = CliRunner().invoke(
hardware_module.hardware, ["list", "--origin", "maestro"]
)

print("returncode: " + str(result.returncode))
print("#### stdout ####")
print(result.stdout[:500] + "..." if len(result.stdout) > 500 else result.stdout)
print("#### stderr ####")
print(result.stderr)
assert result.exit_code == 0, result.output
assert "- name: qemu-arm64" in result.output
assert "compatibles: linux,dummy" in result.output

# Test should succeed
assert result.returncode == 0

# Should be valid JSON
def test_kcidev_results_hardware_list_json(monkeypatch):
"""Test hardware list JSON output without dashboard network access."""
import importlib
import json

try:
data = json.loads(result.stdout)
assert isinstance(data, list)
from click.testing import CliRunner

# Should have at least some hardware entries
assert len(data) > 0
hardware_module = importlib.import_module("kcidev.subcommands.results.hardware")

# Each entry should have 'name' and 'compatibles' fields
for entry in data[:5]: # Check first 5 entries
assert "name" in entry
assert "compatibles" in entry
assert isinstance(entry["name"], str)
assert isinstance(entry["compatibles"], str)
monkeypatch.setattr(
hardware_module,
"dashboard_fetch_hardware_list",
lambda origin, use_json: {
"hardware": [{"hardware": "qemu-arm64", "platform": "linux,dummy"}]
},
)

result = CliRunner().invoke(
hardware_module.hardware, ["list", "--origin", "maestro", "--json"]
)

except json.JSONDecodeError:
pytest.fail("Output is not valid JSON")
assert result.exit_code == 0, result.output
data = json.loads(result.output)
assert data == [{"name": "qemu-arm64", "compatibles": "linux,dummy"}]


def test_kcidev_results_compare_help():
Expand Down Expand Up @@ -923,12 +891,11 @@ def test_kcidev_results_build_with_real_id():
def test_kcidev_session_user_agent():
ua = kcidev_session.headers["User-Agent"]
assert ua == f"kci-dev/{kcidev_version}"
assert kcidev_version != "unknown"


def test_kcidev_version_from_metadata():
assert isinstance(kcidev_version, str)
assert re.match(r"^\d+\.\d+\.\d+", kcidev_version)
assert kcidev_version == "unknown" or re.match(r"^\d+\.\d+\.\d+", kcidev_version)


def test_kcidev_submit_help():
Expand Down
Loading