mirror of
https://github.com/cloudstack-llc/mlx-knife.git
synced 2026-07-22 02:25:23 -04:00
2624210353
- Enforce strict JSON API in tests - Introduce --version --json as sole version reporter
26 lines
762 B
Python
26 lines
762 B
Python
import sys
|
|
import json
|
|
import pytest
|
|
|
|
|
|
@pytest.mark.spec
|
|
def test_cli_list_accepts_json_after_command(monkeypatch, capsys, isolated_cache):
|
|
from mlxk2 import cli
|
|
|
|
monkeypatch.setenv("PYTHONWARNINGS", "ignore")
|
|
monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", "1")
|
|
|
|
# Ensure we pass --json after the subcommand, as users would
|
|
monkeypatch.setattr(sys, "argv", ["mlxk2", "list", "--json"])
|
|
with pytest.raises(SystemExit) as exc:
|
|
cli.main()
|
|
assert exc.value.code == 0
|
|
|
|
out = capsys.readouterr().out.strip()
|
|
data = json.loads(out)
|
|
assert data["status"] == "success"
|
|
assert data["command"] == "list"
|
|
assert data["error"] is None
|
|
assert "data" in data and "models" in data["data"] and "count" in data["data"]
|
|
|