Migrate tests to pytest (#23544)

* Migrate tests to pytest

* Fixup

* Use loop fixture in test_check_config

* Lint
This commit is contained in:
Erik Montnemery 2019-04-30 18:20:38 +02:00 committed by Paulus Schoutsen
parent d71424f285
commit 407e0c58f9
25 changed files with 4744 additions and 4910 deletions

View file

@ -1,50 +1,34 @@
"""Tests Home Assistant temperature helpers."""
import unittest
from tests.common import get_test_home_assistant
import pytest
from homeassistant.const import (
TEMP_CELSIUS, PRECISION_WHOLE, TEMP_FAHRENHEIT, PRECISION_HALVES,
PRECISION_TENTHS)
from homeassistant.helpers.temperature import display_temp
from homeassistant.util.unit_system import METRIC_SYSTEM
import pytest
TEMP = 24.636626
class TestHelpersTemperature(unittest.TestCase):
"""Set up the temperature tests."""
def test_temperature_not_a_number(hass):
"""Test that temperature is a number."""
temp = "Temperature"
with pytest.raises(Exception) as exception:
display_temp(hass, temp, TEMP_CELSIUS, PRECISION_HALVES)
def setUp(self):
"""Set up the tests."""
self.hass = get_test_home_assistant()
self.hass.config.unit_system = METRIC_SYSTEM
assert "Temperature is not a number: {}".format(temp) \
in str(exception)
def tearDown(self):
"""Stop down stuff we started."""
self.hass.stop()
def test_temperature_not_a_number(self):
"""Test that temperature is a number."""
temp = "Temperature"
with pytest.raises(Exception) as exception:
display_temp(self.hass, temp, TEMP_CELSIUS, PRECISION_HALVES)
def test_celsius_halves(hass):
"""Test temperature to celsius rounding to halves."""
assert display_temp(hass, TEMP, TEMP_CELSIUS, PRECISION_HALVES) == 24.5
assert "Temperature is not a number: {}".format(temp) \
in str(exception)
def test_celsius_halves(self):
"""Test temperature to celsius rounding to halves."""
assert 24.5 == display_temp(
self.hass, TEMP, TEMP_CELSIUS, PRECISION_HALVES)
def test_celsius_tenths(hass):
"""Test temperature to celsius rounding to tenths."""
assert display_temp(hass, TEMP, TEMP_CELSIUS, PRECISION_TENTHS) == 24.6
def test_celsius_tenths(self):
"""Test temperature to celsius rounding to tenths."""
assert 24.6 == display_temp(
self.hass, TEMP, TEMP_CELSIUS, PRECISION_TENTHS)
def test_fahrenheit_wholes(self):
"""Test temperature to fahrenheit rounding to wholes."""
assert -4 == display_temp(
self.hass, TEMP, TEMP_FAHRENHEIT, PRECISION_WHOLE)
def test_fahrenheit_wholes(hass):
"""Test temperature to fahrenheit rounding to wholes."""
assert display_temp(hass, TEMP, TEMP_FAHRENHEIT, PRECISION_WHOLE) == -4