mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-06-24 19:06:29 +00:00

* Fix handling with full access / blocked devices * address comment * Use name * Add validation warning * add GPIO check too * remove warning * return directly * fix tests
82 lines
2.2 KiB
Python
82 lines
2.2 KiB
Python
"""Test hardware utils."""
|
|
# pylint: disable=protected-access
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from supervisor.hardware.data import Device
|
|
|
|
|
|
def test_system_partition(coresys):
|
|
"""Test if it is a system partition."""
|
|
disk = Device(
|
|
"sda0",
|
|
Path("/dev/sda0"),
|
|
Path("/sys/bus/usb/001"),
|
|
"block",
|
|
[],
|
|
{"MAJOR": "5", "MINOR": "10"},
|
|
)
|
|
|
|
assert not coresys.hardware.disk.is_system_partition(disk)
|
|
|
|
disk = Device(
|
|
"sda0",
|
|
Path("/dev/sda0"),
|
|
Path("/sys/bus/usb/001"),
|
|
"block",
|
|
[],
|
|
{"MAJOR": "5", "MINOR": "10", "ID_FS_LABEL": "hassos-overlay"},
|
|
)
|
|
|
|
assert coresys.hardware.disk.is_system_partition(disk)
|
|
|
|
|
|
def test_free_space(coresys):
|
|
"""Test free space helper."""
|
|
with patch("shutil.disk_usage", return_value=(42, 42, 2 * (1024.0 ** 3))):
|
|
free = coresys.hardware.disk.get_disk_free_space("/data")
|
|
|
|
assert free == 2.0
|
|
|
|
|
|
def test_total_space(coresys):
|
|
"""Test total space helper."""
|
|
with patch("shutil.disk_usage", return_value=(10 * (1024.0 ** 3), 42, 42)):
|
|
total = coresys.hardware.disk.get_disk_total_space("/data")
|
|
|
|
assert total == 10.0
|
|
|
|
|
|
def test_used_space(coresys):
|
|
"""Test used space helper."""
|
|
with patch("shutil.disk_usage", return_value=(42, 8 * (1024.0 ** 3), 42)):
|
|
used = coresys.hardware.disk.get_disk_used_space("/data")
|
|
|
|
assert used == 8.0
|
|
|
|
|
|
def test_get_mountinfo(coresys):
|
|
"""Test mountinfo helper."""
|
|
mountinfo = coresys.hardware.disk._get_mountinfo("/proc")
|
|
assert mountinfo[4] == "/proc"
|
|
|
|
|
|
def test_get_mount_source(coresys):
|
|
"""Test mount source helper."""
|
|
# For /proc the mount source is known to be "proc"...
|
|
mount_source = coresys.hardware.disk._get_mount_source("/proc")
|
|
assert mount_source == "proc"
|
|
|
|
|
|
def test_try_get_emmc_life_time(coresys, tmp_path):
|
|
"""Test eMMC life time helper."""
|
|
fake_life_time = tmp_path / "fake-mmcblk0-lifetime"
|
|
fake_life_time.write_text("0x01 0x02\n")
|
|
|
|
with patch(
|
|
"supervisor.hardware.disk._BLOCK_DEVICE_EMMC_LIFE_TIME",
|
|
str(tmp_path / "fake-{}-lifetime"),
|
|
):
|
|
value = coresys.hardware.disk._try_get_emmc_life_time("mmcblk0")
|
|
assert value == 20.0
|