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:
1 parent
a6673f6741
commit
287f9c9bda
4 files changed
+84
-9
No files matched your search
@@ -1,3 +1,5 @@
|
||||
"""Test config validators."""
|
||||
from collections import OrderedDict
|
||||
from datetime import timedelta
|
||||
import os
|
||||
import tempfile
|
||||
@@ -367,3 +369,51 @@ def test_has_at_least_one_key():
|
||||
|
||||
for value in ({'beer': None}, {'soda': None}):
|
||||
schema(value)
|
||||
|
||||
|
||||
def test_ordered_dict_order():
|
||||
"""Test ordered_dict validator."""
|
||||
schema = vol.Schema(cv.ordered_dict(int, cv.string))
|
||||
|
||||
val = OrderedDict()
|
||||
val['first'] = 1
|
||||
val['second'] = 2
|
||||
|
||||
validated = schema(val)
|
||||
|
||||
assert isinstance(validated, OrderedDict)
|
||||
assert ['first', 'second'] == list(validated.keys())
|
||||
|
||||
|
||||
def test_ordered_dict_key_validator():
|
||||
"""Test ordered_dict key validator."""
|
||||
schema = vol.Schema(cv.ordered_dict(cv.match_all, cv.string))
|
||||
|
||||
with pytest.raises(vol.Invalid):
|
||||
schema({None: 1})
|
||||
|
||||
schema({'hello': 'world'})
|
||||
|
||||
schema = vol.Schema(cv.ordered_dict(cv.match_all, int))
|
||||
|
||||
with pytest.raises(vol.Invalid):
|
||||
schema({'hello': 1})
|
||||
|
||||
schema({1: 'works'})
|
||||
|
||||
|
||||
def test_ordered_dict_value_validator():
|
||||
"""Test ordered_dict validator."""
|
||||
schema = vol.Schema(cv.ordered_dict(cv.string))
|
||||
|
||||
with pytest.raises(vol.Invalid):
|
||||
schema({'hello': None})
|
||||
|
||||
schema({'hello': 'world'})
|
||||
|
||||
schema = vol.Schema(cv.ordered_dict(int))
|
||||
|
||||
with pytest.raises(vol.Invalid):
|
||||
schema({'hello': 'world'})
|
||||
|
||||
schema({'hello': 5})
|
||||
Reference in new issue
Block a user