Move imports to top for fido (#29557)
* Move imports to top for fido * Fix tests for fido by using patch
This commit is contained in:
1 parent
6de8072e8a
commit
d752fe3033
2 files changed
+26
-30
No files matched your search
@@ -2,7 +2,7 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import sys
|
||||
from unittest.mock import MagicMock
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components.fido import sensor as fido
|
||||
@@ -66,29 +66,25 @@ def fake_async_add_entities(component, update_before_add=False):
|
||||
@asyncio.coroutine
|
||||
def test_fido_sensor(loop, hass):
|
||||
"""Test the Fido number sensor."""
|
||||
sys.modules["pyfido"] = MagicMock()
|
||||
sys.modules["pyfido.client"] = MagicMock()
|
||||
sys.modules["pyfido.client.PyFidoError"] = PyFidoErrorMock
|
||||
import pyfido.client
|
||||
|
||||
pyfido.FidoClient = FidoClientMock
|
||||
pyfido.client.PyFidoError = PyFidoErrorMock
|
||||
config = {
|
||||
"sensor": {
|
||||
"platform": "fido",
|
||||
"name": "fido",
|
||||
"username": "myusername",
|
||||
"password": "password",
|
||||
"monitored_variables": ["balance", "data_remaining"],
|
||||
with patch(
|
||||
"homeassistant.components.fido.sensor.FidoClient", new=FidoClientMock
|
||||
), patch("homeassistant.components.fido.sensor.PyFidoError", new=PyFidoErrorMock):
|
||||
config = {
|
||||
"sensor": {
|
||||
"platform": "fido",
|
||||
"name": "fido",
|
||||
"username": "myusername",
|
||||
"password": "password",
|
||||
"monitored_variables": ["balance", "data_remaining"],
|
||||
}
|
||||
}
|
||||
}
|
||||
with assert_setup_component(1):
|
||||
yield from async_setup_component(hass, "sensor", config)
|
||||
state = hass.states.get("sensor.fido_1112223344_balance")
|
||||
assert state.state == "160.12"
|
||||
assert state.attributes.get("number") == "1112223344"
|
||||
state = hass.states.get("sensor.fido_1112223344_data_remaining")
|
||||
assert state.state == "100.33"
|
||||
with assert_setup_component(1):
|
||||
yield from async_setup_component(hass, "sensor", config)
|
||||
state = hass.states.get("sensor.fido_1112223344_balance")
|
||||
assert state.state == "160.12"
|
||||
assert state.attributes.get("number") == "1112223344"
|
||||
state = hass.states.get("sensor.fido_1112223344_data_remaining")
|
||||
assert state.state == "100.33"
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
|
||||
Reference in new issue
Block a user