Improve boolean validator (#24294)

* Improve boolean validator

* Remove extra throw

* Remove None test as discussed

* Fix for tests depending on None == False
This commit is contained in:
Penny Wood 2019-06-08 13:18:02 +08:00 committed by Paulus Schoutsen
parent 233bc1a108
commit b30f4b8fc0
5 changed files with 20 additions and 9 deletions

View file

@ -17,11 +17,14 @@ def test_boolean():
"""Test boolean validation."""
schema = vol.Schema(cv.boolean)
for value in ('T', 'negative', 'lock'):
for value in (
None, 'T', 'negative', 'lock', 'tr ue',
[], [1, 2], {'one': 'two'}, test_boolean):
with pytest.raises(vol.MultipleInvalid):
schema(value)
for value in ('true', 'On', '1', 'YES', 'enable', 1, True):
for value in ('true', 'On', '1', 'YES', ' true ',
'enable', 1, 50, True, 0.1):
assert schema(value)
for value in ('false', 'Off', '0', 'NO', 'disable', 0, False):