"""Pure-parser test for midistream.parse_ports (no ALSA)."""
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
import midistream as MS

SAMPLE = """ Port    Client name                      Port name
  0:0    System                           Timer
  0:1    System                           Announce
 14:0    Midi Through                     Midi Through Port-0
 28:0    nanoKONTROL2                     nanoKONTROL2 MIDI 1
"""


def test_parse_ports_skips_header_and_parses_rows():
    ports = MS.parse_ports(SAMPLE)
    assert {"addr": "28:0", "client": "nanoKONTROL2", "port": "nanoKONTROL2 MIDI 1"} in ports
    assert all(":" in p["addr"] for p in ports)
    assert not any(p["client"] == "Client name" for p in ports)  # header skipped
    assert len(ports) == 4


def test_parse_ports_empty():
    assert MS.parse_ports("") == []
