Support 'y' in utils.misc.is_true

- Partially resolves PR #542
This commit is contained in:
BJ Dierkes 2019-05-17 20:06:39 -05:00
parent 59e9ce0ca4
commit 2f53a1ff19
2 changed files with 6 additions and 3 deletions

View File

@ -174,8 +174,8 @@ def minimal_logger(namespace, debug=False):
def is_true(item):
"""
Given a value, determine if it is one of
``[True, 'true', 'yes', 'on', '1', 1,]`` (note: strings are converted to
lowercase before comparison).
``[True, 'true', 'yes', 'y', 'on', '1', 1,]`` (note: strings are converted
to lowercase before comparison).
Args:
item: The item to convert to a boolean.
@ -185,7 +185,8 @@ def is_true(item):
otherwise
"""
if isinstance(item, str) and item.lower() in ['true', 'yes', 'on', '1']:
tstrings = ['true', 'yes', 'y', 'on', '1']
if isinstance(item, str) and item.lower() in tstrings:
return True
elif isinstance(item, bool) and item is True:
return True

View File

@ -15,6 +15,7 @@ def test_is_true():
assert misc.is_true('TRUE')
assert misc.is_true('tRue')
assert misc.is_true('yes')
assert misc.is_true('y')
assert misc.is_true('on')
assert misc.is_true(True)
@ -26,6 +27,7 @@ def test_is_true():
assert not misc.is_true('FALSE')
assert not misc.is_true('fAlse')
assert not misc.is_true('no')
assert not misc.is_true('n')
assert not misc.is_true('off')
assert not misc.is_true(False)