diff --git a/.prettierignore b/.prettierignore index 07637a380c5aa36b30c1524dc9561e688edb7f49..b249b537137533e20e0181e297dc6dae4d3e11a0 100644 --- a/.prettierignore +++ b/.prettierignore @@ -5,3 +5,4 @@ homeassistant/components/*/translations/*.json homeassistant/generated/* tests/components/lidarr/fixtures/initialize.js tests/components/lidarr/fixtures/initialize-wrong.js +tests/fixtures/core/config/yaml_errors/ diff --git a/.yamllint b/.yamllint index e587d75d799244011f0ec31ed2862115b55f3480..d8387c634eef3bd03df4ba112bbae76d07d5e3a6 100644 --- a/.yamllint +++ b/.yamllint @@ -1,5 +1,6 @@ ignore: | azure-*.yml + tests/fixtures/core/config/yaml_errors/ rules: braces: level: error diff --git a/tests/fixtures/core/config/yaml_errors/basic/configuration.yaml b/tests/fixtures/core/config/yaml_errors/basic/configuration.yaml new file mode 100644 index 0000000000000000000000000000000000000000..86292e7ab963a2e3a4d91b0c81b1af0521f73f2f --- /dev/null +++ b/tests/fixtures/core/config/yaml_errors/basic/configuration.yaml @@ -0,0 +1,4 @@ +iot_domain: + # Indentation error + - platform: non_adr_0007 + option1: abc diff --git a/tests/fixtures/core/config/yaml_errors/basic_include/configuration.yaml b/tests/fixtures/core/config/yaml_errors/basic_include/configuration.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7b343d41e9a5276d6d93483488ff00e6830be6c7 --- /dev/null +++ b/tests/fixtures/core/config/yaml_errors/basic_include/configuration.yaml @@ -0,0 +1 @@ +iot_domain: !include integrations/iot_domain.yaml diff --git a/tests/fixtures/core/config/yaml_errors/basic_include/integrations/iot_domain.yaml b/tests/fixtures/core/config/yaml_errors/basic_include/integrations/iot_domain.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4e01fecc74cb51c5b787ad7ce4eab05b04c6a6fe --- /dev/null +++ b/tests/fixtures/core/config/yaml_errors/basic_include/integrations/iot_domain.yaml @@ -0,0 +1,3 @@ +# Indentation error +- platform: non_adr_0007 + option1: abc diff --git a/tests/fixtures/core/config/yaml_errors/include_dir_list/configuration.yaml b/tests/fixtures/core/config/yaml_errors/include_dir_list/configuration.yaml new file mode 100644 index 0000000000000000000000000000000000000000..bb0f052a39ab05efdd1787c5d44e5952192f9bfe --- /dev/null +++ b/tests/fixtures/core/config/yaml_errors/include_dir_list/configuration.yaml @@ -0,0 +1 @@ +iot_domain: !include_dir_list iot_domain diff --git a/tests/fixtures/core/config/yaml_errors/include_dir_list/iot_domain/iot_domain_1.yaml b/tests/fixtures/core/config/yaml_errors/include_dir_list/iot_domain/iot_domain_1.yaml new file mode 100644 index 0000000000000000000000000000000000000000..5c01bd1b3c1d2f9502ebe8c131e3bdedf775755a --- /dev/null +++ b/tests/fixtures/core/config/yaml_errors/include_dir_list/iot_domain/iot_domain_1.yaml @@ -0,0 +1,3 @@ +# Indentation error +platform: non_adr_0007 + option1: abc diff --git a/tests/fixtures/core/config/yaml_errors/include_dir_merge_list/configuration.yaml b/tests/fixtures/core/config/yaml_errors/include_dir_merge_list/configuration.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e0c03e9f4454c7fa32ac7f132517cee16c078424 --- /dev/null +++ b/tests/fixtures/core/config/yaml_errors/include_dir_merge_list/configuration.yaml @@ -0,0 +1 @@ +iot_domain: !include_dir_merge_list iot_domain diff --git a/tests/fixtures/core/config/yaml_errors/include_dir_merge_list/iot_domain/iot_domain_1.yaml b/tests/fixtures/core/config/yaml_errors/include_dir_merge_list/iot_domain/iot_domain_1.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4e01fecc74cb51c5b787ad7ce4eab05b04c6a6fe --- /dev/null +++ b/tests/fixtures/core/config/yaml_errors/include_dir_merge_list/iot_domain/iot_domain_1.yaml @@ -0,0 +1,3 @@ +# Indentation error +- platform: non_adr_0007 + option1: abc diff --git a/tests/fixtures/core/config/yaml_errors/packages_include_dir_named/configuration.yaml b/tests/fixtures/core/config/yaml_errors/packages_include_dir_named/configuration.yaml new file mode 100644 index 0000000000000000000000000000000000000000..d3b52e4d49d9ed293f627762d7c612bda7f2501f --- /dev/null +++ b/tests/fixtures/core/config/yaml_errors/packages_include_dir_named/configuration.yaml @@ -0,0 +1,3 @@ +homeassistant: + # Load packages + packages: !include_dir_named integrations diff --git a/tests/fixtures/core/config/yaml_errors/packages_include_dir_named/integrations/adr_0007_1.yaml b/tests/fixtures/core/config/yaml_errors/packages_include_dir_named/integrations/adr_0007_1.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f9f2f6e7319681c561f66e43903c818f3af6ec45 --- /dev/null +++ b/tests/fixtures/core/config/yaml_errors/packages_include_dir_named/integrations/adr_0007_1.yaml @@ -0,0 +1,4 @@ +# Indentation error +adr_0007_1: + host: blah.com + port: 123 diff --git a/tests/snapshots/test_config.ambr b/tests/snapshots/test_config.ambr index b94116f7bca36362d4a8ec5198cf86cec62c9595..98580600f27267901ac7c361b5f6eaf884378809 100644 --- a/tests/snapshots/test_config.ambr +++ b/tests/snapshots/test_config.ambr @@ -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). ", ]) # --- +# 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 + ''', + ]) +# --- diff --git a/tests/test_config.py b/tests/test_config.py index e8e4541311799ca9cfb1bfd4e2814118bf9551e5..d97d4f7a2c890fa37737afa16349a64372fdb0d6 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1540,3 +1540,40 @@ async def test_package_merge_error( if record.levelno == logging.ERROR ] 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