Skip to content

Commit 36e9034

Browse files
committed
next statement not handled
1 parent 6563ba6 commit 36e9034

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

checkbox-support/checkbox_support/helpers/audio_server_utils.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,24 @@ def match(node_id: str, node_name: str, obj) -> bool:
321321
# handle cases where the node name include an index
322322
# i.e. alsa_output.pci-0000_00_1f.3.analog-stereo.10
323323
stripped_name = node.name.rsplit(".", 1)[0]
324-
new_node = next(
325-
obj
326-
for obj in nodes.values()
327-
if obj.get("info", {})
328-
.get("props", {})
329-
.get("node.name", "")
330-
.rsplit(".", 1)[0]
331-
== stripped_name
332-
)
333-
node.id = str(new_node["info"]["props"]["node.id"])
334-
node.name = new_node["info"]["props"]["node.name"]
324+
try:
325+
new_node = next(
326+
obj
327+
for obj in nodes.values()
328+
if obj.get("info", {})
329+
.get("props", {})
330+
.get("node.name", "")
331+
.rsplit(".", 1)[0]
332+
== stripped_name
333+
)
334+
node.id = str(new_node["info"]["props"]["node.id"])
335+
node.name = new_node["info"]["props"]["node.name"]
336+
except StopIteration:
337+
raise RuntimeError(
338+
"Node '{}' (id: {}) not found after setting profile '{}' on device '{}'".format(
339+
node.name, node.id, node.profile_id, node.device_id
340+
)
341+
)
335342

336343
self._set_default_audio_node(node.id)
337344

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,20 @@ def test_set_node_of_type_ephemeral(self):
353353
self.pipewire._set_card_profile.assert_called_once_with("1", "2")
354354
self.pipewire._set_default_audio_node.assert_called_once_with("new_id")
355355

356+
def test_set_node_of_type_not_found(self):
357+
"""Test setting a node that cannot be found raises RuntimeError."""
358+
359+
node = Node("1", "2", "name", "id", "description")
360+
self.pipewire._set_card_profile = Mock()
361+
self.pipewire._get_audio_nodes = Mock(return_value={})
362+
363+
with self.assertRaises(RuntimeError) as cm:
364+
self.pipewire._set_node_of_type(node, NodeType.SINK)
365+
366+
self.assertIn("name", str(cm.exception))
367+
self.assertIn("id", str(cm.exception))
368+
self.assertIn("not found", str(cm.exception))
369+
356370

357371
class PulseaudioUtilsTests(unittest.TestCase):
358372
"""Test cases for the PulseaudioUtils class."""

0 commit comments

Comments
 (0)