mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Add case insensitive testing to boolean string validation.
This commit is contained in:
parent
eb415d7b96
commit
cbe9a7d2a3
@ -23,6 +23,7 @@ longitude = vol.All(vol.Coerce(float), vol.Range(min=-180, max=180),
|
|||||||
def boolean(value):
|
def boolean(value):
|
||||||
"""Validate and coerce a boolean value."""
|
"""Validate and coerce a boolean value."""
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
|
value = value.lower()
|
||||||
if value in ('1', 'true', 'yes', 'on', 'enable'):
|
if value in ('1', 'true', 'yes', 'on', 'enable'):
|
||||||
return True
|
return True
|
||||||
if value in ('0', 'false', 'no', 'off', 'disable'):
|
if value in ('0', 'false', 'no', 'off', 'disable'):
|
||||||
|
@ -4,6 +4,21 @@ import voluptuous as vol
|
|||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
|
|
||||||
|
def test_boolean():
|
||||||
|
"""Test boolean validation."""
|
||||||
|
schema = vol.Schema(cv.boolean)
|
||||||
|
|
||||||
|
for value in ('T', 'negative', 'lock'):
|
||||||
|
with pytest.raises(vol.MultipleInvalid):
|
||||||
|
schema(value)
|
||||||
|
|
||||||
|
for value in ('true', 'On', '1', 'YES', 'enable', 1, True):
|
||||||
|
assert schema(value)
|
||||||
|
|
||||||
|
for value in ('false', 'Off', '0', 'NO', 'disable', 0, False):
|
||||||
|
assert not schema(value)
|
||||||
|
|
||||||
|
|
||||||
def test_latitude():
|
def test_latitude():
|
||||||
"""Test latitude validation."""
|
"""Test latitude validation."""
|
||||||
schema = vol.Schema(cv.latitude)
|
schema = vol.Schema(cv.latitude)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user