Skip to content

Commit

Permalink
fix: extra error message check
Browse files Browse the repository at this point in the history
  • Loading branch information
tomli380576 committed Nov 14, 2024
1 parent 72beae0 commit b65b2a6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TestV4L2ComplianceParser(ut.TestCase):

@patch("subprocess.run")
def test_happy_path(self, mock_run: MagicMock):
ok_input = read_file_as_str("clean_input_1")
ok_input = read_file_as_str("22_04_success")
mock_run.return_value = sp.CompletedProcess(
[], 1, stdout=ok_input, stderr=""
)
Expand Down Expand Up @@ -44,6 +44,21 @@ def test_unparsable(self, mock_run: MagicMock):

self.assertRaises(AssertionError, parse_v4l2_compliance)

@patch("subprocess.run")
def test_unopenable_device(self, mock_run: MagicMock):
err_messages = [
# 16.04 18.04: found this message in VMs without camera pass through
"Failed to open device /dev/video0: No such file or directory"
# 20.04: found this msg in VMs without camera pass through
# 22.04, 24.04: found this message if we disable camera in BIOS
"Cannot open device /dev/video0, exiting."
]
for err_msg in err_messages:
mock_run.return_value = sp.CompletedProcess(
[], 1, stdout="", stderr=err_msg
)
self.assertRaises(FileNotFoundError, parse_v4l2_compliance)


if __name__ == "__main__":
ut.main()
5 changes: 3 additions & 2 deletions checkbox-support/checkbox_support/parsers/v4l2_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ def parse_v4l2_compliance(
) # can't really depend on the return code here
# since any failure => return code 1

if "Cannot open device" in out.stderr:
error_prefixes = ("Failed to open", "Cannot open device")
if any(out.stderr.startswith(prefix) for prefix in error_prefixes):
# can't open the device
raise ValueError(out.stderr)
raise FileNotFoundError(out.stderr)

lines = [] # type: list[str]
for line in out.stdout.splitlines():
Expand Down

0 comments on commit b65b2a6

Please sign in to comment.