mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Rewrite transport_nsw sensor tests to pytest tests (#41169)
* Improve transport_nsw sensor tests. * patch fix.
This commit is contained in:
parent
27c3ce16c3
commit
e64b8774ec
@ -1,10 +1,7 @@
|
|||||||
"""The tests for the Transport NSW (AU) sensor platform."""
|
"""The tests for the Transport NSW (AU) sensor platform."""
|
||||||
import unittest
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from homeassistant.setup import setup_component
|
|
||||||
|
|
||||||
from tests.async_mock import patch
|
from tests.async_mock import patch
|
||||||
from tests.common import get_test_home_assistant
|
|
||||||
|
|
||||||
VALID_CONFIG = {
|
VALID_CONFIG = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
@ -31,24 +28,16 @@ def get_departuresMock(_stop_id, route, destination, api_key):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
class TestRMVtransportSensor(unittest.TestCase):
|
@patch("TransportNSW.TransportNSW.get_departures", side_effect=get_departuresMock)
|
||||||
"""Test the TransportNSW sensor."""
|
async def test_transportnsw_config(mocked_get_departures, hass):
|
||||||
|
"""Test minimal TransportNSW configuration."""
|
||||||
def setUp(self):
|
assert await async_setup_component(hass, "sensor", VALID_CONFIG)
|
||||||
"""Set up things to run when tests begin."""
|
await hass.async_block_till_done()
|
||||||
self.hass = get_test_home_assistant()
|
state = hass.states.get("sensor.next_bus")
|
||||||
self.addCleanup(self.hass.stop)
|
assert state.state == "16"
|
||||||
|
assert state.attributes["stop_id"] == "209516"
|
||||||
@patch("TransportNSW.TransportNSW.get_departures", side_effect=get_departuresMock)
|
assert state.attributes["route"] == "199"
|
||||||
def test_transportnsw_config(self, mock_get_departures):
|
assert state.attributes["delay"] == 6
|
||||||
"""Test minimal TransportNSW configuration."""
|
assert state.attributes["real_time"] == "y"
|
||||||
assert setup_component(self.hass, "sensor", VALID_CONFIG)
|
assert state.attributes["destination"] == "Palm Beach"
|
||||||
self.hass.block_till_done()
|
assert state.attributes["mode"] == "Bus"
|
||||||
state = self.hass.states.get("sensor.next_bus")
|
|
||||||
assert state.state == "16"
|
|
||||||
assert state.attributes["stop_id"] == "209516"
|
|
||||||
assert state.attributes["route"] == "199"
|
|
||||||
assert state.attributes["delay"] == 6
|
|
||||||
assert state.attributes["real_time"] == "y"
|
|
||||||
assert state.attributes["destination"] == "Palm Beach"
|
|
||||||
assert state.attributes["mode"] == "Bus"
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user