Skip to content

Commit

Permalink
fix: raise an error if the device can't be opened
Browse files Browse the repository at this point in the history
  • Loading branch information
tomli380576 committed Oct 29, 2024
1 parent 8b63aa8 commit 39858e7
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions checkbox-support/checkbox_support/parsers/v4l2_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ def get_test_name_from_line(line: str) -> T.Tuple[str, bool]:


def parse_v4l2_compliance(
device: T.Union[int, str] = "/dev/video0"
device: T.Optional[str] = None,
) -> T.Tuple[Summary, Details]:
"""Parses the output of v4l2-compliance
:param device: which device to test, defaults to "/dev/video0",
it can also be an integer. See v4l2-compliance -h
:type device: T.Union[int, str], optional
:return: 2 dictionaries (summary, details).
NOTE: summary comes from directly parsing the numbers in the last line of
NOTE: summary comes from directly parsing the numbers in the last line of
v4l2-compliance and it does **NOT** match the array sizes in Details
since we map the test names to actual ioctls.
Expand All @@ -127,10 +127,21 @@ def parse_v4l2_compliance(
assert which("v4l2-compliance")

out = sp.run(
["v4l2-compliance", "-d", str(device), "-C", "never"], # type: ignore
[
"v4l2-compliance",
*(["-d", str(device)] if device else []),
"-C",
"never",
],
universal_newlines=True,
stdout=sp.PIPE,
)
stderr=sp.PIPE,
) # can't really depend on the return code here
# since any failure => return code 1

if "Cannot open device" in out.stderr:
# can't open the device
raise ValueError(out.stderr)

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

0 comments on commit 39858e7

Please sign in to comment.