Extend video & add tests (#1518)

This commit is contained in:
Pascal Vizeli 2020-02-20 00:29:48 +01:00 committed by GitHub
parent a21353909d
commit 8dbfea75b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -28,7 +28,7 @@ GPIO_DEVICES: Path = Path("/sys/class/gpio")
SOC_DEVICES: Path = Path("/sys/devices/platform/soc")
RE_TTY: re.Pattern = re.compile(r"tty[A-Z]+")
RE_VIDEO_DEVICES = re.compile(r"^(?:vchiq|cec)")
RE_VIDEO_DEVICES = re.compile(r"^(?:vchiq|cec\d+|video\d+)")
@attr.s(frozen=True)

View File

@ -1,6 +1,8 @@
"""Test hardware utils."""
from unittest.mock import patch, PropertyMock
from pathlib import Path
from hassio.misc.hardware import Hardware
from hassio.misc.hardware import Hardware, Device
def test_read_all_devices():
@ -8,3 +10,25 @@ def test_read_all_devices():
system = Hardware()
assert system.devices
def test_video_devices():
"""Test video device filter."""
system = Hardware()
device_list = [
Device("test-dev", Path("/dev/test-dev"), []),
Device("vchiq", Path("/dev/vchiq"), []),
Device("cec0", Path("/dev/cec0"), []),
Device("video1", Path("/dev/video1"), []),
]
with patch(
"hassio.misc.hardware.Hardware.devices", new_callable=PropertyMock
) as mock_device:
mock_device.return_value = device_list
assert system.video_devices == [
Device("vchiq", Path("/dev/vchiq"), []),
Device("cec0", Path("/dev/cec0"), []),
Device("video1", Path("/dev/video1"), []),
]