test_mod_host_ports.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import sys
  2. import unittest
  3. from pathlib import Path
  4. from types import SimpleNamespace
  5. import yaml
  6. ROOT = Path(__file__).resolve().parents[1]
  7. sys.path.insert(0, str(ROOT / "scripts"))
  8. from run_mod_host_ports import assert_boundary_ports_absent, loopback_command
  9. class ModHostPipeWirePortTests(unittest.TestCase):
  10. @classmethod
  11. def setUpClass(cls):
  12. cls.state = yaml.safe_load(
  13. (ROOT / "config" / "desired-state.yaml").read_text(encoding="utf-8")
  14. )
  15. def test_input_and_output_loopbacks_expose_four_stable_mono_channels(self):
  16. input_command = loopback_command(
  17. "/usr/bin/pw-loopback",
  18. "rigforge.mod-host-input",
  19. "rigforge.mod-host-input",
  20. "rigforge.mod-host-input.capture",
  21. ["AUX0", "AUX1", "AUX2", "AUX3"],
  22. 2.666666,
  23. )
  24. output_command = loopback_command(
  25. "/usr/bin/pw-loopback",
  26. "rigforge.mod-host-output",
  27. "rigforge.mod-host-output.playback",
  28. "rigforge.mod-host-output",
  29. ["AUX0", "AUX1", "AUX2", "AUX3"],
  30. 2.666666,
  31. )
  32. self.assertIn("media.class=Audio/Sink", input_command[10])
  33. self.assertIn("rigforge.mod-host-input.capture", input_command[12])
  34. self.assertIn("rigforge.mod-host-output.playback", output_command[10])
  35. self.assertIn("rigforge.mod-host-output", output_command[12])
  36. for command in (input_command, output_command):
  37. self.assertIn("--channels", command)
  38. self.assertIn("--channel-map", command)
  39. self.assertIn("--latency", command)
  40. self.assertEqual(command[4], "4")
  41. self.assertEqual(command[8], "2.66667")
  42. self.assertIn("[AUX0,AUX1,AUX2,AUX3]", command)
  43. self.assertIn("media.class=Audio/Sink", command[10])
  44. self.assertIn("media.class=Audio/Source", command[12])
  45. self.assertEqual(
  46. self.state["deployment"]["mod_host_ports"]["channel_map"],
  47. ["AUX0", "AUX1", "AUX2", "AUX3"],
  48. )
  49. def test_runner_refuses_duplicate_boundary_names(self):
  50. def runner(command, **_kwargs):
  51. if command == ["pw-link", "-o"]:
  52. return SimpleNamespace(stdout="rigforge.mod-host-output:capture_AUX0\n")
  53. if command == ["pw-link", "-i"]:
  54. return SimpleNamespace(stdout="")
  55. self.fail(f"unexpected command: {command}")
  56. with self.assertRaisesRegex(RuntimeError, "already present"):
  57. assert_boundary_ports_absent(self.state, runner)
  58. if __name__ == "__main__":
  59. unittest.main()