mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Remove classes in nx584 tests (#42628)
This commit is contained in:
parent
8f22c5917f
commit
9fc92ab04e
@ -46,13 +46,9 @@ def client(fake_zones):
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("client")
|
||||
class TestNX584SensorSetup:
|
||||
"""Test the NX584 sensor platform."""
|
||||
|
||||
@staticmethod
|
||||
@mock.patch("homeassistant.components.nx584.binary_sensor.NX584Watcher")
|
||||
@mock.patch("homeassistant.components.nx584.binary_sensor.NX584ZoneSensor")
|
||||
def test_setup_defaults(mock_nx, mock_watcher, hass, fake_zones):
|
||||
def test_nx584_sensor_setup_defaults(mock_nx, mock_watcher, hass, fake_zones):
|
||||
"""Test the setup with no configuration."""
|
||||
add_entities = mock.MagicMock()
|
||||
config = {
|
||||
@ -67,10 +63,11 @@ class TestNX584SensorSetup:
|
||||
assert nx584_client.Client.call_count == 1
|
||||
assert nx584_client.Client.call_args == mock.call("http://localhost:5007")
|
||||
|
||||
@staticmethod
|
||||
|
||||
@pytest.mark.usefixtures("client")
|
||||
@mock.patch("homeassistant.components.nx584.binary_sensor.NX584Watcher")
|
||||
@mock.patch("homeassistant.components.nx584.binary_sensor.NX584ZoneSensor")
|
||||
def test_setup_full_config(mock_nx, mock_watcher, hass, fake_zones):
|
||||
def test_nx584_sensor_setup_full_config(mock_nx, mock_watcher, hass, fake_zones):
|
||||
"""Test the setup with full configuration."""
|
||||
config = {
|
||||
"host": "foo",
|
||||
@ -91,11 +88,13 @@ class TestNX584SensorSetup:
|
||||
assert nx584_client.Client.call_args == mock.call("http://foo:123")
|
||||
assert mock_watcher.called
|
||||
|
||||
@staticmethod
|
||||
|
||||
async def _test_assert_graceful_fail(hass, config):
|
||||
"""Test the failing."""
|
||||
assert not await async_setup_component(hass, "nx584", config)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("client")
|
||||
@pytest.mark.parametrize(
|
||||
"config",
|
||||
[
|
||||
@ -105,10 +104,12 @@ class TestNX584SensorSetup:
|
||||
({"zone_types": {"notazone": "motion"}}),
|
||||
],
|
||||
)
|
||||
async def test_setup_bad_config(self, hass, config):
|
||||
async def test_nx584_sensor_setup_bad_config(hass, config):
|
||||
"""Test the setup with bad configuration."""
|
||||
await self._test_assert_graceful_fail(hass, config)
|
||||
await _test_assert_graceful_fail(hass, config)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("client")
|
||||
@pytest.mark.parametrize(
|
||||
"exception_type",
|
||||
[
|
||||
@ -116,18 +117,21 @@ class TestNX584SensorSetup:
|
||||
pytest.param(IndexError, id="no_partitions"),
|
||||
],
|
||||
)
|
||||
async def test_setup_with_exceptions(self, hass, exception_type):
|
||||
async def test_nx584_sensor_setup_with_exceptions(hass, exception_type):
|
||||
"""Test the setup handles exceptions."""
|
||||
nx584_client.Client.return_value.list_zones.side_effect = exception_type
|
||||
await self._test_assert_graceful_fail(hass, {})
|
||||
await _test_assert_graceful_fail(hass, {})
|
||||
|
||||
async def test_setup_version_too_old(self, hass):
|
||||
|
||||
@pytest.mark.usefixtures("client")
|
||||
async def test_nx584_sensor_setup_version_too_old(hass):
|
||||
"""Test if version is too old."""
|
||||
nx584_client.Client.return_value.get_version.return_value = "1.0"
|
||||
await self._test_assert_graceful_fail(hass, {})
|
||||
await _test_assert_graceful_fail(hass, {})
|
||||
|
||||
@staticmethod
|
||||
def test_setup_no_zones(hass):
|
||||
|
||||
@pytest.mark.usefixtures("client")
|
||||
def test_nx584_sensor_setup_no_zones(hass):
|
||||
"""Test the setup with no zones."""
|
||||
nx584_client.Client.return_value.list_zones.return_value = []
|
||||
add_entities = mock.MagicMock()
|
||||
@ -148,12 +152,8 @@ def test_nx584_zone_sensor_normal():
|
||||
assert not sensor.is_on
|
||||
|
||||
|
||||
class TestNX584Watcher:
|
||||
"""Test the NX584 watcher."""
|
||||
|
||||
@staticmethod
|
||||
@mock.patch.object(nx584.NX584ZoneSensor, "schedule_update_ha_state")
|
||||
def test_process_zone_event(mock_update):
|
||||
def test_nx584_watcher_process_zone_event(mock_update):
|
||||
"""Test the processing of zone events."""
|
||||
zone1 = {"number": 1, "name": "foo", "state": True}
|
||||
zone2 = {"number": 2, "name": "bar", "state": True}
|
||||
@ -166,16 +166,16 @@ class TestNX584Watcher:
|
||||
assert not zone1["state"]
|
||||
assert mock_update.call_count == 1
|
||||
|
||||
@staticmethod
|
||||
|
||||
@mock.patch.object(nx584.NX584ZoneSensor, "schedule_update_ha_state")
|
||||
def test_process_zone_event_missing_zone(mock_update):
|
||||
def test_nx584_watcher_process_zone_event_missing_zone(mock_update):
|
||||
"""Test the processing of zone events with missing zones."""
|
||||
watcher = nx584.NX584Watcher(None, {})
|
||||
watcher._process_zone_event({"zone": 1, "zone_state": False})
|
||||
assert not mock_update.called
|
||||
|
||||
@staticmethod
|
||||
def test_run_with_zone_events():
|
||||
|
||||
def test_nx584_watcher_run_with_zone_events():
|
||||
"""Test the zone events."""
|
||||
empty_me = [1, 2]
|
||||
|
||||
@ -206,9 +206,9 @@ class TestNX584Watcher:
|
||||
run()
|
||||
assert 3 == client.get_events.call_count
|
||||
|
||||
@staticmethod
|
||||
|
||||
@mock.patch("time.sleep")
|
||||
def test_run_retries_failures(mock_sleep):
|
||||
def test_nx584_watcher_run_retries_failures(mock_sleep):
|
||||
"""Test the retries with failures."""
|
||||
empty_me = [1, 2]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user