| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import copy
- import sys
- import unittest
- from pathlib import Path
- ROOT = Path(__file__).resolve().parents[1]
- sys.path.insert(0, str(ROOT / "scripts"))
- from observe_pipewire import load_state, observe, parse_pw_link_output, validate_managed_links
- CAPTURE_0 = "alsa_input.hw_U192k_0:capture_AUX0"
- CAPTURE_2 = "alsa_input.hw_U192k_0:capture_AUX2"
- CAPTURE_3 = "alsa_input.hw_U192k_0:capture_AUX3"
- PLAYBACK_0 = "alsa_output.hw_U192k_0:playback_AUX0"
- class PipeWireObserverTests(unittest.TestCase):
- @classmethod
- def setUpClass(cls):
- cls.state = load_state(ROOT / "config" / "desired-state.yaml")
- def test_empty_managed_set_ignores_wireplumber_hardware_links(self):
- observed = parse_pw_link_output(
- "alsa_output.usb-umc:Line1.split:output_AUX0\n"
- f" |-> {PLAYBACK_0}\n"
- f"{CAPTURE_0}\n"
- " |-> alsa_input.usb-umc:Mic1.split:input_AUX0\n"
- )
- self.assertEqual(observe(self.state, observed), [])
- def test_reports_missing_and_unexpected_managed_links_without_mutating(self):
- state = copy.deepcopy(self.state)
- state["routing"]["managed_ports"] = [CAPTURE_0, CAPTURE_2, CAPTURE_3, PLAYBACK_0]
- state["routing"]["managed_links"] = [
- {"from": CAPTURE_0, "to": PLAYBACK_0, "status": "planned"},
- {"from": CAPTURE_2, "to": PLAYBACK_0, "status": "observed"},
- ]
- observed = {
- (CAPTURE_2, PLAYBACK_0),
- (CAPTURE_3, PLAYBACK_0),
- }
- reports = observe(state, observed)
- self.assertEqual(
- reports,
- [
- {"kind": "missing", "from": CAPTURE_0, "to": PLAYBACK_0, "action": "would-link"},
- {"kind": "unexpected", "from": CAPTURE_3, "to": PLAYBACK_0, "action": "would-review"},
- ],
- )
- self.assertEqual(state["routing"]["managed_links"][0]["status"], "planned")
- def test_parser_handles_incoming_and_outgoing_link_views(self):
- links = parse_pw_link_output(
- f"{CAPTURE_0}\n"
- f" |-> {PLAYBACK_0}\n"
- f"{PLAYBACK_0}\n"
- f" |<- {CAPTURE_0}\n"
- )
- self.assertEqual(links, {(CAPTURE_0, PLAYBACK_0)})
- def test_rejects_logical_mix_endpoint(self):
- state = copy.deepcopy(self.state)
- state["routing"]["managed_ports"] = [PLAYBACK_0]
- state["routing"]["managed_links"] = [
- {"from": "direct_mix", "to": PLAYBACK_0, "status": "planned"}
- ]
- self.assertTrue(any("concrete UMC AUX port" in error for error in validate_managed_links(state)))
- def test_managed_links_must_use_declared_ports(self):
- state = copy.deepcopy(self.state)
- state["routing"]["managed_links"] = [
- {"from": CAPTURE_0, "to": PLAYBACK_0, "status": "planned"}
- ]
- self.assertTrue(any("endpoints must be listed" in error for error in validate_managed_links(state)))
- if __name__ == "__main__":
- unittest.main()
|