From 8dbfea75b1d80f50a72c1eb8c487457e3ed567d2 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 20 Feb 2020 00:29:48 +0100 Subject: [PATCH] Extend video & add tests (#1518) --- hassio/misc/hardware.py | 2 +- tests/misc/test_hardware.py | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/hassio/misc/hardware.py b/hassio/misc/hardware.py index 74701b330..7aa49f42b 100644 --- a/hassio/misc/hardware.py +++ b/hassio/misc/hardware.py @@ -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) diff --git a/tests/misc/test_hardware.py b/tests/misc/test_hardware.py index d969e7152..eee1c3677 100644 --- a/tests/misc/test_hardware.py +++ b/tests/misc/test_hardware.py @@ -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"), []), + ]