Improve onewire tests (#85064)

This commit is contained in:
epenet 2023-01-03 17:32:39 +01:00 committed by GitHub
parent 6af07aa348
commit 3737170d37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 8 deletions

View File

@ -1,4 +1,5 @@
"""Tests for 1-Wire binary sensors.""" """Tests for 1-Wire binary sensors."""
from collections.abc import Generator
import logging import logging
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
@ -21,7 +22,7 @@ from tests.common import mock_device_registry, mock_registry
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def override_platforms(): def override_platforms() -> Generator[None, None, None]:
"""Override PLATFORMS.""" """Override PLATFORMS."""
with patch("homeassistant.components.onewire.PLATFORMS", [Platform.BINARY_SENSOR]): with patch("homeassistant.components.onewire.PLATFORMS", [Platform.BINARY_SENSOR]):
yield yield
@ -33,7 +34,7 @@ async def test_binary_sensors(
owproxy: MagicMock, owproxy: MagicMock,
device_id: str, device_id: str,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
): ) -> None:
"""Test for 1-Wire binary sensor. """Test for 1-Wire binary sensor.
This test forces all entities to be enabled. This test forces all entities to be enabled.

View File

@ -1,4 +1,5 @@
"""Test 1-Wire diagnostics.""" """Test 1-Wire diagnostics."""
from collections.abc import Generator
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
import pytest import pytest
@ -14,7 +15,7 @@ from tests.components.diagnostics import get_diagnostics_for_config_entry
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def override_platforms(): def override_platforms() -> Generator[None, None, None]:
"""Override PLATFORMS.""" """Override PLATFORMS."""
with patch("homeassistant.components.onewire.PLATFORMS", [Platform.SWITCH]): with patch("homeassistant.components.onewire.PLATFORMS", [Platform.SWITCH]):
yield yield
@ -41,7 +42,7 @@ async def test_entry_diagnostics(
hass_client, hass_client,
owproxy: MagicMock, owproxy: MagicMock,
device_id: str, device_id: str,
): ) -> None:
"""Test config entry diagnostics.""" """Test config entry diagnostics."""
setup_owproxy_mock_devices(owproxy, Platform.SENSOR, [device_id]) setup_owproxy_mock_devices(owproxy, Platform.SENSOR, [device_id])
await hass.config_entries.async_setup(config_entry.entry_id) await hass.config_entries.async_setup(config_entry.entry_id)

View File

@ -1,4 +1,5 @@
"""Tests for 1-Wire sensors.""" """Tests for 1-Wire sensors."""
from collections.abc import Generator
import logging import logging
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
@ -21,7 +22,7 @@ from tests.common import mock_device_registry, mock_registry
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def override_platforms(): def override_platforms() -> Generator[None, None, None]:
"""Override PLATFORMS.""" """Override PLATFORMS."""
with patch("homeassistant.components.onewire.PLATFORMS", [Platform.SENSOR]): with patch("homeassistant.components.onewire.PLATFORMS", [Platform.SENSOR]):
yield yield
@ -33,7 +34,7 @@ async def test_sensors(
owproxy: MagicMock, owproxy: MagicMock,
device_id: str, device_id: str,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
): ) -> None:
"""Test for 1-Wire device. """Test for 1-Wire device.
As they would be on a clean setup: all binary-sensors and switches disabled. As they would be on a clean setup: all binary-sensors and switches disabled.

View File

@ -1,4 +1,5 @@
"""Tests for 1-Wire switches.""" """Tests for 1-Wire switches."""
from collections.abc import Generator
import logging import logging
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
@ -29,7 +30,7 @@ from tests.common import mock_device_registry, mock_registry
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def override_platforms(): def override_platforms() -> Generator[None, None, None]:
"""Override PLATFORMS.""" """Override PLATFORMS."""
with patch("homeassistant.components.onewire.PLATFORMS", [Platform.SWITCH]): with patch("homeassistant.components.onewire.PLATFORMS", [Platform.SWITCH]):
yield yield
@ -41,7 +42,7 @@ async def test_switches(
owproxy: MagicMock, owproxy: MagicMock,
device_id: str, device_id: str,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
): ) -> None:
"""Test for 1-Wire switch. """Test for 1-Wire switch.
This test forces all entities to be enabled. This test forces all entities to be enabled.