mirror of
https://github.com/datafolklabs/cement.git
synced 2026-02-06 11:37:06 +00:00
parent
59e9ce0ca4
commit
2f53a1ff19
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user