feat(bridge): add wifi/serial bridge runtime and UI
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
66
tests/test_pi_wifi_scan.py
Normal file
66
tests/test_pi_wifi_scan.py
Normal file
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Tests for nmcli Wi‑Fi scan parsing."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / "src"))
|
||||
|
||||
from util.pi_wifi import _unescape_nmcli # noqa: E402
|
||||
|
||||
|
||||
def test_unescape_nmcli():
|
||||
assert _unescape_nmcli("bridge\\:abc") == "bridge:abc"
|
||||
assert _unescape_nmcli("plain") == "plain"
|
||||
|
||||
|
||||
def test_interface_display_name_fallback(monkeypatch):
|
||||
from util import pi_wifi
|
||||
|
||||
monkeypatch.setattr(
|
||||
pi_wifi,
|
||||
"_interface_display_name",
|
||||
lambda device: "Test Wi‑Fi" if device == "wlan0" else device,
|
||||
)
|
||||
import subprocess
|
||||
|
||||
def fake_run(*args, **kwargs):
|
||||
class _R:
|
||||
stdout = "wlan0:wifi:connected:HomeNet\neth0:ethernet:connected:\n"
|
||||
|
||||
return _R()
|
||||
|
||||
monkeypatch.setattr(subprocess, "run", fake_run)
|
||||
ifaces = pi_wifi.list_wifi_interfaces()
|
||||
assert len(ifaces) == 1
|
||||
assert ifaces[0]["device"] == "wlan0"
|
||||
assert ifaces[0]["label"] == "Test Wi‑Fi"
|
||||
assert ifaces[0]["connection"] == "HomeNet"
|
||||
|
||||
|
||||
def test_scan_wifi_parses_terse_nmcli(monkeypatch):
|
||||
import asyncio
|
||||
|
||||
from util import pi_wifi
|
||||
|
||||
sample = "\n".join(
|
||||
[
|
||||
"bridge-588c81a2fc18:84:",
|
||||
"My Network:72:WPA2",
|
||||
":50:WPA2",
|
||||
"led:100:WPA2",
|
||||
]
|
||||
)
|
||||
|
||||
async def fake_run(*args, **kwargs):
|
||||
return 0, sample, ""
|
||||
|
||||
monkeypatch.setattr(pi_wifi, "_run_nmcli", fake_run)
|
||||
|
||||
networks = asyncio.run(pi_wifi.scan_wifi("wlan0"))
|
||||
ssids = [n["ssid"] for n in networks]
|
||||
assert ssids == ["led", "bridge-588c81a2fc18", "My Network"]
|
||||
assert networks[0]["signal"] == 100
|
||||
Reference in New Issue
Block a user