mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Migrate octoprint tests to use freezegun (#105408)
This commit is contained in:
parent
3e3f9cf092
commit
b4731674f8
@ -1,6 +1,7 @@
|
|||||||
"""The tests for Octoptint binary sensor module."""
|
"""The tests for Octoptint binary sensor module."""
|
||||||
from datetime import UTC, datetime
|
from datetime import UTC, datetime
|
||||||
from unittest.mock import patch
|
|
||||||
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
@ -8,7 +9,7 @@ from homeassistant.helpers import entity_registry as er
|
|||||||
from . import init_integration
|
from . import init_integration
|
||||||
|
|
||||||
|
|
||||||
async def test_sensors(hass: HomeAssistant) -> None:
|
async def test_sensors(hass: HomeAssistant, freezer: FrozenDateTimeFactory) -> None:
|
||||||
"""Test the underlying sensors."""
|
"""Test the underlying sensors."""
|
||||||
printer = {
|
printer = {
|
||||||
"state": {
|
"state": {
|
||||||
@ -22,10 +23,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
|
|||||||
"progress": {"completion": 50, "printTime": 600, "printTimeLeft": 6000},
|
"progress": {"completion": 50, "printTime": 600, "printTimeLeft": 6000},
|
||||||
"state": "Printing",
|
"state": "Printing",
|
||||||
}
|
}
|
||||||
with patch(
|
freezer.move_to(datetime(2020, 2, 20, 9, 10, 13, 543, tzinfo=UTC))
|
||||||
"homeassistant.util.dt.utcnow",
|
|
||||||
return_value=datetime(2020, 2, 20, 9, 10, 13, 543, tzinfo=UTC),
|
|
||||||
):
|
|
||||||
await init_integration(hass, "sensor", printer=printer, job=job)
|
await init_integration(hass, "sensor", printer=printer, job=job)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
entity_registry = er.async_get(hass)
|
||||||
@ -80,7 +78,9 @@ async def test_sensors(hass: HomeAssistant) -> None:
|
|||||||
assert entry.unique_id == "Estimated Finish Time-uuid"
|
assert entry.unique_id == "Estimated Finish Time-uuid"
|
||||||
|
|
||||||
|
|
||||||
async def test_sensors_no_target_temp(hass: HomeAssistant) -> None:
|
async def test_sensors_no_target_temp(
|
||||||
|
hass: HomeAssistant, freezer: FrozenDateTimeFactory
|
||||||
|
) -> None:
|
||||||
"""Test the underlying sensors."""
|
"""Test the underlying sensors."""
|
||||||
printer = {
|
printer = {
|
||||||
"state": {
|
"state": {
|
||||||
@ -89,9 +89,7 @@ async def test_sensors_no_target_temp(hass: HomeAssistant) -> None:
|
|||||||
},
|
},
|
||||||
"temperature": {"tool1": {"actual": 18.83136, "target": None}},
|
"temperature": {"tool1": {"actual": 18.83136, "target": None}},
|
||||||
}
|
}
|
||||||
with patch(
|
freezer.move_to(datetime(2020, 2, 20, 9, 10, 0))
|
||||||
"homeassistant.util.dt.utcnow", return_value=datetime(2020, 2, 20, 9, 10, 0)
|
|
||||||
):
|
|
||||||
await init_integration(hass, "sensor", printer=printer)
|
await init_integration(hass, "sensor", printer=printer)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
entity_registry = er.async_get(hass)
|
||||||
@ -111,7 +109,9 @@ async def test_sensors_no_target_temp(hass: HomeAssistant) -> None:
|
|||||||
assert entry.unique_id == "target tool1 temp-uuid"
|
assert entry.unique_id == "target tool1 temp-uuid"
|
||||||
|
|
||||||
|
|
||||||
async def test_sensors_paused(hass: HomeAssistant) -> None:
|
async def test_sensors_paused(
|
||||||
|
hass: HomeAssistant, freezer: FrozenDateTimeFactory
|
||||||
|
) -> None:
|
||||||
"""Test the underlying sensors."""
|
"""Test the underlying sensors."""
|
||||||
printer = {
|
printer = {
|
||||||
"state": {
|
"state": {
|
||||||
@ -125,9 +125,7 @@ async def test_sensors_paused(hass: HomeAssistant) -> None:
|
|||||||
"progress": {"completion": 50, "printTime": 600, "printTimeLeft": 6000},
|
"progress": {"completion": 50, "printTime": 600, "printTimeLeft": 6000},
|
||||||
"state": "Paused",
|
"state": "Paused",
|
||||||
}
|
}
|
||||||
with patch(
|
freezer.move_to(datetime(2020, 2, 20, 9, 10, 0))
|
||||||
"homeassistant.util.dt.utcnow", return_value=datetime(2020, 2, 20, 9, 10, 0)
|
|
||||||
):
|
|
||||||
await init_integration(hass, "sensor", printer=printer, job=job)
|
await init_integration(hass, "sensor", printer=printer, job=job)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
entity_registry = er.async_get(hass)
|
||||||
@ -147,16 +145,16 @@ async def test_sensors_paused(hass: HomeAssistant) -> None:
|
|||||||
assert entry.unique_id == "Estimated Finish Time-uuid"
|
assert entry.unique_id == "Estimated Finish Time-uuid"
|
||||||
|
|
||||||
|
|
||||||
async def test_sensors_printer_disconnected(hass: HomeAssistant) -> None:
|
async def test_sensors_printer_disconnected(
|
||||||
|
hass: HomeAssistant, freezer: FrozenDateTimeFactory
|
||||||
|
) -> None:
|
||||||
"""Test the underlying sensors."""
|
"""Test the underlying sensors."""
|
||||||
job = {
|
job = {
|
||||||
"job": {},
|
"job": {},
|
||||||
"progress": {"completion": 50, "printTime": 600, "printTimeLeft": 6000},
|
"progress": {"completion": 50, "printTime": 600, "printTimeLeft": 6000},
|
||||||
"state": "Paused",
|
"state": "Paused",
|
||||||
}
|
}
|
||||||
with patch(
|
freezer.move_to(datetime(2020, 2, 20, 9, 10, 0))
|
||||||
"homeassistant.util.dt.utcnow", return_value=datetime(2020, 2, 20, 9, 10, 0)
|
|
||||||
):
|
|
||||||
await init_integration(hass, "sensor", printer=None, job=job)
|
await init_integration(hass, "sensor", printer=None, job=job)
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
entity_registry = er.async_get(hass)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user