from __future__ import annotations

from pymuclient import epy


def test_usage_lists_spec_commands() -> None:
    usage = epy._usage("epy")
    assert "spec compile" in usage
    assert "spec explode" in usage


def test_main_dispatches_spec_command(monkeypatch) -> None:
    dispatched: dict[str, list[str]] = {}
    monkeypatch.setattr(epy, "_maybe_check_update", lambda interactive: None)
    monkeypatch.setattr(epy, "_missing_dependencies", lambda: [])
    monkeypatch.setattr(epy, "_dispatch_spec", lambda argv: dispatched.setdefault("argv", argv))

    epy.main(["spec", "compile", "in.vehicle", "-o", "out.vehicle"])

    assert dispatched["argv"] == ["compile", "in.vehicle", "-o", "out.vehicle"]


def test_main_dispatches_spec_explode_command(monkeypatch) -> None:
    dispatched: dict[str, list[str]] = {}
    monkeypatch.setattr(epy, "_maybe_check_update", lambda interactive: None)
    monkeypatch.setattr(epy, "_missing_dependencies", lambda: [])
    monkeypatch.setattr(epy, "_dispatch_spec", lambda argv: dispatched.setdefault("argv", argv))

    epy.main(["spec", "explode", "in.vehicle", "-o", "out.vehicleproj"])

    assert dispatched["argv"] == ["explode", "in.vehicle", "-o", "out.vehicleproj"]
