Skip to content

Commit c428002

Browse files
committed
better description of how to use set-node/sink in PW
1 parent 36e9034 commit c428002

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

checkbox-support/checkbox_support/helpers/tests/test_audio_server_utils.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,22 @@ def test_set_sink(self, mock_check_output):
249249
["wpctl", "set-default", "123"]
250250
)
251251

252+
@patch(
253+
"checkbox_support.helpers.audio_server_utils.subprocess.check_output"
254+
)
255+
def test_set_sink_error(self, mock_check_output):
256+
"""Test setting a sink raises RuntimeError on failure."""
257+
mock_check_output.side_effect = subprocess.CalledProcessError(
258+
1, "wpctl"
259+
)
260+
node = Node("dev1", "prof1", "sink1", "123", "Sink 1")
261+
262+
with self.assertRaises(RuntimeError) as cm:
263+
self.pipewire.set_sink(node)
264+
265+
self.assertIn("sink1", str(cm.exception))
266+
self.assertIn("123", str(cm.exception))
267+
252268
@patch(
253269
"checkbox_support.helpers.audio_server_utils.subprocess.check_output"
254270
)
@@ -262,6 +278,22 @@ def test_set_source(self, mock_check_output):
262278
["wpctl", "set-default", "456"]
263279
)
264280

281+
@patch(
282+
"checkbox_support.helpers.audio_server_utils.subprocess.check_output"
283+
)
284+
def test_set_source_error(self, mock_check_output):
285+
"""Test setting a source raises RuntimeError on failure."""
286+
mock_check_output.side_effect = subprocess.CalledProcessError(
287+
1, "wpctl"
288+
)
289+
node = Node("dev1", "prof1", "source1", "456", "Source 1")
290+
291+
with self.assertRaises(RuntimeError) as cm:
292+
self.pipewire.set_source(node)
293+
294+
self.assertIn("source1", str(cm.exception))
295+
self.assertIn("456", str(cm.exception))
296+
265297
@patch(
266298
"checkbox_support.helpers.audio_server_utils.subprocess.check_output"
267299
)
@@ -473,6 +505,19 @@ def test_set_source(self, mock_check_output):
473505
["pactl", "set-default-source", "test_source"]
474506
)
475507

508+
@patch(
509+
"checkbox_support.helpers.audio_server_utils.subprocess.check_output"
510+
)
511+
def test_set_source_error(self, mock_check_output):
512+
"""Test setting a source raises RuntimeError on error."""
513+
mock_check_output.side_effect = subprocess.CalledProcessError(
514+
1, "pactl"
515+
)
516+
node = Node("0", None, "test_source", "0", "Test Source")
517+
518+
with self.assertRaises(RuntimeError):
519+
self.pulseaudio.set_source(node)
520+
476521
@patch(
477522
"checkbox_support.helpers.audio_server_utils.subprocess.check_output"
478523
)

0 commit comments

Comments
 (0)