mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Black
This commit is contained in:
@@ -4,28 +4,26 @@ import os # noqa: F401 pylint: disable=unused-import
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.helpers.check_config import (
|
||||
async_check_ha_config_file, CheckConfigError)
|
||||
async_check_ha_config_file,
|
||||
CheckConfigError,
|
||||
)
|
||||
from homeassistant.config import YAML_CONFIG_FILE
|
||||
from tests.common import patch_yaml_files
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
BASE_CONFIG = (
|
||||
'homeassistant:\n'
|
||||
' name: Home\n'
|
||||
' latitude: -26.107361\n'
|
||||
' longitude: 28.054500\n'
|
||||
' elevation: 1600\n'
|
||||
' unit_system: metric\n'
|
||||
' time_zone: GMT\n'
|
||||
'\n\n'
|
||||
"homeassistant:\n"
|
||||
" name: Home\n"
|
||||
" latitude: -26.107361\n"
|
||||
" longitude: 28.054500\n"
|
||||
" elevation: 1600\n"
|
||||
" unit_system: metric\n"
|
||||
" time_zone: GMT\n"
|
||||
"\n\n"
|
||||
)
|
||||
|
||||
BAD_CORE_CONFIG = (
|
||||
'homeassistant:\n'
|
||||
' unit_system: bad\n'
|
||||
'\n\n'
|
||||
)
|
||||
BAD_CORE_CONFIG = "homeassistant:\n" " unit_system: bad\n" "\n\n"
|
||||
|
||||
|
||||
def log_ha_config(conf):
|
||||
@@ -41,16 +39,14 @@ def log_ha_config(conf):
|
||||
|
||||
async def test_bad_core_config(hass, loop):
|
||||
"""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):
|
||||
files = {YAML_CONFIG_FILE: BAD_CORE_CONFIG}
|
||||
with patch("os.path.isfile", return_value=True), patch_yaml_files(files):
|
||||
res = await async_check_ha_config_file(hass)
|
||||
log_ha_config(res)
|
||||
|
||||
assert isinstance(res.errors[0].message, str)
|
||||
assert res.errors[0].domain == 'homeassistant'
|
||||
assert res.errors[0].config == {'unit_system': 'bad'}
|
||||
assert res.errors[0].domain == "homeassistant"
|
||||
assert res.errors[0].config == {"unit_system": "bad"}
|
||||
|
||||
# Only 1 error expected
|
||||
res.errors.pop(0)
|
||||
@@ -59,31 +55,28 @@ async def test_bad_core_config(hass, loop):
|
||||
|
||||
async def test_config_platform_valid(hass, loop):
|
||||
"""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):
|
||||
files = {YAML_CONFIG_FILE: BASE_CONFIG + "light:\n platform: demo"}
|
||||
with patch("os.path.isfile", return_value=True), patch_yaml_files(files):
|
||||
res = await async_check_ha_config_file(hass)
|
||||
log_ha_config(res)
|
||||
|
||||
assert res.keys() == {'homeassistant', 'light'}
|
||||
assert res['light'] == [{'platform': 'demo'}]
|
||||
assert res.keys() == {"homeassistant", "light"}
|
||||
assert res["light"] == [{"platform": "demo"}]
|
||||
assert not res.errors
|
||||
|
||||
|
||||
async def test_component_platform_not_found(hass, loop):
|
||||
"""Test errors if component or platform not found."""
|
||||
# Make sure they don't exist
|
||||
files = {
|
||||
YAML_CONFIG_FILE: BASE_CONFIG + 'beer:',
|
||||
}
|
||||
with patch('os.path.isfile', return_value=True), patch_yaml_files(files):
|
||||
files = {YAML_CONFIG_FILE: BASE_CONFIG + "beer:"}
|
||||
with patch("os.path.isfile", return_value=True), patch_yaml_files(files):
|
||||
res = await async_check_ha_config_file(hass)
|
||||
log_ha_config(res)
|
||||
|
||||
assert res.keys() == {'homeassistant'}
|
||||
assert res.keys() == {"homeassistant"}
|
||||
assert res.errors[0] == CheckConfigError(
|
||||
'Integration not found: beer', None, None)
|
||||
"Integration not found: beer", None, None
|
||||
)
|
||||
|
||||
# Only 1 error expected
|
||||
res.errors.pop(0)
|
||||
@@ -93,19 +86,19 @@ async def test_component_platform_not_found(hass, loop):
|
||||
async def test_component_platform_not_found_2(hass, loop):
|
||||
"""Test errors if component or platform not found."""
|
||||
# Make sure they don't exist
|
||||
files = {
|
||||
YAML_CONFIG_FILE: BASE_CONFIG + 'light:\n platform: beer',
|
||||
}
|
||||
with patch('os.path.isfile', return_value=True), patch_yaml_files(files):
|
||||
files = {YAML_CONFIG_FILE: BASE_CONFIG + "light:\n platform: beer"}
|
||||
with patch("os.path.isfile", return_value=True), patch_yaml_files(files):
|
||||
res = await async_check_ha_config_file(hass)
|
||||
log_ha_config(res)
|
||||
|
||||
assert res.keys() == {'homeassistant', 'light'}
|
||||
assert res['light'] == []
|
||||
assert res.keys() == {"homeassistant", "light"}
|
||||
assert res["light"] == []
|
||||
|
||||
assert res.errors[0] == CheckConfigError(
|
||||
'Integration beer not found when trying to verify its '
|
||||
'light platform.', None, None)
|
||||
"Integration beer not found when trying to verify its " "light platform.",
|
||||
None,
|
||||
None,
|
||||
)
|
||||
|
||||
# Only 1 error expected
|
||||
res.errors.pop(0)
|
||||
@@ -115,30 +108,26 @@ async def test_component_platform_not_found_2(hass, loop):
|
||||
async def test_package_invalid(hass, loop):
|
||||
"""Test a valid platform setup."""
|
||||
files = {
|
||||
YAML_CONFIG_FILE: BASE_CONFIG + (
|
||||
' packages:\n'
|
||||
' p1:\n'
|
||||
' group: ["a"]'),
|
||||
YAML_CONFIG_FILE: BASE_CONFIG
|
||||
+ (" packages:\n" " p1:\n" ' group: ["a"]')
|
||||
}
|
||||
with patch('os.path.isfile', return_value=True), patch_yaml_files(files):
|
||||
with patch("os.path.isfile", return_value=True), patch_yaml_files(files):
|
||||
res = await async_check_ha_config_file(hass)
|
||||
log_ha_config(res)
|
||||
|
||||
assert res.errors[0].domain == 'homeassistant.packages.p1.group'
|
||||
assert res.errors[0].config == {'group': ['a']}
|
||||
assert res.errors[0].domain == "homeassistant.packages.p1.group"
|
||||
assert res.errors[0].config == {"group": ["a"]}
|
||||
# Only 1 error expected
|
||||
res.errors.pop(0)
|
||||
assert not res.errors
|
||||
|
||||
assert res.keys() == {'homeassistant'}
|
||||
assert res.keys() == {"homeassistant"}
|
||||
|
||||
|
||||
async def test_bootstrap_error(hass, loop):
|
||||
"""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):
|
||||
files = {YAML_CONFIG_FILE: BASE_CONFIG + "automation: !include no.yaml"}
|
||||
with patch("os.path.isfile", return_value=True), patch_yaml_files(files):
|
||||
res = await async_check_ha_config_file(hass)
|
||||
log_ha_config(res)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user