from . import boardtype

import subprocess
import pytest


@pytest.mark.skipif(not boardtype.is_devkit(), reason="Not a devkit")
def test_modem_usb():
    "Test if the modem is visible on the USB bus"
    out = subprocess.check_output(["lsusb", "-d", "1e0e:9001"])
    assert(b"Qualcom" in out)


def test_modem_modem_manager():
    "Test if modem manager picked up the modem"
    out = subprocess.check_output(["mmcli", "-m", "0"])
    if boardtype.is_librem5():
        assert(b"manufacturer: QUALCOMM INCORPORATED" in out)
    else:
        assert(b"model: SIMCOM_SIM7100" in out)


def test_modem_alsa():
    "Test if the modem is seen by alsa"
    out = subprocess.run(["aplay", "-l"], capture_output=True)
    assert(out.returncode == 0)
    if boardtype.is_librem5():
        assert((b"gtm601" in out.stdout) or (b"bm818" in out.stdout))
    else:
        assert(b": SIM7100 [SIMCom SIM7100]" in out.stdout)


@pytest.mark.skipif(not boardtype.is_librem5(), reason="Not a phone")
def test_modem_bm818():
    "Test if the modem is visible on the USB bus"
    out = subprocess.check_output(["lsusb", "-d", "2020:2060"])
    assert(b"2020:2060" in out)
