test_mod_host_ports.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_use_stable_mono_aux0_ports(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",
  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",
  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[8], "2.66667")
  41. self.assertIn("[AUX0]", command)
  42. self.assertIn("media.class=Audio/Sink", command[10])
  43. self.assertIn("media.class=Audio/Source", command[12])
  44. def test_runner_refuses_duplicate_boundary_names(self):
  45. def runner(command, **_kwargs):
  46. if command == ["pw-link", "-o"]:
  47. return SimpleNamespace(stdout="rigforge.mod-host-output:capture_AUX0\n")
  48. if command == ["pw-link", "-i"]:
  49. return SimpleNamespace(stdout="")
  50. self.fail(f"unexpected command: {command}")
  51. with self.assertRaisesRegex(RuntimeError, "already present"):
  52. assert_boundary_ports_absent(self.state, runner)
  53. if __name__ == "__main__":
  54. unittest.main()