From 5583f43030530a540230115d0517f496bb12498c Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 22 Jul 2020 23:21:32 -0700 Subject: [PATCH] Clean up fido tests (#38098) --- tests/components/fido/test_sensor.py | 35 +++++----------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/tests/components/fido/test_sensor.py b/tests/components/fido/test_sensor.py index c96e6d0ab58..551a59f0788 100644 --- a/tests/components/fido/test_sensor.py +++ b/tests/components/fido/test_sensor.py @@ -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