Clean up fido tests (#38098)

This commit is contained in:
Paulus Schoutsen 2020-07-22 23:21:32 -07:00 committed by GitHub
parent f742875e0d
commit 5583f43030
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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