Something went wrong. Try again.
A Material 3 inspired desktop shell for Niri and Hyprland created with Ignis.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148from modules.network import presentation as pfrom modules.network.model import ( Capabilities, Connectivity, ErrorCode, EthernetLink, LinkDetails, LinkState, NetworkError, NetworkSnapshot, Security, WifiNetwork, WifiState,)
def net(ssid, strength=60, state=LinkState.IDLE, saved=False, security=Security.PSK): return WifiNetwork(ssid, ssid, security, strength, state=state, saved=saved)
def snap(networks=(), enabled=True, available=True, scanning=False, ethernet=(), connectivity=Connectivity.FULL, link=None): station = LinkState.IDLE for n in networks: if n.state is not LinkState.IDLE: station = n.state return NetworkSnapshot( backend="iwd", wifi=WifiState(available, enabled, scanning, station, tuple(networks), link), ethernet=tuple(ethernet), connectivity=connectivity, capabilities=Capabilities(), )
def test_every_error_code_has_text(): for code in ErrorCode: assert p.error_message(NetworkError(code)) assert p.error_message(RuntimeError("x")) == p.ERROR_TEXT[ErrorCode.FAILED]
def test_cancel_is_ignored(): assert p.should_ignore(NetworkError(ErrorCode.CANCELLED)) assert not p.should_ignore(NetworkError(ErrorCode.FAILED))
def test_sections_group_and_order(): networks = ( net("zeta", 90), net("home", 40, saved=True), net("cafe", 80), net("work", 70, state=LinkState.CONNECTED, saved=True), net("busy", 50, state=LinkState.CONNECTING), ) result = p.sections(networks) assert [key for key, _, _ in result] == ["current", "saved", "available"] assert [n.ssid for n in result[0][2]] == ["work", "busy"] assert [n.ssid for n in result[1][2]] == ["home"] assert [n.ssid for n in result[2][2]] == ["zeta", "cafe"]
def test_sections_filter_and_drop_empty(): networks = (net("Home"), net("Office", saved=True)) result = p.sections(networks, " HOM ") assert [(k, [n.ssid for n in m]) for k, _, m in result] == [("available", ["Home"])] assert p.sections(networks, "nothing") == []
def test_password_prompt_rules(): assert p.needs_password_prompt(net("a")) assert not p.needs_password_prompt(net("a", saved=True)) assert not p.needs_password_prompt(net("a", security=Security.OPEN)) assert not p.is_supported(net("a", security=Security.ENTERPRISE)) assert p.is_supported(net("a", security=Security.ENTERPRISE, saved=True))
def test_row_subtitle(): assert p.row_subtitle(net("a", 80, saved=True)) == "Saved · WPA · Excellent" assert p.row_subtitle(net("a", 10, security=Security.OPEN)) == "Open · Weak"
def test_headline_wifi_connected(): link = LinkDetails(frequency_mhz=5180) h = p.headline(snap([net("home", 80, LinkState.CONNECTED)], link=link)) assert (h.title, h.tone) == ("home", "ok") assert h.subtitle == "Excellent · 5 GHz · Internet access"
def test_headline_prefers_ethernet(): wired = EthernetLink("enp1", True, 1000, "aa:bb") h = p.headline(snap([net("home", 80, LinkState.CONNECTED)], ethernet=[wired])) assert h.title == "Ethernet" assert h.subtitle == "1.0 Gbps · Internet access"
def test_headline_states(): assert p.headline(snap(available=False)).title == "No Wi-Fi adapter" assert p.headline(snap(enabled=False)).title == "Wi-Fi is off" assert p.headline(snap(scanning=True)).tone == "busy" assert p.headline(snap()).title == "Not connected" busy = p.headline(snap([net("x", state=LinkState.CONNECTING)])) assert busy.tone == "busy" and "Connecting" in busy.subtitle
def test_headline_warns_without_internet(): h = p.headline(snap([net("home", 80, LinkState.CONNECTED)], connectivity=Connectivity.LIMITED)) assert h.tone == "warn"
def test_bar_icons(): assert p.bar_state(snap(available=False)).icon is None assert p.bar_state(snap(enabled=False)).icon == "signal_wifi_off" assert p.bar_state(snap()).icon == "signal_wifi_statusbar_not_connected" assert p.bar_state(snap([net("x", state=LinkState.CONNECTING)])).icon == "wifi_find" strong = p.bar_state(snap([net("x", 90, LinkState.CONNECTED)])) assert strong.icon == "signal_wifi_4_bar" and "x" in strong.tooltip weak = p.bar_state(snap([net("x", 90, LinkState.CONNECTED)], connectivity=Connectivity.LIMITED)) assert weak.icon == "signal_wifi_bad" portal = p.bar_state(snap([net("x", 90, LinkState.CONNECTED)], connectivity=Connectivity.PORTAL)) assert portal.icon == "captive_portal" wired = EthernetLink("enp1", True) assert p.bar_state(snap(available=False, ethernet=[wired])).icon == "settings_ethernet"
def test_link_facts(): assert p.link_facts(None) == [] facts = p.link_facts(LinkDetails("aa:bb", 2412, rx_mbps=866.7, tx_mbps=1200)) assert facts == [ ("router", "2.4 GHz"), ("arrow_downward", "867 Mbps"), ("arrow_upward", "1.2 Gbps"), ("fingerprint", "AA:BB"), ] assert ("speed", "up to 300 Mbps") in p.link_facts(LinkDetails(max_mbps=300))
def test_ethernet_text(): assert p.ethernet_subtitle(EthernetLink("e", False)) == "Cable unplugged" assert p.ethernet_subtitle(EthernetLink("e", True, 100, "aa")) == "100 Mbps · AA"
def test_passphrase_problem(): assert p.passphrase_problem("") is not None assert p.passphrase_problem("short") is not None assert p.passphrase_problem("x" * 64) is not None assert p.passphrase_problem("x" * 8) is None assert p.passphrase_problem("x" * 63) is None