Rewrite simulated unittest tests to pytest style test functions (#41115)

This commit is contained in:
Eliot Wong 2020-10-04 07:48:47 -04:00 committed by GitHub
parent c3ef05a37e
commit f7696fdb9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,30 +17,17 @@ 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."""
def setup_method(self, method):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def teardown_method(self, method):
"""Stop everything that was started."""
self.hass.stop()
def test_default_config(self):
"""Test default config.""" """Test default config."""
config = {"sensor": {"platform": "simulated"}} config = {"sensor": {"platform": "simulated"}}
assert setup_component(self.hass, "sensor", config) assert await async_setup_component(hass, "sensor", config)
self.hass.block_till_done() await hass.async_block_till_done()
assert len(self.hass.states.entity_ids()) == 1 assert len(hass.states.async_entity_ids()) == 1
state = self.hass.states.get("sensor.simulated") state = hass.states.get("sensor.simulated")
assert state.attributes.get(CONF_FRIENDLY_NAME) == DEFAULT_NAME assert state.attributes.get(CONF_FRIENDLY_NAME) == DEFAULT_NAME
assert state.attributes.get(CONF_AMP) == DEFAULT_AMP assert state.attributes.get(CONF_AMP) == DEFAULT_AMP