Bugfix group order (#3323)
* Add ordered dict config validator * Have group component use ordered dict config validator * Improve config_validation testing * update doc string config_validation.ordered_dict * validate full dict entries * Further simplify ordered_dict validator. * Lint fix
This commit is contained in:
parent
fa4b253871
commit
838b09bb8f
4 changed files with 84 additions and 9 deletions
|
@ -1,4 +1,5 @@
|
|||
"""Helpers for config validation using voluptuous."""
|
||||
from collections import OrderedDict
|
||||
from datetime import timedelta
|
||||
import os
|
||||
from urllib.parse import urlparse
|
||||
|
@ -290,6 +291,27 @@ def url(value: Any) -> str:
|
|||
raise vol.Invalid('invalid url')
|
||||
|
||||
|
||||
def ordered_dict(value_validator, key_validator=match_all):
|
||||
"""Validate an ordered dict validator that maintains ordering.
|
||||
|
||||
value_validator will be applied to each value of the dictionary.
|
||||
key_validator (optional) will be applied to each key of the dictionary.
|
||||
"""
|
||||
item_validator = vol.Schema({key_validator: value_validator})
|
||||
|
||||
def validator(value):
|
||||
"""Validate ordered dict."""
|
||||
config = OrderedDict()
|
||||
|
||||
for key, val in value.items():
|
||||
v_res = item_validator({key: val})
|
||||
config.update(v_res)
|
||||
|
||||
return config
|
||||
|
||||
return validator
|
||||
|
||||
|
||||
# Validator helpers
|
||||
|
||||
def key_dependency(key, dependency):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue