Fail tests if wrapped callbacks or coroutines throw (#35010)
This commit is contained in:
1 parent
b35306052d
commit
f1ecac92df
22 files changed
+156
-38
No files matched your search
@@ -2,6 +2,8 @@
|
||||
import copy
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import alarm_control_panel
|
||||
from homeassistant.const import (
|
||||
STATE_ALARM_ARMED_AWAY,
|
||||
@@ -551,6 +553,7 @@ async def test_discovery_update_alarm(hass, mqtt_mock, caplog):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(hass, mqtt_mock, caplog):
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer" }'
|
||||
|
||||
@@ -3,6 +3,8 @@ import copy
|
||||
from datetime import datetime, timedelta
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import binary_sensor, mqtt
|
||||
from homeassistant.components.mqtt.discovery import async_start
|
||||
from homeassistant.const import (
|
||||
@@ -184,6 +186,43 @@ async def test_setting_sensor_value_via_mqtt_message(hass, mqtt_mock):
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
async def test_invalid_sensor_value_via_mqtt_message(hass, mqtt_mock, caplog):
|
||||
"""Test the setting of the value via MQTT."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
binary_sensor.DOMAIN,
|
||||
{
|
||||
binary_sensor.DOMAIN: {
|
||||
"platform": "mqtt",
|
||||
"name": "test",
|
||||
"state_topic": "test-topic",
|
||||
"payload_on": "ON",
|
||||
"payload_off": "OFF",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
state = hass.states.get("binary_sensor.test")
|
||||
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
async_fire_mqtt_message(hass, "test-topic", "0N")
|
||||
state = hass.states.get("binary_sensor.test")
|
||||
assert state.state == STATE_OFF
|
||||
assert "No matching payload found for entity" in caplog.text
|
||||
caplog.clear()
|
||||
assert "No matching payload found for entity" not in caplog.text
|
||||
|
||||
async_fire_mqtt_message(hass, "test-topic", "ON")
|
||||
state = hass.states.get("binary_sensor.test")
|
||||
assert state.state == STATE_ON
|
||||
|
||||
async_fire_mqtt_message(hass, "test-topic", "0FF")
|
||||
state = hass.states.get("binary_sensor.test")
|
||||
assert state.state == STATE_ON
|
||||
assert "No matching payload found for entity" in caplog.text
|
||||
|
||||
|
||||
async def test_setting_sensor_value_via_mqtt_message_and_template(hass, mqtt_mock):
|
||||
"""Test the setting of the value via MQTT."""
|
||||
assert await async_setup_component(
|
||||
@@ -548,6 +587,7 @@ async def test_expiration_on_discovery_and_discovery_update_of_binary_sensor(
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(hass, mqtt_mock, caplog):
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer",' ' "off_delay": -1 }'
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"""The tests for mqtt camera component."""
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import camera, mqtt
|
||||
from homeassistant.components.mqtt.discovery import async_start
|
||||
from homeassistant.setup import async_setup_component
|
||||
@@ -155,6 +157,7 @@ async def test_discovery_update_camera(hass, mqtt_mock, caplog):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(hass, mqtt_mock, caplog):
|
||||
"""Test handling of bad discovery message."""
|
||||
entry = MockConfigEntry(domain=mqtt.DOMAIN)
|
||||
|
||||
@@ -868,6 +868,7 @@ async def test_discovery_update_climate(hass, mqtt_mock, caplog):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(hass, mqtt_mock, caplog):
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer",' ' "power_command_topic": "test_topic#" }'
|
||||
|
||||
@@ -252,7 +252,6 @@ async def help_test_unique_id(hass, domain, config):
|
||||
"""Test unique id option only creates one entity per unique_id."""
|
||||
await async_mock_mqtt_component(hass)
|
||||
assert await async_setup_component(hass, domain, config,)
|
||||
async_fire_mqtt_message(hass, "test-topic", "payload")
|
||||
assert len(hass.states.async_entity_ids(domain)) == 1
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
"""The tests for the MQTT cover platform."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import cover
|
||||
from homeassistant.components.cover import (
|
||||
ATTR_CURRENT_POSITION,
|
||||
@@ -1831,6 +1833,7 @@ async def test_discovery_update_cover(hass, mqtt_mock, caplog):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(hass, mqtt_mock, caplog):
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer",' ' "command_topic": "test_topic#" }'
|
||||
|
||||
@@ -134,6 +134,7 @@ async def test_get_non_existing_triggers(hass, device_reg, entity_reg, mqtt_mock
|
||||
assert_lists_same(triggers, [])
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discover_bad_triggers(hass, device_reg, entity_reg, mqtt_mock):
|
||||
"""Test bad discovery message."""
|
||||
config_entry = MockConfigEntry(domain=DOMAIN, data={})
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
"""Test MQTT fans."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import fan
|
||||
from homeassistant.const import (
|
||||
ATTR_ASSUMED_STATE,
|
||||
@@ -681,6 +683,7 @@ async def test_discovery_update_fan(hass, mqtt_mock, caplog):
|
||||
await help_test_discovery_update(hass, mqtt_mock, caplog, fan.DOMAIN, data1, data2)
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(hass, mqtt_mock, caplog):
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer" }'
|
||||
|
||||
@@ -821,6 +821,7 @@ async def test_setup_fails_without_config(hass):
|
||||
assert not await async_setup_component(hass, mqtt.DOMAIN, {})
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_message_callback_exception_gets_logged(hass, caplog):
|
||||
"""Test exception raised by message handler."""
|
||||
await async_mock_mqtt_component(hass)
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
from copy import deepcopy
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import vacuum
|
||||
from homeassistant.components.mqtt import CONF_COMMAND_TOPIC
|
||||
from homeassistant.components.mqtt.vacuum import schema_legacy as mqttvacuum
|
||||
@@ -612,6 +614,7 @@ async def test_discovery_update_vacuum(hass, mqtt_mock, caplog):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(hass, mqtt_mock, caplog):
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer",' ' "command_topic": "test_topic#" }'
|
||||
|
||||
@@ -153,6 +153,8 @@ light:
|
||||
payload_off: "off"
|
||||
|
||||
"""
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import light, mqtt
|
||||
from homeassistant.components.mqtt.discovery import async_start
|
||||
from homeassistant.const import ATTR_ASSUMED_STATE, STATE_OFF, STATE_ON
|
||||
@@ -1420,6 +1422,7 @@ async def test_discovery_update_light(hass, mqtt_mock, caplog):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(hass, mqtt_mock, caplog):
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer" }'
|
||||
|
||||
@@ -89,6 +89,8 @@ light:
|
||||
"""
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import light
|
||||
from homeassistant.const import (
|
||||
ATTR_ASSUMED_STATE,
|
||||
@@ -1155,6 +1157,7 @@ async def test_discovery_update_light(hass, mqtt_mock, caplog):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(hass, mqtt_mock, caplog):
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer" }'
|
||||
@@ -1214,5 +1217,5 @@ async def test_entity_id_update_discovery_update(hass, mqtt_mock):
|
||||
async def test_entity_debug_info_message(hass, mqtt_mock):
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG, payload='{"state":"ON"}'
|
||||
)
|
||||
@@ -26,6 +26,8 @@ If your light doesn't support white value feature, omit `white_value_template`.
|
||||
|
||||
If your light doesn't support RGB feature, omit `(red|green|blue)_template`.
|
||||
"""
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import light
|
||||
from homeassistant.const import (
|
||||
ATTR_ASSUMED_STATE,
|
||||
@@ -901,6 +903,7 @@ async def test_discovery_update_light(hass, mqtt_mock, caplog):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(hass, mqtt_mock, caplog):
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer" }'
|
||||
@@ -961,6 +964,15 @@ async def test_entity_id_update_discovery_update(hass, mqtt_mock):
|
||||
|
||||
async def test_entity_debug_info_message(hass, mqtt_mock):
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
config = {
|
||||
light.DOMAIN: {
|
||||
"platform": "mqtt",
|
||||
"schema": "template",
|
||||
"name": "test",
|
||||
"command_topic": "test-topic",
|
||||
"command_on_template": "on,{{ transition }}",
|
||||
"command_off_template": "off,{{ transition|d }}",
|
||||
"state_template": '{{ value.split(",")[0] }}',
|
||||
}
|
||||
}
|
||||
await help_test_entity_debug_info_message(hass, mqtt_mock, light.DOMAIN, config)
|
||||
@@ -1,4 +1,6 @@
|
||||
"""The tests for the MQTT lock platform."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.lock import (
|
||||
DOMAIN as LOCK_DOMAIN,
|
||||
SERVICE_LOCK,
|
||||
@@ -366,6 +368,7 @@ async def test_discovery_update_lock(hass, mqtt_mock, caplog):
|
||||
await help_test_discovery_update(hass, mqtt_mock, caplog, LOCK_DOMAIN, data1, data2)
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(hass, mqtt_mock, caplog):
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer" }'
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
from datetime import datetime, timedelta
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import mqtt
|
||||
from homeassistant.components.mqtt.discovery import async_start
|
||||
import homeassistant.components.sensor as sensor
|
||||
@@ -361,6 +363,7 @@ async def test_discovery_update_sensor(hass, mqtt_mock, caplog):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(hass, mqtt_mock, caplog):
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer",' ' "state_topic": "test_topic#" }'
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
from copy import deepcopy
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import vacuum
|
||||
from homeassistant.components.mqtt import CONF_COMMAND_TOPIC, CONF_STATE_TOPIC
|
||||
from homeassistant.components.mqtt.vacuum import CONF_SCHEMA, schema_state as mqttvacuum
|
||||
@@ -298,6 +300,7 @@ async def test_no_fan_vacuum(hass, mqtt_mock):
|
||||
assert state.attributes.get(ATTR_BATTERY_LEVEL) == 61
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_status_invalid_json(hass, mqtt_mock):
|
||||
"""Test to make sure nothing breaks if the vacuum sends bad JSON."""
|
||||
config = deepcopy(DEFAULT_CONFIG)
|
||||
@@ -406,6 +409,7 @@ async def test_discovery_update_vacuum(hass, mqtt_mock, caplog):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(hass, mqtt_mock, caplog):
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "schema": "state", "name": "Beer",' ' "command_topic": "test_topic#"}'
|
||||
@@ -460,5 +464,5 @@ async def test_entity_id_update_discovery_update(hass, mqtt_mock):
|
||||
async def test_entity_debug_info_message(hass, mqtt_mock):
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass, mqtt_mock, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock, vacuum.DOMAIN, DEFAULT_CONFIG_2, payload="{}"
|
||||
)
|
||||
@@ -314,6 +314,7 @@ async def test_discovery_update_switch(hass, mqtt_mock, caplog):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(hass, mqtt_mock, caplog):
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer" }'
|
||||
|
||||
Reference in new issue
Block a user