mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Clean up fido tests (#38098)
This commit is contained in:
parent
f742875e0d
commit
5583f43030
@ -1,6 +1,7 @@
|
|||||||
"""The test for the fido sensor platform."""
|
"""The test for the fido sensor platform."""
|
||||||
import logging
|
import logging
|
||||||
import sys
|
|
||||||
|
from pyfido.client import PyFidoError
|
||||||
|
|
||||||
from homeassistant.bootstrap import async_setup_component
|
from homeassistant.bootstrap import async_setup_component
|
||||||
from homeassistant.components.fido import sensor as fido
|
from homeassistant.components.fido import sensor as fido
|
||||||
@ -36,35 +37,12 @@ class FidoClientMockError(FidoClientMock):
|
|||||||
|
|
||||||
async def fetch_data(self):
|
async def fetch_data(self):
|
||||||
"""Return fake fetching data."""
|
"""Return fake fetching data."""
|
||||||
raise PyFidoErrorMock("Fake Error")
|
raise PyFidoError("Fake Error")
|
||||||
|
|
||||||
|
|
||||||
class PyFidoErrorMock(Exception):
|
|
||||||
"""Fake PyFido Error."""
|
|
||||||
|
|
||||||
|
|
||||||
class PyFidoClientFakeModule:
|
|
||||||
"""Fake pyfido.client module."""
|
|
||||||
|
|
||||||
PyFidoError = PyFidoErrorMock
|
|
||||||
|
|
||||||
|
|
||||||
class PyFidoFakeModule:
|
|
||||||
"""Fake pyfido module."""
|
|
||||||
|
|
||||||
FidoClient = FidoClientMockError
|
|
||||||
|
|
||||||
|
|
||||||
def fake_async_add_entities(component, update_before_add=False):
|
|
||||||
"""Fake async_add_entities function."""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
async def test_fido_sensor(loop, hass):
|
async def test_fido_sensor(loop, hass):
|
||||||
"""Test the Fido number sensor."""
|
"""Test the Fido number sensor."""
|
||||||
with patch(
|
with patch("homeassistant.components.fido.sensor.FidoClient", new=FidoClientMock):
|
||||||
"homeassistant.components.fido.sensor.FidoClient", new=FidoClientMock
|
|
||||||
), patch("homeassistant.components.fido.sensor.PyFidoError", new=PyFidoErrorMock):
|
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
"platform": "fido",
|
"platform": "fido",
|
||||||
@ -87,10 +65,9 @@ async def test_fido_sensor(loop, hass):
|
|||||||
async def test_error(hass, caplog):
|
async def test_error(hass, caplog):
|
||||||
"""Test the Fido sensor errors."""
|
"""Test the Fido sensor errors."""
|
||||||
caplog.set_level(logging.ERROR)
|
caplog.set_level(logging.ERROR)
|
||||||
sys.modules["pyfido"] = PyFidoFakeModule()
|
|
||||||
sys.modules["pyfido.client"] = PyFidoClientFakeModule()
|
|
||||||
|
|
||||||
config = {}
|
config = {}
|
||||||
fake_async_add_entities = MagicMock()
|
fake_async_add_entities = MagicMock()
|
||||||
await fido.async_setup_platform(hass, config, fake_async_add_entities)
|
with patch("homeassistant.components.fido.sensor.FidoClient", FidoClientMockError):
|
||||||
|
await fido.async_setup_platform(hass, config, fake_async_add_entities)
|
||||||
assert fake_async_add_entities.called is False
|
assert fake_async_add_entities.called is False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user