rewrite mqtt unittest tests to pytest style (#42122)
This commit is contained in:
parent
6c3362217e
commit
e5aa5e2c35
3 changed files with 9 additions and 18 deletions
|
@ -2,7 +2,6 @@
|
|||
import copy
|
||||
from datetime import datetime
|
||||
import json
|
||||
from unittest import mock
|
||||
|
||||
from homeassistant.components import mqtt
|
||||
from homeassistant.components.mqtt import debug_info
|
||||
|
@ -11,7 +10,7 @@ from homeassistant.const import ATTR_ASSUMED_STATE, STATE_UNAVAILABLE
|
|||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import ANY
|
||||
from tests.async_mock import ANY, patch
|
||||
from tests.common import async_fire_mqtt_message, mock_registry
|
||||
|
||||
DEFAULT_CONFIG_DEVICE_INFO_ID = {
|
||||
|
@ -834,7 +833,7 @@ async def help_test_entity_debug_info_max_messages(hass, mqtt_mock, domain, conf
|
|||
]
|
||||
|
||||
start_dt = datetime(2019, 1, 1, 0, 0, 0)
|
||||
with mock.patch("homeassistant.util.dt.utcnow") as dt_utcnow:
|
||||
with patch("homeassistant.util.dt.utcnow") as dt_utcnow:
|
||||
dt_utcnow.return_value = start_dt
|
||||
for i in range(0, debug_info.STORED_MESSAGES + 1):
|
||||
async_fire_mqtt_message(hass, "test-topic", f"{i}")
|
||||
|
@ -896,7 +895,7 @@ async def help_test_entity_debug_info_message(
|
|||
]
|
||||
|
||||
start_dt = datetime(2019, 1, 1, 0, 0, 0)
|
||||
with mock.patch("homeassistant.util.dt.utcnow") as dt_utcnow:
|
||||
with patch("homeassistant.util.dt.utcnow") as dt_utcnow:
|
||||
dt_utcnow.return_value = start_dt
|
||||
async_fire_mqtt_message(hass, topic, payload)
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
"""The tests for the MQTT subscription component."""
|
||||
from unittest import mock
|
||||
|
||||
from homeassistant.components.mqtt.subscription import (
|
||||
async_subscribe_topics,
|
||||
async_unsubscribe_topics,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
|
||||
from tests.async_mock import ANY
|
||||
from tests.common import async_fire_mqtt_message
|
||||
|
||||
|
||||
|
@ -131,9 +130,7 @@ async def test_qos_encoding_default(hass, mqtt_mock, caplog):
|
|||
sub_state,
|
||||
{"test_topic1": {"topic": "test-topic1", "msg_callback": msg_callback}},
|
||||
)
|
||||
mqtt_mock.async_subscribe.assert_called_once_with(
|
||||
"test-topic1", mock.ANY, 0, "utf-8"
|
||||
)
|
||||
mqtt_mock.async_subscribe.assert_called_once_with("test-topic1", ANY, 0, "utf-8")
|
||||
|
||||
|
||||
async def test_qos_encoding_custom(hass, mqtt_mock, caplog):
|
||||
|
@ -157,9 +154,7 @@ async def test_qos_encoding_custom(hass, mqtt_mock, caplog):
|
|||
}
|
||||
},
|
||||
)
|
||||
mqtt_mock.async_subscribe.assert_called_once_with(
|
||||
"test-topic1", mock.ANY, 1, "utf-16"
|
||||
)
|
||||
mqtt_mock.async_subscribe.assert_called_once_with("test-topic1", ANY, 1, "utf-16")
|
||||
|
||||
|
||||
async def test_no_change(hass, mqtt_mock, caplog):
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
"""The tests for the MQTT automation."""
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
import homeassistant.components.automation as automation
|
||||
from homeassistant.const import ATTR_ENTITY_ID, ENTITY_MATCH_ALL, SERVICE_TURN_OFF
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import ANY
|
||||
from tests.common import async_fire_mqtt_message, async_mock_service, mock_component
|
||||
|
||||
|
||||
|
@ -115,9 +114,7 @@ async def test_encoding_default(hass, calls, mqtt_mock):
|
|||
},
|
||||
)
|
||||
|
||||
mqtt_mock.async_subscribe.assert_called_once_with(
|
||||
"test-topic", mock.ANY, 0, "utf-8"
|
||||
)
|
||||
mqtt_mock.async_subscribe.assert_called_once_with("test-topic", ANY, 0, "utf-8")
|
||||
|
||||
|
||||
async def test_encoding_custom(hass, calls, mqtt_mock):
|
||||
|
@ -133,4 +130,4 @@ async def test_encoding_custom(hass, calls, mqtt_mock):
|
|||
},
|
||||
)
|
||||
|
||||
mqtt_mock.async_subscribe.assert_called_once_with("test-topic", mock.ANY, 0, None)
|
||||
mqtt_mock.async_subscribe.assert_called_once_with("test-topic", ANY, 0, None)
|
||||
|
|
Loading…
Add table
Reference in a new issue