1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Fix check config (#43663)

This commit is contained in:
Paulus Schoutsen
2020-11-26 22:25:21 +01:00
committed by GitHub
parent edf70e9f06
commit e1de36fda8
4 changed files with 85 additions and 21 deletions

View File

@@ -7,8 +7,8 @@ from homeassistant.helpers.check_config import (
async_check_ha_config_file,
)
from tests.async_mock import patch
from tests.common import patch_yaml_files
from tests.async_mock import Mock, patch
from tests.common import mock_platform, patch_yaml_files
_LOGGER = logging.getLogger(__name__)
@@ -37,7 +37,7 @@ def log_ha_config(conf):
_LOGGER.debug("error[%s] = %s", cnt, err)
async def test_bad_core_config(hass, loop):
async def test_bad_core_config(hass):
"""Test a bad core config setup."""
files = {YAML_CONFIG_FILE: BAD_CORE_CONFIG}
with patch("os.path.isfile", return_value=True), patch_yaml_files(files):
@@ -53,7 +53,7 @@ async def test_bad_core_config(hass, loop):
assert not res.errors
async def test_config_platform_valid(hass, loop):
async def test_config_platform_valid(hass):
"""Test a valid platform setup."""
files = {YAML_CONFIG_FILE: BASE_CONFIG + "light:\n platform: demo"}
with patch("os.path.isfile", return_value=True), patch_yaml_files(files):
@@ -65,7 +65,7 @@ async def test_config_platform_valid(hass, loop):
assert not res.errors
async def test_component_platform_not_found(hass, loop):
async def test_component_platform_not_found(hass):
"""Test errors if component or platform not found."""
# Make sure they don't exist
files = {YAML_CONFIG_FILE: BASE_CONFIG + "beer:"}
@@ -83,7 +83,7 @@ async def test_component_platform_not_found(hass, loop):
assert not res.errors
async def test_component_platform_not_found_2(hass, loop):
async def test_component_platform_not_found_2(hass):
"""Test errors if component or platform not found."""
# Make sure they don't exist
files = {YAML_CONFIG_FILE: BASE_CONFIG + "light:\n platform: beer"}
@@ -103,7 +103,7 @@ async def test_component_platform_not_found_2(hass, loop):
assert not res.errors
async def test_package_invalid(hass, loop):
async def test_package_invalid(hass):
"""Test a valid platform setup."""
files = {
YAML_CONFIG_FILE: BASE_CONFIG + (" packages:\n p1:\n" ' group: ["a"]')
@@ -121,7 +121,7 @@ async def test_package_invalid(hass, loop):
assert res.keys() == {"homeassistant"}
async def test_bootstrap_error(hass, loop):
async def test_bootstrap_error(hass):
"""Test a valid platform setup."""
files = {YAML_CONFIG_FILE: BASE_CONFIG + "automation: !include no.yaml"}
with patch("os.path.isfile", return_value=True), patch_yaml_files(files):
@@ -146,6 +146,7 @@ automation:
input:
trigger_event: blueprint_event
service_to_call: test.automation
input_datetime:
""",
hass.config.path(
"blueprints/automation/test_event_service.yaml"
@@ -166,3 +167,28 @@ action:
with patch("os.path.isfile", return_value=True), patch_yaml_files(files):
res = await async_check_ha_config_file(hass)
assert len(res.get("automation", [])) == 1
assert len(res.errors) == 0
assert "input_datetime" in res
async def test_config_platform_raise(hass):
"""Test bad config validation platform."""
mock_platform(
hass,
"bla.config",
Mock(async_validate_config=Mock(side_effect=Exception("Broken"))),
)
files = {
YAML_CONFIG_FILE: BASE_CONFIG
+ """
bla:
value: 1
""",
}
with patch("os.path.isfile", return_value=True), patch_yaml_files(files):
res = await async_check_ha_config_file(hass)
assert len(res.errors) == 1
err = res.errors[0]
assert err.domain == "bla"
assert err.message == "Unexpected error calling config validator: Broken"
assert err.config == {"value": 1}