Rewrite nsw_fuel_station tests to pytest style (#41171)

This commit is contained in:
Ronan Murray 2020-10-19 11:19:39 +01:00 committed by GitHub
parent 5e98bdb19c
commit 16c402f583
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,11 +1,9 @@
"""The tests for the NSW Fuel Station sensor platform.""" """The tests for the NSW Fuel Station sensor platform."""
import unittest
from homeassistant.components import sensor from homeassistant.components import sensor
from homeassistant.setup import setup_component from homeassistant.setup import async_setup_component
from tests.async_mock import patch from tests.async_mock import patch
from tests.common import assert_setup_component, get_test_home_assistant from tests.common import assert_setup_component
VALID_CONFIG = { VALID_CONFIG = {
"platform": "nsw_fuel_station", "platform": "nsw_fuel_station",
@ -72,39 +70,33 @@ class FuelCheckClientMock:
) )
class TestNSWFuelStation(unittest.TestCase): @patch(
"""Test the NSW Fuel Station sensor platform.""" "homeassistant.components.nsw_fuel_station.sensor.FuelCheckClient",
new=FuelCheckClientMock,
)
async def test_setup(hass):
"""Test the setup with custom settings."""
with assert_setup_component(1, sensor.DOMAIN):
assert await async_setup_component(
hass, sensor.DOMAIN, {"sensor": VALID_CONFIG}
)
await hass.async_block_till_done()
def setUp(self): fake_entities = ["my_fake_station_p95", "my_fake_station_e10"]
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.config = VALID_CONFIG
self.addCleanup(self.hass.stop)
@patch( for entity_id in fake_entities:
"homeassistant.components.nsw_fuel_station.sensor.FuelCheckClient", state = hass.states.get(f"sensor.{entity_id}")
new=FuelCheckClientMock, assert state is not None
)
def test_setup(self):
"""Test the setup with custom settings."""
with assert_setup_component(1, sensor.DOMAIN):
assert setup_component(self.hass, sensor.DOMAIN, {"sensor": VALID_CONFIG})
self.hass.block_till_done()
fake_entities = ["my_fake_station_p95", "my_fake_station_e10"]
for entity_id in fake_entities: @patch(
state = self.hass.states.get(f"sensor.{entity_id}") "homeassistant.components.nsw_fuel_station.sensor.FuelCheckClient",
assert state is not None new=FuelCheckClientMock,
)
async def test_sensor_values(hass):
"""Test retrieval of sensor values."""
assert await async_setup_component(hass, sensor.DOMAIN, {"sensor": VALID_CONFIG})
await hass.async_block_till_done()
@patch( assert "140.0" == hass.states.get("sensor.my_fake_station_e10").state
"homeassistant.components.nsw_fuel_station.sensor.FuelCheckClient", assert "150.0" == hass.states.get("sensor.my_fake_station_p95").state
new=FuelCheckClientMock,
)
def test_sensor_values(self):
"""Test retrieval of sensor values."""
assert setup_component(self.hass, sensor.DOMAIN, {"sensor": VALID_CONFIG})
self.hass.block_till_done()
assert "140.0" == self.hass.states.get("sensor.my_fake_station_e10").state
assert "150.0" == self.hass.states.get("sensor.my_fake_station_p95").state