Pytest tests (#17750)

* Convert core tests

* Convert component tests to use pytest assert

* Lint 🤷‍♂️

* Fix test

* Fix 3 typos in docs
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2018-10-24 12:10:05 +02:00
1 parent 4222f7562b
commit 08fe7c3ece
223 files changed
+6747 -7237

No files matched your search

+9 -9
View File
@@ -62,56 +62,56 @@ class TestUptimeSensor(unittest.TestCase):
def test_uptime_sensor_days_output(self):
"""Test uptime sensor output data."""
sensor = UptimeSensor('test', 'days')
self.assertEqual(sensor.unit_of_measurement, 'days')
assert sensor.unit_of_measurement == 'days'
new_time = sensor.initial + timedelta(days=1)
with patch('homeassistant.util.dt.now', return_value=new_time):
run_coroutine_threadsafe(
sensor.async_update(),
self.hass.loop
).result()
self.assertEqual(sensor.state, 1.00)
assert sensor.state == 1.00
new_time = sensor.initial + timedelta(days=111.499)
with patch('homeassistant.util.dt.now', return_value=new_time):
run_coroutine_threadsafe(
sensor.async_update(),
self.hass.loop
).result()
self.assertEqual(sensor.state, 111.50)
assert sensor.state == 111.50
def test_uptime_sensor_hours_output(self):
"""Test uptime sensor output data."""
sensor = UptimeSensor('test', 'hours')
self.assertEqual(sensor.unit_of_measurement, 'hours')
assert sensor.unit_of_measurement == 'hours'
new_time = sensor.initial + timedelta(hours=16)
with patch('homeassistant.util.dt.now', return_value=new_time):
run_coroutine_threadsafe(
sensor.async_update(),
self.hass.loop
).result()
self.assertEqual(sensor.state, 16.00)
assert sensor.state == 16.00
new_time = sensor.initial + timedelta(hours=72.499)
with patch('homeassistant.util.dt.now', return_value=new_time):
run_coroutine_threadsafe(
sensor.async_update(),
self.hass.loop
).result()
self.assertEqual(sensor.state, 72.50)
assert sensor.state == 72.50
def test_uptime_sensor_minutes_output(self):
"""Test uptime sensor output data."""
sensor = UptimeSensor('test', 'minutes')
self.assertEqual(sensor.unit_of_measurement, 'minutes')
assert sensor.unit_of_measurement == 'minutes'
new_time = sensor.initial + timedelta(minutes=16)
with patch('homeassistant.util.dt.now', return_value=new_time):
run_coroutine_threadsafe(
sensor.async_update(),
self.hass.loop
).result()
self.assertEqual(sensor.state, 16.00)
assert sensor.state == 16.00
new_time = sensor.initial + timedelta(minutes=12.499)
with patch('homeassistant.util.dt.now', return_value=new_time):
run_coroutine_threadsafe(
sensor.async_update(),
self.hass.loop
).result()
self.assertEqual(sensor.state, 12.50)
assert sensor.state == 12.50