Rewrite worldclock unittest tests to pytest style test functions (#40922)
This commit is contained in:
parent
d95f83b5fb
commit
95d228cace
1 changed files with 38 additions and 35 deletions
|
@ -1,49 +1,52 @@
|
|||
"""The test for the World clock sensor platform."""
|
||||
import unittest
|
||||
import pytest
|
||||
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
@pytest.fixture
|
||||
def time_zone():
|
||||
"""Fixture for time zone."""
|
||||
return dt_util.get_time_zone("America/New_York")
|
||||
|
||||
|
||||
class TestWorldClockSensor(unittest.TestCase):
|
||||
"""Test the World clock sensor."""
|
||||
async def test_time(hass, time_zone):
|
||||
"""Test the time at a different location."""
|
||||
config = {"sensor": {"platform": "worldclock", "time_zone": "America/New_York"}}
|
||||
|
||||
def setUp(self):
|
||||
"""Set up things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.time_zone = dt_util.get_time_zone("America/New_York")
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"sensor",
|
||||
config,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
def test_time(self):
|
||||
"""Test the time at a different location."""
|
||||
config = {"sensor": {"platform": "worldclock", "time_zone": "America/New_York"}}
|
||||
assert setup_component(self.hass, "sensor", config)
|
||||
self.hass.block_till_done()
|
||||
self.addCleanup(self.hass.stop)
|
||||
state = hass.states.get("sensor.worldclock_sensor")
|
||||
assert state is not None
|
||||
|
||||
state = self.hass.states.get("sensor.worldclock_sensor")
|
||||
assert state is not None
|
||||
assert state.state == dt_util.now(time_zone=time_zone).strftime("%H:%M")
|
||||
|
||||
assert state.state == dt_util.now(time_zone=self.time_zone).strftime("%H:%M")
|
||||
|
||||
def test_time_format(self):
|
||||
"""Test time_format setting."""
|
||||
time_format = "%a, %b %d, %Y %I:%M %p"
|
||||
config = {
|
||||
"sensor": {
|
||||
"platform": "worldclock",
|
||||
"time_zone": "America/New_York",
|
||||
"time_format": time_format,
|
||||
}
|
||||
async def test_time_format(hass, time_zone):
|
||||
"""Test time_format setting."""
|
||||
time_format = "%a, %b %d, %Y %I:%M %p"
|
||||
config = {
|
||||
"sensor": {
|
||||
"platform": "worldclock",
|
||||
"time_zone": "America/New_York",
|
||||
"time_format": time_format,
|
||||
}
|
||||
assert setup_component(self.hass, "sensor", config)
|
||||
self.hass.block_till_done()
|
||||
self.addCleanup(self.hass.stop)
|
||||
}
|
||||
|
||||
state = self.hass.states.get("sensor.worldclock_sensor")
|
||||
assert state is not None
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"sensor",
|
||||
config,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert state.state == dt_util.now(time_zone=self.time_zone).strftime(
|
||||
time_format
|
||||
)
|
||||
state = hass.states.get("sensor.worldclock_sensor")
|
||||
assert state is not None
|
||||
|
||||
assert state.state == dt_util.now(time_zone=time_zone).strftime(time_format)
|
||||
|
|
Loading…
Add table
Reference in a new issue