mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Improve type hints in prusalink tests (#123873)
This commit is contained in:
parent
f414f5d77a
commit
1af6528f4f
@ -1,16 +1,19 @@
|
|||||||
"""Fixtures for PrusaLink."""
|
"""Fixtures for PrusaLink."""
|
||||||
|
|
||||||
|
from collections.abc import Generator
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.prusalink import DOMAIN
|
from homeassistant.components.prusalink import DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_config_entry(hass):
|
def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
|
||||||
"""Mock a PrusaLink config entry."""
|
"""Mock a PrusaLink config entry."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
@ -23,7 +26,7 @@ def mock_config_entry(hass):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_version_api(hass):
|
def mock_version_api() -> Generator[dict[str, str]]:
|
||||||
"""Mock PrusaLink version API."""
|
"""Mock PrusaLink version API."""
|
||||||
resp = {
|
resp = {
|
||||||
"api": "2.0.0",
|
"api": "2.0.0",
|
||||||
@ -36,7 +39,7 @@ def mock_version_api(hass):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_info_api(hass):
|
def mock_info_api() -> Generator[dict[str, Any]]:
|
||||||
"""Mock PrusaLink info API."""
|
"""Mock PrusaLink info API."""
|
||||||
resp = {
|
resp = {
|
||||||
"nozzle_diameter": 0.40,
|
"nozzle_diameter": 0.40,
|
||||||
@ -50,7 +53,7 @@ def mock_info_api(hass):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_get_legacy_printer(hass):
|
def mock_get_legacy_printer() -> Generator[dict[str, Any]]:
|
||||||
"""Mock PrusaLink printer API."""
|
"""Mock PrusaLink printer API."""
|
||||||
resp = {"telemetry": {"material": "PLA"}}
|
resp = {"telemetry": {"material": "PLA"}}
|
||||||
with patch("pyprusalink.PrusaLink.get_legacy_printer", return_value=resp):
|
with patch("pyprusalink.PrusaLink.get_legacy_printer", return_value=resp):
|
||||||
@ -58,7 +61,7 @@ def mock_get_legacy_printer(hass):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_get_status_idle(hass):
|
def mock_get_status_idle() -> Generator[dict[str, Any]]:
|
||||||
"""Mock PrusaLink printer API."""
|
"""Mock PrusaLink printer API."""
|
||||||
resp = {
|
resp = {
|
||||||
"storage": {
|
"storage": {
|
||||||
@ -86,7 +89,7 @@ def mock_get_status_idle(hass):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_get_status_printing(hass):
|
def mock_get_status_printing() -> Generator[dict[str, Any]]:
|
||||||
"""Mock PrusaLink printer API."""
|
"""Mock PrusaLink printer API."""
|
||||||
resp = {
|
resp = {
|
||||||
"job": {
|
"job": {
|
||||||
@ -114,7 +117,7 @@ def mock_get_status_printing(hass):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_job_api_idle(hass):
|
def mock_job_api_idle() -> Generator[dict[str, Any]]:
|
||||||
"""Mock PrusaLink job API having no job."""
|
"""Mock PrusaLink job API having no job."""
|
||||||
resp = {}
|
resp = {}
|
||||||
with patch("pyprusalink.PrusaLink.get_job", return_value=resp):
|
with patch("pyprusalink.PrusaLink.get_job", return_value=resp):
|
||||||
@ -122,7 +125,7 @@ def mock_job_api_idle(hass):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_job_api_idle_mk3(hass):
|
def mock_job_api_idle_mk3() -> Generator[dict[str, Any]]:
|
||||||
"""Mock PrusaLink job API having a job with idle state (MK3)."""
|
"""Mock PrusaLink job API having a job with idle state (MK3)."""
|
||||||
resp = {
|
resp = {
|
||||||
"id": 129,
|
"id": 129,
|
||||||
@ -148,7 +151,7 @@ def mock_job_api_idle_mk3(hass):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_job_api_printing(hass):
|
def mock_job_api_printing() -> Generator[dict[str, Any]]:
|
||||||
"""Mock PrusaLink printing."""
|
"""Mock PrusaLink printing."""
|
||||||
resp = {
|
resp = {
|
||||||
"id": 129,
|
"id": 129,
|
||||||
@ -174,7 +177,9 @@ def mock_job_api_printing(hass):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_job_api_paused(hass, mock_get_status_printing, mock_job_api_printing):
|
def mock_job_api_paused(
|
||||||
|
mock_get_status_printing: dict[str, Any], mock_job_api_printing: dict[str, Any]
|
||||||
|
) -> None:
|
||||||
"""Mock PrusaLink paused printing."""
|
"""Mock PrusaLink paused printing."""
|
||||||
mock_job_api_printing["state"] = "PAUSED"
|
mock_job_api_printing["state"] = "PAUSED"
|
||||||
mock_get_status_printing["printer"]["state"] = "PAUSED"
|
mock_get_status_printing["printer"]["state"] = "PAUSED"
|
||||||
@ -182,10 +187,10 @@ def mock_job_api_paused(hass, mock_get_status_printing, mock_job_api_printing):
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_api(
|
def mock_api(
|
||||||
mock_version_api,
|
mock_version_api: dict[str, str],
|
||||||
mock_info_api,
|
mock_info_api: dict[str, Any],
|
||||||
mock_get_legacy_printer,
|
mock_get_legacy_printer: dict[str, Any],
|
||||||
mock_get_status_idle,
|
mock_get_status_idle: dict[str, Any],
|
||||||
mock_job_api_idle,
|
mock_job_api_idle: dict[str, Any],
|
||||||
):
|
) -> None:
|
||||||
"""Mock PrusaLink API."""
|
"""Mock PrusaLink API."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user