Rewrite random unittest tests to pytest style test functions (#40920)
This commit is contained in:
1 parent
c5041b41c8
commit
ad8ab183cb
2 files changed
+48
-60
No files matched your search
@@ -1,37 +1,26 @@
|
||||
"""The test for the random number sensor platform."""
|
||||
import unittest
|
||||
|
||||
from homeassistant.setup import setup_component
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
||||
class TestRandomSensor(unittest.TestCase):
|
||||
async def test_random_sensor(hass):
|
||||
"""Test the Random number 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_random_sensor(self):
|
||||
"""Test the Random number sensor."""
|
||||
config = {
|
||||
"sensor": {
|
||||
"platform": "random",
|
||||
"name": "test",
|
||||
"minimum": 10,
|
||||
"maximum": 20,
|
||||
}
|
||||
config = {
|
||||
"sensor": {
|
||||
"platform": "random",
|
||||
"name": "test",
|
||||
"minimum": 10,
|
||||
"maximum": 20,
|
||||
}
|
||||
}
|
||||
|
||||
assert setup_component(self.hass, "sensor", config)
|
||||
self.hass.block_till_done()
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"sensor",
|
||||
config,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = self.hass.states.get("sensor.test")
|
||||
state = hass.states.get("sensor.test")
|
||||
|
||||
assert int(state.state) <= config["sensor"]["maximum"]
|
||||
assert int(state.state) >= config["sensor"]["minimum"]
|
||||
assert int(state.state) <= config["sensor"]["maximum"]
|
||||
assert int(state.state) >= config["sensor"]["minimum"]
|
||||
Reference in new issue
Block a user