Case insensitive check for boolean validation

This commit is contained in:
cyprien-g
2015-12-28 16:18:49 +01:00
parent 7e67011fc5
commit 754c250f7e
2 changed files with 4 additions and 2 deletions

View File

@@ -131,9 +131,9 @@ def boolean(s):
>>> boolean('false')
False
'''
if s in ['true', 'True']:
if s.lower() == 'true':
return True
elif s in ['false', 'False']:
elif s.lower() == 'false':
return False
else:
raise ValueError('Invalid boolean value')

View File

@@ -34,8 +34,10 @@ def test_get_function_from_name_for_class_method():
def test_boolean():
assert utils.boolean('true')
assert utils.boolean('True')
assert utils.boolean('TRUE')
assert not utils.boolean('false')
assert not utils.boolean('False')
assert not utils.boolean('FALSE')
with pytest.raises(ValueError):
utils.boolean('foo')