from __future__ import annotations

import pytest

from pymuclient import epy


def test_extract_attach_value_variants() -> None:
    assert epy._extract_attach_value(["-a", "can0@500000"]) == "can0@500000"
    assert epy._extract_attach_value(["--attach", "gs_usb:0@500000"]) == "gs_usb:0@500000"
    assert epy._extract_attach_value(["--attach=socketcan:can0@500000"]) == "socketcan:can0@500000"
    assert epy._extract_attach_value(["--log"]) is None


def test_missing_server_can_dependencies_uses_attach_target(monkeypatch: pytest.MonkeyPatch) -> None:
    from pymulator.core import can as can_module

    captured: dict[str, str] = {}

    def _fake_missing(interface: str) -> list[str]:
        captured["interface"] = interface
        return ["gs_usb"]

    monkeypatch.setattr(can_module, "missing_python_can_modules", _fake_missing)

    missing = epy._missing_server_can_dependencies(["--attach", "can0@500000"])

    assert missing == ["gs_usb"]
    assert captured["interface"] == "can0"
