Skip to content

Commit

Permalink
Add tests for component configuration with multiple errors (home-assi…
Browse files Browse the repository at this point in the history
…stant#103964)

* Add tests for component configuration with multiple errors

* Add new configuration file

* Fix typo

---------

Co-authored-by: Martin Hjelmare <[email protected]>
  • Loading branch information
emontnemery and MartinHjelmare authored Nov 14, 2023
1 parent 2d39eaf commit 381ebf3
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ iot_domain:
# This violates the non_adr_0007.iot_domain platform schema (no_such_option does not exist)
- platform: non_adr_0007
no_such_option: abc
option1: abc
# This violates the non_adr_0007.iot_domain platform schema:
# - no_such_option does not exist
# - option1 is missing
# - option2 is wrong type
- platform: non_adr_0007
no_such_option: abc
option2: 123

# This is correct and should not generate errors
adr_0007_1:
Expand All @@ -27,3 +35,11 @@ adr_0007_3:
adr_0007_4:
host: blah.com
no_such_option: foo

# Multiple errors:
# - host is missing
# - no_such_option does not exist
# - port is wrong type
adr_0007_5:
no_such_option: foo
port: foo
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ iot_domain: !include integrations/iot_domain.yaml
adr_0007_1: !include integrations/adr_0007_1.yaml
adr_0007_2: !include integrations/adr_0007_2.yaml
adr_0007_3: !include integrations/adr_0007_3.yaml
adr_0007_4: !include integrations/adr_0007_4.yaml
adr_0007_5: !include integrations/adr_0007_5.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Multiple errors:
# - host is missing
# - no_such_option does not exist
# - port is wrong type
no_such_option: foo
port: foo
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@
# This violates the non_adr_0007.iot_domain platform schema (no_such_option does not exist)
- platform: non_adr_0007
no_such_option: abc
option1: abc
# This violates the non_adr_0007.iot_domain platform schema:
# - no_such_option does not exist
# - option1 is missing
# - option2 is wrong type
- platform: non_adr_0007
no_such_option: abc
option2: 123
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This violates the non_adr_0007.iot_domain platform schema (no_such_option does not exist)
platform: non_adr_0007
no_such_option: abc
option1: abc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This violates the non_adr_0007.iot_domain platform schema:
# - no_such_option does not exist
# - option1 is missing
# - option2 is wrong type
platform: non_adr_0007
no_such_option: abc
option2: 123
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@
# This violates the non_adr_0007.iot_domain platform schema (no_such_option does not exist)
- platform: non_adr_0007
no_such_option: abc
option1: abc
# This violates the non_adr_0007.iot_domain platform schema:
# - no_such_option does not exist
# - option1 is missing
# - option2 is wrong type
- platform: non_adr_0007
no_such_option: abc
option2: 123
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ homeassistant:
# This violates the non_adr_0007.iot_domain platform schema (no_such_option does not exist)
- platform: non_adr_0007
no_such_option: abc
option1: abc
pack_iot_domain_5:
iot_domain:
# This violates the non_adr_0007.iot_domain platform schema:
# - no_such_option does not exist
# - option1 is missing
# - option2 is wrong type
- platform: non_adr_0007
no_such_option: abc
option2: 123
pack_adr_0007_1:
# This is correct and should not generate errors
adr_0007_1:
Expand All @@ -36,3 +46,11 @@ homeassistant:
adr_0007_4:
host: blah.com
no_such_option: foo
pack_adr_0007_5:
# Multiple errors:
# - host is missing
# - no_such_option does not exist
# - port is wrong type
adr_0007_5:
no_such_option: foo
port: foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Multiple errors:
# - host is missing
# - no_such_option does not exist
# - port is wrong type
adr_0007_5:
no_such_option: foo
port: foo
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ iot_domain:
option1: 123
# This violates the non_adr_0007.iot_domain platform schema (no_such_option does not exist)
- platform: non_adr_0007
- no_such_option: abc
no_such_option: abc
option1: abc
# This violates the non_adr_0007.iot_domain platform schema:
# - no_such_option does not exist
# - option1 is missing
# - option2 is wrong type
- platform: non_adr_0007
no_such_option: abc
option2: 123
25 changes: 18 additions & 7 deletions tests/snapshots/test_config.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,63 @@
"Invalid config for [iot_domain] at <BASE_PATH>/fixtures/core/config/component_validation/basic/configuration.yaml, line 6: required key not provided 'platform', got None.",
"Invalid config for [iot_domain.non_adr_0007] at <BASE_PATH>/fixtures/core/config/component_validation/basic/configuration.yaml, line 9: expected str for dictionary value 'option1', got 123.",
"Invalid config for [iot_domain.non_adr_0007] at <BASE_PATH>/fixtures/core/config/component_validation/basic/configuration.yaml, line 12: 'no_such_option' is an invalid option for [iot_domain.non_adr_0007], check: no_such_option",
"Invalid config for [adr_0007_2] at <BASE_PATH>/fixtures/core/config/component_validation/basic/configuration.yaml, line 19: required key not provided 'adr_0007_2->host', got None.",
"Invalid config for [adr_0007_3] at <BASE_PATH>/fixtures/core/config/component_validation/basic/configuration.yaml, line 24: expected int for dictionary value 'adr_0007_3->port', got 'foo'.",
"Invalid config for [adr_0007_4] at <BASE_PATH>/fixtures/core/config/component_validation/basic/configuration.yaml, line 29: 'no_such_option' is an invalid option for [adr_0007_4], check: adr_0007_4->no_such_option",
"Invalid config for [iot_domain.non_adr_0007] at <BASE_PATH>/fixtures/core/config/component_validation/basic/configuration.yaml, line 19: 'no_such_option' is an invalid option for [iot_domain.non_adr_0007], check: no_such_option",
"Invalid config for [adr_0007_2] at <BASE_PATH>/fixtures/core/config/component_validation/basic/configuration.yaml, line 27: required key not provided 'adr_0007_2->host', got None.",
"Invalid config for [adr_0007_3] at <BASE_PATH>/fixtures/core/config/component_validation/basic/configuration.yaml, line 32: expected int for dictionary value 'adr_0007_3->port', got 'foo'.",
"Invalid config for [adr_0007_4] at <BASE_PATH>/fixtures/core/config/component_validation/basic/configuration.yaml, line 37: 'no_such_option' is an invalid option for [adr_0007_4], check: adr_0007_4->no_such_option",
"Invalid config for [adr_0007_5] at <BASE_PATH>/fixtures/core/config/component_validation/basic/configuration.yaml, line 44: 'no_such_option' is an invalid option for [adr_0007_5], check: adr_0007_5->no_such_option",
])
# ---
# name: test_component_config_validation_error[basic_include]
list([
"Invalid config for [iot_domain] at <BASE_PATH>/fixtures/core/config/component_validation/basic_include/integrations/iot_domain.yaml, line 5: required key not provided 'platform', got None.",
"Invalid config for [iot_domain.non_adr_0007] at <BASE_PATH>/fixtures/core/config/component_validation/basic_include/integrations/iot_domain.yaml, line 8: expected str for dictionary value 'option1', got 123.",
"Invalid config for [iot_domain.non_adr_0007] at <BASE_PATH>/fixtures/core/config/component_validation/basic_include/integrations/iot_domain.yaml, line 11: 'no_such_option' is an invalid option for [iot_domain.non_adr_0007], check: no_such_option",
"Invalid config for [iot_domain.non_adr_0007] at <BASE_PATH>/fixtures/core/config/component_validation/basic_include/integrations/iot_domain.yaml, line 18: 'no_such_option' is an invalid option for [iot_domain.non_adr_0007], check: no_such_option",
"Invalid config for [adr_0007_2] at <BASE_PATH>/fixtures/core/config/component_validation/basic_include/configuration.yaml, line 3: required key not provided 'adr_0007_2->host', got None.",
"Invalid config for [adr_0007_3] at <BASE_PATH>/fixtures/core/config/component_validation/basic_include/integrations/adr_0007_3.yaml, line 3: expected int for dictionary value 'adr_0007_3->port', got 'foo'.",
"Invalid config for [adr_0007_4] at <BASE_PATH>/fixtures/core/config/component_validation/basic_include/integrations/adr_0007_4.yaml, line 3: 'no_such_option' is an invalid option for [adr_0007_4], check: adr_0007_4->no_such_option",
"Invalid config for [adr_0007_5] at <BASE_PATH>/fixtures/core/config/component_validation/basic_include/integrations/adr_0007_5.yaml, line 5: 'no_such_option' is an invalid option for [adr_0007_5], check: adr_0007_5->no_such_option",
])
# ---
# name: test_component_config_validation_error[include_dir_list]
list([
"Invalid config for [iot_domain] at <BASE_PATH>/fixtures/core/config/component_validation/include_dir_list/iot_domain/iot_domain_2.yaml, line 2: required key not provided 'platform', got None.",
"Invalid config for [iot_domain.non_adr_0007] at <BASE_PATH>/fixtures/core/config/component_validation/include_dir_list/iot_domain/iot_domain_3.yaml, line 3: expected str for dictionary value 'option1', got 123.",
"Invalid config for [iot_domain.non_adr_0007] at <BASE_PATH>/fixtures/core/config/component_validation/include_dir_list/iot_domain/iot_domain_4.yaml, line 3: 'no_such_option' is an invalid option for [iot_domain.non_adr_0007], check: no_such_option",
"Invalid config for [iot_domain.non_adr_0007] at <BASE_PATH>/fixtures/core/config/component_validation/include_dir_list/iot_domain/iot_domain_5.yaml, line 6: 'no_such_option' is an invalid option for [iot_domain.non_adr_0007], check: no_such_option",
])
# ---
# name: test_component_config_validation_error[include_dir_merge_list]
list([
"Invalid config for [iot_domain] at <BASE_PATH>/fixtures/core/config/component_validation/include_dir_merge_list/iot_domain/iot_domain_1.yaml, line 5: required key not provided 'platform', got None.",
"Invalid config for [iot_domain.non_adr_0007] at <BASE_PATH>/fixtures/core/config/component_validation/include_dir_merge_list/iot_domain/iot_domain_2.yaml, line 3: expected str for dictionary value 'option1', got 123.",
"Invalid config for [iot_domain.non_adr_0007] at <BASE_PATH>/fixtures/core/config/component_validation/include_dir_merge_list/iot_domain/iot_domain_2.yaml, line 6: 'no_such_option' is an invalid option for [iot_domain.non_adr_0007], check: no_such_option",
"Invalid config for [iot_domain.non_adr_0007] at <BASE_PATH>/fixtures/core/config/component_validation/include_dir_merge_list/iot_domain/iot_domain_2.yaml, line 13: 'no_such_option' is an invalid option for [iot_domain.non_adr_0007], check: no_such_option",
])
# ---
# name: test_component_config_validation_error[packages]
list([
"Invalid config for [iot_domain] at <BASE_PATH>/fixtures/core/config/component_validation/packages/configuration.yaml, line 11: required key not provided 'platform', got None.",
"Invalid config for [iot_domain.non_adr_0007] at <BASE_PATH>/fixtures/core/config/component_validation/packages/configuration.yaml, line 16: expected str for dictionary value 'option1', got 123.",
"Invalid config for [iot_domain.non_adr_0007] at <BASE_PATH>/fixtures/core/config/component_validation/packages/configuration.yaml, line 21: 'no_such_option' is an invalid option for [iot_domain.non_adr_0007], check: no_such_option",
"Invalid config for [adr_0007_2] at <BASE_PATH>/fixtures/core/config/component_validation/packages/configuration.yaml, line 28: required key not provided 'adr_0007_2->host', got None.",
"Invalid config for [adr_0007_3] at <BASE_PATH>/fixtures/core/config/component_validation/packages/configuration.yaml, line 33: expected int for dictionary value 'adr_0007_3->port', got 'foo'.",
"Invalid config for [adr_0007_4] at <BASE_PATH>/fixtures/core/config/component_validation/packages/configuration.yaml, line 38: 'no_such_option' is an invalid option for [adr_0007_4], check: adr_0007_4->no_such_option",
"Invalid config for [iot_domain.non_adr_0007] at <BASE_PATH>/fixtures/core/config/component_validation/packages/configuration.yaml, line 30: 'no_such_option' is an invalid option for [iot_domain.non_adr_0007], check: no_such_option",
"Invalid config for [adr_0007_2] at <BASE_PATH>/fixtures/core/config/component_validation/packages/configuration.yaml, line 38: required key not provided 'adr_0007_2->host', got None.",
"Invalid config for [adr_0007_3] at <BASE_PATH>/fixtures/core/config/component_validation/packages/configuration.yaml, line 43: expected int for dictionary value 'adr_0007_3->port', got 'foo'.",
"Invalid config for [adr_0007_4] at <BASE_PATH>/fixtures/core/config/component_validation/packages/configuration.yaml, line 48: 'no_such_option' is an invalid option for [adr_0007_4], check: adr_0007_4->no_such_option",
"Invalid config for [adr_0007_5] at <BASE_PATH>/fixtures/core/config/component_validation/packages/configuration.yaml, line 55: 'no_such_option' is an invalid option for [adr_0007_5], check: adr_0007_5->no_such_option",
])
# ---
# name: test_component_config_validation_error[packages_include_dir_named]
list([
"Invalid config for [iot_domain] at <BASE_PATH>/fixtures/core/config/component_validation/packages_include_dir_named/integrations/iot_domain.yaml, line 6: required key not provided 'platform', got None.",
"Invalid config for [iot_domain.non_adr_0007] at <BASE_PATH>/fixtures/core/config/component_validation/packages_include_dir_named/integrations/iot_domain.yaml, line 9: expected str for dictionary value 'option1', got 123.",
"Invalid config for [iot_domain] at <BASE_PATH>/fixtures/core/config/component_validation/packages_include_dir_named/integrations/iot_domain.yaml, line 12: required key not provided 'platform', got None.",
"Invalid config for [iot_domain.non_adr_0007] at <BASE_PATH>/fixtures/core/config/component_validation/packages_include_dir_named/integrations/iot_domain.yaml, line 12: 'no_such_option' is an invalid option for [iot_domain.non_adr_0007], check: no_such_option",
"Invalid config for [iot_domain.non_adr_0007] at <BASE_PATH>/fixtures/core/config/component_validation/packages_include_dir_named/integrations/iot_domain.yaml, line 19: 'no_such_option' is an invalid option for [iot_domain.non_adr_0007], check: no_such_option",
"Invalid config for [adr_0007_2] at <BASE_PATH>/fixtures/core/config/component_validation/packages_include_dir_named/integrations/adr_0007_2.yaml, line 2: required key not provided 'adr_0007_2->host', got None.",
"Invalid config for [adr_0007_3] at <BASE_PATH>/fixtures/core/config/component_validation/packages_include_dir_named/integrations/adr_0007_3.yaml, line 4: expected int for dictionary value 'adr_0007_3->port', got 'foo'.",
"Invalid config for [adr_0007_4] at <BASE_PATH>/fixtures/core/config/component_validation/packages_include_dir_named/integrations/adr_0007_4.yaml, line 4: 'no_such_option' is an invalid option for [adr_0007_4], check: adr_0007_4->no_such_option",
"Invalid config for [adr_0007_5] at <BASE_PATH>/fixtures/core/config/component_validation/packages_include_dir_named/integrations/adr_0007_5.yaml, line 6: 'no_such_option' is an invalid option for [adr_0007_5], check: adr_0007_5->no_such_option",
])
# ---
# name: test_package_merge_error[packages]
Expand Down
13 changes: 11 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ async def mock_non_adr_0007_integration(hass) -> None:
configuration key
"""

test_platform_schema = IOT_DOMAIN_PLATFORM_SCHEMA.extend({"option1": str})
test_platform_schema = IOT_DOMAIN_PLATFORM_SCHEMA.extend(
{vol.Required("option1"): str, vol.Optional("option2"): str}
)
mock_platform(
hass,
"non_adr_0007.iot_domain",
Expand All @@ -133,7 +135,13 @@ async def mock_non_adr_0007_integration(hass) -> None:
async def mock_adr_0007_integrations(hass) -> list[Integration]:
"""Mock ADR-0007 compliant integrations."""
integrations = []
for domain in ["adr_0007_1", "adr_0007_2", "adr_0007_3", "adr_0007_4"]:
for domain in [
"adr_0007_1",
"adr_0007_2",
"adr_0007_3",
"adr_0007_4",
"adr_0007_5",
]:
adr_0007_config_schema = vol.Schema(
{
domain: vol.Schema(
Expand Down Expand Up @@ -1504,6 +1512,7 @@ async def test_component_config_validation_error(
"adr_0007_2",
"adr_0007_3",
"adr_0007_4",
"adr_0007_5",
]:
integration = await async_get_integration(hass, domain)
await config_util.async_process_component_config(
Expand Down

0 comments on commit 381ebf3

Please sign in to comment.