* Person schema for merge_packages #21307 * empty list * skip empty persons * hound * test schema * ensure_none * remove any test changes * remove_falsy validator * nice! * coretests
This commit is contained in:
parent
5613e8bb60
commit
3453d67cfe
4 changed files with 19 additions and 8 deletions
|
@ -50,7 +50,8 @@ PERSON_SCHEMA = vol.Schema({
|
|||
})
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
vol.Optional(DOMAIN): vol.Any(vol.All(cv.ensure_list, [PERSON_SCHEMA]), {})
|
||||
vol.Optional(DOMAIN): vol.All(
|
||||
cv.ensure_list, cv.remove_falsy, [PERSON_SCHEMA])
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
_UNDEF = object()
|
||||
|
|
|
@ -349,6 +349,11 @@ def positive_timedelta(value: timedelta) -> timedelta:
|
|||
return value
|
||||
|
||||
|
||||
def remove_falsy(value: Sequence[T]) -> Sequence[T]:
|
||||
"""Remove falsy values from a list."""
|
||||
return [v for v in value if v]
|
||||
|
||||
|
||||
def service(value):
|
||||
"""Validate service."""
|
||||
# Services use same format as entities so we can use same helper.
|
||||
|
|
|
@ -48,7 +48,7 @@ def main():
|
|||
|
||||
schema_type, schema = _identify_config_schema(module)
|
||||
|
||||
add_msg("CONFIG_SCHEMA " + schema_type, module_name + ' ' +
|
||||
add_msg("CONFIG_SCHEMA " + str(schema_type), module_name + ' ' +
|
||||
color('cyan', str(schema)[:60]))
|
||||
|
||||
for key in sorted(msg):
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
"""Test config validators."""
|
||||
from datetime import timedelta, datetime, date
|
||||
from datetime import date, datetime, timedelta
|
||||
import enum
|
||||
import os
|
||||
from socket import _GLOBAL_DEFAULT_TIMEOUT
|
||||
from unittest.mock import Mock, patch
|
||||
import uuid
|
||||
|
||||
import homeassistant
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
|
||||
|
@ -291,6 +291,11 @@ def test_time_period():
|
|||
assert -1 * timedelta(hours=1, minutes=15) == schema('-1:15')
|
||||
|
||||
|
||||
def test_remove_falsy():
|
||||
"""Test remove falsy."""
|
||||
assert cv.remove_falsy([0, None, 1, "1", {}, [], ""]) == [1, "1"]
|
||||
|
||||
|
||||
def test_service():
|
||||
"""Test service validation."""
|
||||
schema = vol.Schema(cv.service)
|
||||
|
@ -908,7 +913,7 @@ def test_matches_regex():
|
|||
schema(" nrtd ")
|
||||
|
||||
test_str = "This is a test including uiae."
|
||||
assert (schema(test_str) == test_str)
|
||||
assert schema(test_str) == test_str
|
||||
|
||||
|
||||
def test_is_regex():
|
||||
|
@ -982,6 +987,6 @@ def test_uuid4_hex(caplog):
|
|||
# the 17th char should be 8-a
|
||||
schema('a03d31b22eee4acc7b90eec40be6ed23')
|
||||
|
||||
hex = uuid.uuid4().hex
|
||||
assert schema(hex) == hex
|
||||
assert schema(hex.upper()) == hex
|
||||
_hex = uuid.uuid4().hex
|
||||
assert schema(_hex) == _hex
|
||||
assert schema(_hex.upper()) == _hex
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue