1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2025-12-24 20:35:55 +00:00

Fix mypy issues in docker, hardware and homeassistant modules (#5805)

* Fix mypy issues in docker and hardware modules

* Fix mypy issues in homeassistant module

* Fix async_send_command typing

* Fixes from feedback
This commit is contained in:
Mike Degatano
2025-04-08 12:52:58 -04:00
committed by GitHub
parent 59a7e9519d
commit 4a00caa2e8
22 changed files with 247 additions and 153 deletions

21
tests/docker/conftest.py Normal file
View File

@@ -0,0 +1,21 @@
"""Fixtures for docker tests."""
import pytest
from supervisor.coresys import CoreSys
from supervisor.docker.interface import DockerInterface
class TestDockerInterface(DockerInterface):
"""Test docker interface."""
@property
def name(self) -> str:
"""Name of test interface."""
return "test_interface"
@pytest.fixture
def test_docker_interface(coresys: CoreSys) -> TestDockerInterface:
"""Return test docker interface."""
return TestDockerInterface(coresys)

View File

@@ -5,37 +5,44 @@ from supervisor.coresys import CoreSys
from supervisor.docker.interface import DOCKER_HUB, DockerInterface
def test_no_credentials(coresys: CoreSys):
def test_no_credentials(coresys: CoreSys, test_docker_interface: DockerInterface):
"""Test no credentials."""
docker = DockerInterface(coresys)
coresys.docker.config._data["registries"] = {
DOCKER_HUB: {"username": "Spongebob Squarepants", "password": "Password1!"}
}
assert not docker._get_credentials("ghcr.io/homeassistant")
assert not docker._get_credentials("ghcr.io/homeassistant/amd64-supervisor")
assert not test_docker_interface._get_credentials("ghcr.io/homeassistant")
assert not test_docker_interface._get_credentials(
"ghcr.io/homeassistant/amd64-supervisor"
)
def test_no_matching_credentials(coresys: CoreSys):
def test_no_matching_credentials(
coresys: CoreSys, test_docker_interface: DockerInterface
):
"""Test no matching credentials."""
docker = DockerInterface(coresys)
coresys.docker.config._data["registries"] = {
DOCKER_HUB: {"username": "Spongebob Squarepants", "password": "Password1!"}
}
assert not docker._get_credentials("ghcr.io/homeassistant")
assert not docker._get_credentials("ghcr.io/homeassistant/amd64-supervisor")
assert not test_docker_interface._get_credentials("ghcr.io/homeassistant")
assert not test_docker_interface._get_credentials(
"ghcr.io/homeassistant/amd64-supervisor"
)
def test_matching_credentials(coresys: CoreSys):
def test_matching_credentials(coresys: CoreSys, test_docker_interface: DockerInterface):
"""Test no matching credentials."""
docker = DockerInterface(coresys)
coresys.docker.config._data["registries"] = {
"ghcr.io": {"username": "Octocat", "password": "Password1!"},
DOCKER_HUB: {"username": "Spongebob Squarepants", "password": "Password1!"},
}
credentials = docker._get_credentials("ghcr.io/homeassistant/amd64-supervisor")
credentials = test_docker_interface._get_credentials(
"ghcr.io/homeassistant/amd64-supervisor"
)
assert credentials["registry"] == "ghcr.io"
credentials = docker._get_credentials("homeassistant/amd64-supervisor")
credentials = test_docker_interface._get_credentials(
"homeassistant/amd64-supervisor"
)
assert credentials["username"] == "Spongebob Squarepants"
assert "registry" not in credentials

View File

@@ -44,18 +44,26 @@ def mock_verify_content(coresys: CoreSys):
(CpuArch.AMD64, "linux/amd64"),
],
)
async def test_docker_image_platform(coresys: CoreSys, cpu_arch: str, platform: str):
async def test_docker_image_platform(
coresys: CoreSys,
test_docker_interface: DockerInterface,
cpu_arch: str,
platform: str,
):
"""Test platform set correctly from arch."""
with patch.object(
coresys.docker.images, "pull", return_value=Mock(id="test:1.2.3")
) as pull:
instance = DockerInterface(coresys)
await instance.install(AwesomeVersion("1.2.3"), "test", arch=cpu_arch)
await test_docker_interface.install(
AwesomeVersion("1.2.3"), "test", arch=cpu_arch
)
assert pull.call_count == 1
assert pull.call_args == call("test:1.2.3", platform=platform)
async def test_docker_image_default_platform(coresys: CoreSys):
async def test_docker_image_default_platform(
coresys: CoreSys, test_docker_interface: DockerInterface
):
"""Test platform set using supervisor arch when omitted."""
with (
patch.object(
@@ -65,8 +73,7 @@ async def test_docker_image_default_platform(coresys: CoreSys):
coresys.docker.images, "pull", return_value=Mock(id="test:1.2.3")
) as pull,
):
instance = DockerInterface(coresys)
await instance.install(AwesomeVersion("1.2.3"), "test")
await test_docker_interface.install(AwesomeVersion("1.2.3"), "test")
assert pull.call_count == 1
assert pull.call_args == call("test:1.2.3", platform="linux/386")