Clean up fido tests (#38098)
This commit is contained in:
parent
f742875e0d
commit
5583f43030
1 changed files with 6 additions and 29 deletions
|
@ -1,6 +1,7 @@
|
|||
"""The test for the fido sensor platform."""
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from pyfido.client import PyFidoError
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components.fido import sensor as fido
|
||||
|
@ -36,35 +37,12 @@ class FidoClientMockError(FidoClientMock):
|
|||
|
||||
async def fetch_data(self):
|
||||
"""Return fake fetching data."""
|
||||
raise PyFidoErrorMock("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
|
||||
raise PyFidoError("Fake Error")
|
||||
|
||||
|
||||
async def test_fido_sensor(loop, hass):
|
||||
"""Test the Fido number sensor."""
|
||||
with patch(
|
||||
"homeassistant.components.fido.sensor.FidoClient", new=FidoClientMock
|
||||
), patch("homeassistant.components.fido.sensor.PyFidoError", new=PyFidoErrorMock):
|
||||
with patch("homeassistant.components.fido.sensor.FidoClient", new=FidoClientMock):
|
||||
config = {
|
||||
"sensor": {
|
||||
"platform": "fido",
|
||||
|
@ -87,10 +65,9 @@ async def test_fido_sensor(loop, hass):
|
|||
async def test_error(hass, caplog):
|
||||
"""Test the Fido sensor errors."""
|
||||
caplog.set_level(logging.ERROR)
|
||||
sys.modules["pyfido"] = PyFidoFakeModule()
|
||||
sys.modules["pyfido.client"] = PyFidoClientFakeModule()
|
||||
|
||||
config = {}
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue