Add tests for yaml syntax errors (#103908)
This commit is contained in:
parent
2bdd969cf6
commit
e64582ae9a
13 changed files with 132 additions and 0 deletions
|
@ -5,3 +5,4 @@ homeassistant/components/*/translations/*.json
|
||||||
homeassistant/generated/*
|
homeassistant/generated/*
|
||||||
tests/components/lidarr/fixtures/initialize.js
|
tests/components/lidarr/fixtures/initialize.js
|
||||||
tests/components/lidarr/fixtures/initialize-wrong.js
|
tests/components/lidarr/fixtures/initialize-wrong.js
|
||||||
|
tests/fixtures/core/config/yaml_errors/
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
ignore: |
|
ignore: |
|
||||||
azure-*.yml
|
azure-*.yml
|
||||||
|
tests/fixtures/core/config/yaml_errors/
|
||||||
rules:
|
rules:
|
||||||
braces:
|
braces:
|
||||||
level: error
|
level: error
|
||||||
|
|
4
tests/fixtures/core/config/yaml_errors/basic/configuration.yaml
vendored
Normal file
4
tests/fixtures/core/config/yaml_errors/basic/configuration.yaml
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
iot_domain:
|
||||||
|
# Indentation error
|
||||||
|
- platform: non_adr_0007
|
||||||
|
option1: abc
|
1
tests/fixtures/core/config/yaml_errors/basic_include/configuration.yaml
vendored
Normal file
1
tests/fixtures/core/config/yaml_errors/basic_include/configuration.yaml
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
iot_domain: !include integrations/iot_domain.yaml
|
3
tests/fixtures/core/config/yaml_errors/basic_include/integrations/iot_domain.yaml
vendored
Normal file
3
tests/fixtures/core/config/yaml_errors/basic_include/integrations/iot_domain.yaml
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Indentation error
|
||||||
|
- platform: non_adr_0007
|
||||||
|
option1: abc
|
1
tests/fixtures/core/config/yaml_errors/include_dir_list/configuration.yaml
vendored
Normal file
1
tests/fixtures/core/config/yaml_errors/include_dir_list/configuration.yaml
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
iot_domain: !include_dir_list iot_domain
|
3
tests/fixtures/core/config/yaml_errors/include_dir_list/iot_domain/iot_domain_1.yaml
vendored
Normal file
3
tests/fixtures/core/config/yaml_errors/include_dir_list/iot_domain/iot_domain_1.yaml
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Indentation error
|
||||||
|
platform: non_adr_0007
|
||||||
|
option1: abc
|
1
tests/fixtures/core/config/yaml_errors/include_dir_merge_list/configuration.yaml
vendored
Normal file
1
tests/fixtures/core/config/yaml_errors/include_dir_merge_list/configuration.yaml
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
iot_domain: !include_dir_merge_list iot_domain
|
3
tests/fixtures/core/config/yaml_errors/include_dir_merge_list/iot_domain/iot_domain_1.yaml
vendored
Normal file
3
tests/fixtures/core/config/yaml_errors/include_dir_merge_list/iot_domain/iot_domain_1.yaml
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Indentation error
|
||||||
|
- platform: non_adr_0007
|
||||||
|
option1: abc
|
3
tests/fixtures/core/config/yaml_errors/packages_include_dir_named/configuration.yaml
vendored
Normal file
3
tests/fixtures/core/config/yaml_errors/packages_include_dir_named/configuration.yaml
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
homeassistant:
|
||||||
|
# Load packages
|
||||||
|
packages: !include_dir_named integrations
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Indentation error
|
||||||
|
adr_0007_1:
|
||||||
|
host: blah.com
|
||||||
|
port: 123
|
|
@ -57,3 +57,73 @@
|
||||||
"Package adr_0007_3_2 setup failed. Integration adr_0007_3 has duplicate key 'host' (See <BASE_PATH>/fixtures/core/config/package_errors/packages_include_dir_named/integrations/adr_0007_3_2.yaml:1). ",
|
"Package adr_0007_3_2 setup failed. Integration adr_0007_3 has duplicate key 'host' (See <BASE_PATH>/fixtures/core/config/package_errors/packages_include_dir_named/integrations/adr_0007_3_2.yaml:1). ",
|
||||||
])
|
])
|
||||||
# ---
|
# ---
|
||||||
|
# name: test_yaml_error[basic]
|
||||||
|
'''
|
||||||
|
mapping values are not allowed here
|
||||||
|
in "<BASE_PATH>/fixtures/core/config/yaml_errors/basic/configuration.yaml", line 4, column 14
|
||||||
|
'''
|
||||||
|
# ---
|
||||||
|
# name: test_yaml_error[basic].1
|
||||||
|
list([
|
||||||
|
'''
|
||||||
|
mapping values are not allowed here
|
||||||
|
in "<BASE_PATH>/fixtures/core/config/yaml_errors/basic/configuration.yaml", line 4, column 14
|
||||||
|
''',
|
||||||
|
])
|
||||||
|
# ---
|
||||||
|
# name: test_yaml_error[basic_include]
|
||||||
|
'''
|
||||||
|
mapping values are not allowed here
|
||||||
|
in "<BASE_PATH>/fixtures/core/config/yaml_errors/basic_include/integrations/iot_domain.yaml", line 3, column 12
|
||||||
|
'''
|
||||||
|
# ---
|
||||||
|
# name: test_yaml_error[basic_include].1
|
||||||
|
list([
|
||||||
|
'''
|
||||||
|
mapping values are not allowed here
|
||||||
|
in "<BASE_PATH>/fixtures/core/config/yaml_errors/basic_include/integrations/iot_domain.yaml", line 3, column 12
|
||||||
|
''',
|
||||||
|
])
|
||||||
|
# ---
|
||||||
|
# name: test_yaml_error[include_dir_list]
|
||||||
|
'''
|
||||||
|
mapping values are not allowed here
|
||||||
|
in "<BASE_PATH>/fixtures/core/config/yaml_errors/include_dir_list/iot_domain/iot_domain_1.yaml", line 3, column 10
|
||||||
|
'''
|
||||||
|
# ---
|
||||||
|
# name: test_yaml_error[include_dir_list].1
|
||||||
|
list([
|
||||||
|
'''
|
||||||
|
mapping values are not allowed here
|
||||||
|
in "<BASE_PATH>/fixtures/core/config/yaml_errors/include_dir_list/iot_domain/iot_domain_1.yaml", line 3, column 10
|
||||||
|
''',
|
||||||
|
])
|
||||||
|
# ---
|
||||||
|
# name: test_yaml_error[include_dir_merge_list]
|
||||||
|
'''
|
||||||
|
mapping values are not allowed here
|
||||||
|
in "<BASE_PATH>/fixtures/core/config/yaml_errors/include_dir_merge_list/iot_domain/iot_domain_1.yaml", line 3, column 12
|
||||||
|
'''
|
||||||
|
# ---
|
||||||
|
# name: test_yaml_error[include_dir_merge_list].1
|
||||||
|
list([
|
||||||
|
'''
|
||||||
|
mapping values are not allowed here
|
||||||
|
in "<BASE_PATH>/fixtures/core/config/yaml_errors/include_dir_merge_list/iot_domain/iot_domain_1.yaml", line 3, column 12
|
||||||
|
''',
|
||||||
|
])
|
||||||
|
# ---
|
||||||
|
# name: test_yaml_error[packages_include_dir_named]
|
||||||
|
'''
|
||||||
|
mapping values are not allowed here
|
||||||
|
in "<BASE_PATH>/fixtures/core/config/yaml_errors/packages_include_dir_named/integrations/adr_0007_1.yaml", line 4, column 9
|
||||||
|
'''
|
||||||
|
# ---
|
||||||
|
# name: test_yaml_error[packages_include_dir_named].1
|
||||||
|
list([
|
||||||
|
'''
|
||||||
|
mapping values are not allowed here
|
||||||
|
in "<BASE_PATH>/fixtures/core/config/yaml_errors/packages_include_dir_named/integrations/adr_0007_1.yaml", line 4, column 9
|
||||||
|
''',
|
||||||
|
])
|
||||||
|
# ---
|
||||||
|
|
|
@ -1540,3 +1540,40 @@ async def test_package_merge_error(
|
||||||
if record.levelno == logging.ERROR
|
if record.levelno == logging.ERROR
|
||||||
]
|
]
|
||||||
assert error_records == snapshot
|
assert error_records == snapshot
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"config_dir",
|
||||||
|
[
|
||||||
|
"basic",
|
||||||
|
"basic_include",
|
||||||
|
"include_dir_list",
|
||||||
|
"include_dir_merge_list",
|
||||||
|
"packages_include_dir_named",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_yaml_error(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
config_dir: str,
|
||||||
|
mock_iot_domain_integration: Integration,
|
||||||
|
mock_non_adr_0007_integration: None,
|
||||||
|
mock_adr_0007_integrations: list[Integration],
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
) -> None:
|
||||||
|
"""Test schema error in component."""
|
||||||
|
|
||||||
|
base_path = os.path.dirname(__file__)
|
||||||
|
hass.config.config_dir = os.path.join(
|
||||||
|
base_path, "fixtures", "core", "config", "yaml_errors", config_dir
|
||||||
|
)
|
||||||
|
with pytest.raises(HomeAssistantError) as exc_info:
|
||||||
|
await config_util.async_hass_config_yaml(hass)
|
||||||
|
assert str(exc_info.value).replace(base_path, "<BASE_PATH>") == snapshot
|
||||||
|
|
||||||
|
error_records = [
|
||||||
|
record.message.replace(base_path, "<BASE_PATH>")
|
||||||
|
for record in caplog.get_records("call")
|
||||||
|
if record.levelno == logging.ERROR
|
||||||
|
]
|
||||||
|
assert error_records == snapshot
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue