Rewrite simulated unittest tests to pytest style test functions (#41115)
This commit is contained in:
parent
c3ef05a37e
commit
f7696fdb9f
1 changed files with 17 additions and 32 deletions
|
@ -1,6 +1,4 @@
|
||||||
"""The tests for the simulated sensor."""
|
"""The tests for the simulated sensor."""
|
||||||
import unittest
|
|
||||||
|
|
||||||
from homeassistant.components.simulated.sensor import (
|
from homeassistant.components.simulated.sensor import (
|
||||||
CONF_AMP,
|
CONF_AMP,
|
||||||
CONF_FWHM,
|
CONF_FWHM,
|
||||||
|
@ -19,37 +17,24 @@ from homeassistant.components.simulated.sensor import (
|
||||||
DEFAULT_SEED,
|
DEFAULT_SEED,
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_FRIENDLY_NAME
|
from homeassistant.const import CONF_FRIENDLY_NAME
|
||||||
from homeassistant.setup import setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import get_test_home_assistant
|
|
||||||
|
|
||||||
|
|
||||||
class TestSimulatedSensor(unittest.TestCase):
|
async def test_simulated_sensor_default_config(hass):
|
||||||
"""Test the simulated sensor."""
|
"""Test default config."""
|
||||||
|
config = {"sensor": {"platform": "simulated"}}
|
||||||
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
def setup_method(self, method):
|
assert len(hass.states.async_entity_ids()) == 1
|
||||||
"""Set up things to be run when tests are started."""
|
state = hass.states.get("sensor.simulated")
|
||||||
self.hass = get_test_home_assistant()
|
|
||||||
|
|
||||||
def teardown_method(self, method):
|
assert state.attributes.get(CONF_FRIENDLY_NAME) == DEFAULT_NAME
|
||||||
"""Stop everything that was started."""
|
assert state.attributes.get(CONF_AMP) == DEFAULT_AMP
|
||||||
self.hass.stop()
|
assert state.attributes.get(CONF_UNIT) is None
|
||||||
|
assert state.attributes.get(CONF_MEAN) == DEFAULT_MEAN
|
||||||
def test_default_config(self):
|
assert state.attributes.get(CONF_PERIOD) == 60.0
|
||||||
"""Test default config."""
|
assert state.attributes.get(CONF_PHASE) == DEFAULT_PHASE
|
||||||
config = {"sensor": {"platform": "simulated"}}
|
assert state.attributes.get(CONF_FWHM) == DEFAULT_FWHM
|
||||||
assert setup_component(self.hass, "sensor", config)
|
assert state.attributes.get(CONF_SEED) == DEFAULT_SEED
|
||||||
self.hass.block_till_done()
|
assert state.attributes.get(CONF_RELATIVE_TO_EPOCH) == DEFAULT_RELATIVE_TO_EPOCH
|
||||||
|
|
||||||
assert len(self.hass.states.entity_ids()) == 1
|
|
||||||
state = self.hass.states.get("sensor.simulated")
|
|
||||||
|
|
||||||
assert state.attributes.get(CONF_FRIENDLY_NAME) == DEFAULT_NAME
|
|
||||||
assert state.attributes.get(CONF_AMP) == DEFAULT_AMP
|
|
||||||
assert state.attributes.get(CONF_UNIT) is None
|
|
||||||
assert state.attributes.get(CONF_MEAN) == DEFAULT_MEAN
|
|
||||||
assert state.attributes.get(CONF_PERIOD) == 60.0
|
|
||||||
assert state.attributes.get(CONF_PHASE) == DEFAULT_PHASE
|
|
||||||
assert state.attributes.get(CONF_FWHM) == DEFAULT_FWHM
|
|
||||||
assert state.attributes.get(CONF_SEED) == DEFAULT_SEED
|
|
||||||
assert state.attributes.get(CONF_RELATIVE_TO_EPOCH) == DEFAULT_RELATIVE_TO_EPOCH
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue