supervisor/tests/hardware/test_module.py
dependabot[bot] dafc2cfec2
Bump pyupgrade from 2.26.0 to 2.26.0.post1 (#3131)
* Bump pyupgrade from 2.26.0 to 2.26.0.post1

Bumps [pyupgrade](https://github.com/asottile/pyupgrade) from 2.26.0 to 2.26.0.post1.
- [Release notes](https://github.com/asottile/pyupgrade/releases)
- [Commits](https://github.com/asottile/pyupgrade/commits)

---
updated-dependencies:
- dependency-name: pyupgrade
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update .pre-commit-config.yaml

* Fixes

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Pascal Vizeli <pvizeli@syshack.ch>
2021-09-21 18:22:56 +02:00

133 lines
3.4 KiB
Python

"""Test HardwareManager Module."""
from pathlib import Path
from supervisor.hardware.const import UdevSubsystem
from supervisor.hardware.data import Device
# pylint: disable=protected-access
def test_initial_device_initialize(coresys):
"""Initialize the local hardware."""
assert not coresys.hardware.devices
coresys.hardware._import_devices()
assert coresys.hardware.devices
def test_device_path_lookup(coresys):
"""Test device lookup."""
for device in (
Device(
"ttyACM0",
Path("/dev/ttyACM0"),
Path("/sys/bus/usb/001"),
"tty",
None,
[],
{"ID_VENDOR": "xy"},
[],
),
Device(
"ttyUSB0",
Path("/dev/ttyUSB0"),
Path("/sys/bus/usb/000"),
"tty",
None,
[Path("/dev/ttyS1"), Path("/dev/serial/by-id/xyx")],
{"ID_VENDOR": "xy"},
[],
),
Device(
"ttyS0",
Path("/dev/ttyS0"),
Path("/sys/bus/usb/002"),
"tty",
None,
[],
{},
[],
),
Device(
"video1",
Path("/dev/video1"),
Path("/sys/bus/usb/003"),
"misc",
None,
[],
{"ID_VENDOR": "xy"},
[],
),
):
coresys.hardware.update_device(device)
assert coresys.hardware.exists_device_node(Path("/dev/ttyACM0"))
assert coresys.hardware.exists_device_node(Path("/dev/ttyS1"))
assert coresys.hardware.exists_device_node(Path("/dev/ttyS0"))
assert coresys.hardware.exists_device_node(Path("/dev/serial/by-id/xyx"))
assert coresys.hardware.exists_device_node(Path("/sys/bus/usb/001"))
assert not coresys.hardware.exists_device_node(Path("/dev/ttyS2"))
assert not coresys.hardware.exists_device_node(Path("/dev/ttyUSB1"))
def test_device_filter(coresys):
"""Test device filter."""
for device in (
Device(
"ttyACM0",
Path("/dev/ttyACM0"),
Path("/sys/bus/usb/000"),
"tty",
None,
[],
{"ID_VENDOR": "xy"},
[],
),
Device(
"ttyUSB0",
Path("/dev/ttyUSB0"),
Path("/sys/bus/usb/001"),
"tty",
None,
[Path("/dev/ttyS1"), Path("/dev/serial/by-id/xyx")],
{"ID_VENDOR": "xy"},
[],
),
Device(
"ttyS0",
Path("/dev/ttyS0"),
Path("/sys/bus/usb/002"),
"tty",
None,
[],
{},
[],
),
Device(
"video1",
Path("/dev/video1"),
Path("/sys/bus/usb/003"),
"misc",
None,
[],
{"ID_VENDOR": "xy"},
[],
),
):
coresys.hardware.update_device(device)
assert sorted(
device.path for device in coresys.hardware.filter_devices()
) == sorted(device.path for device in coresys.hardware.devices)
assert sorted(
device.path
for device in coresys.hardware.filter_devices(subsystem=UdevSubsystem.SERIAL)
) == sorted(
device.path
for device in coresys.hardware.devices
if device.subsystem == UdevSubsystem.SERIAL
)