Changed FilterTest namedtuples to dataclasses (#37252)

This commit is contained in:
mdegat01 2020-06-30 12:59:21 -04:00 committed by GitHub
parent 86c27b50f1
commit b78f163bb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 13 deletions

View file

@ -1,5 +1,7 @@
"""The tests for the Apache Kafka component.""" """The tests for the Apache Kafka component."""
from collections import namedtuple from asyncio import AbstractEventLoop
from dataclasses import dataclass
from typing import Callable, Type
import pytest import pytest
@ -16,8 +18,23 @@ MIN_CONFIG = {
"port": 8080, "port": 8080,
"topic": "topic", "topic": "topic",
} }
FilterTest = namedtuple("FilterTest", "id should_pass")
MockKafkaClient = namedtuple("MockKafkaClient", "init start send_and_wait")
@dataclass
class FilterTest:
"""Class for capturing a filter test."""
id: str
should_pass: bool
@dataclass
class MockKafkaClient:
"""Mock of the Apache Kafka client for testing."""
init: Callable[[Type[AbstractEventLoop], str, str], None]
start: Callable[[], None]
send_and_wait: Callable[[str, str], None]
@pytest.fixture(name="mock_client") @pytest.fixture(name="mock_client")

View file

@ -1,5 +1,5 @@
"""The tests for the Azure Event Hub component.""" """The tests for the Azure Event Hub component."""
from collections import namedtuple from dataclasses import dataclass
import pytest import pytest
@ -17,7 +17,14 @@ MIN_CONFIG = {
"event_hub_sas_policy": "policy", "event_hub_sas_policy": "policy",
"event_hub_sas_key": "key", "event_hub_sas_key": "key",
} }
FilterTest = namedtuple("FilterTest", "id should_pass")
@dataclass
class FilterTest:
"""Class for capturing a filter test."""
id: str
should_pass: bool
@pytest.fixture(autouse=True, name="mock_client", scope="module") @pytest.fixture(autouse=True, name="mock_client", scope="module")

View file

@ -1,5 +1,5 @@
"""The tests for the Google Pub/Sub component.""" """The tests for the Google Pub/Sub component."""
from collections import namedtuple from dataclasses import dataclass
from datetime import datetime from datetime import datetime
import pytest import pytest
@ -15,6 +15,14 @@ import tests.async_mock as mock
GOOGLE_PUBSUB_PATH = "homeassistant.components.google_pubsub" GOOGLE_PUBSUB_PATH = "homeassistant.components.google_pubsub"
@dataclass
class FilterTest:
"""Class for capturing a filter test."""
id: str
should_pass: bool
async def test_datetime(): async def test_datetime():
"""Test datetime encoding.""" """Test datetime encoding."""
time = datetime(2019, 1, 13, 12, 30, 5) time = datetime(2019, 1, 13, 12, 30, 5)
@ -109,9 +117,6 @@ async def test_full_config(hass, mock_client):
) )
FilterTest = namedtuple("FilterTest", "id should_pass")
def make_event(entity_id): def make_event(entity_id):
"""Make a mock event for test.""" """Make a mock event for test."""
domain = split_entity_id(entity_id)[0] domain = split_entity_id(entity_id)[0]

View file

@ -1,5 +1,5 @@
"""The tests for the Prometheus exporter.""" """The tests for the Prometheus exporter."""
from collections import namedtuple from dataclasses import dataclass
import pytest import pytest
@ -22,6 +22,14 @@ import tests.async_mock as mock
PROMETHEUS_PATH = "homeassistant.components.prometheus" PROMETHEUS_PATH = "homeassistant.components.prometheus"
@dataclass
class FilterTest:
"""Class for capturing a filter test."""
id: str
should_pass: bool
@pytest.fixture @pytest.fixture
async def prometheus_client(loop, hass, hass_client): async def prometheus_client(loop, hass, hass_client):
"""Initialize an hass_client with Prometheus component.""" """Initialize an hass_client with Prometheus component."""
@ -202,9 +210,6 @@ async def test_full_config(hass, mock_client):
assert EVENT_STATE_CHANGED == hass.bus.listen.call_args_list[0][0][0] assert EVENT_STATE_CHANGED == hass.bus.listen.call_args_list[0][0][0]
FilterTest = namedtuple("FilterTest", "id should_pass")
def make_event(entity_id): def make_event(entity_id):
"""Make a mock event for test.""" """Make a mock event for test."""
domain = split_entity_id(entity_id)[0] domain = split_entity_id(entity_id)[0]