Merge "If 'bool_from_string' provided a boolean just return it"
This commit is contained in:
commit
b644e2b27b
@ -119,6 +119,8 @@ def bool_from_string(subject, strict=False, default=False):
|
||||
ValueError which is useful when parsing values passed in from an API call.
|
||||
Strings yielding False are 'f', 'false', 'off', 'n', 'no', or '0'.
|
||||
"""
|
||||
if isinstance(subject, bool):
|
||||
return subject
|
||||
if not isinstance(subject, six.string_types):
|
||||
subject = six.text_type(subject)
|
||||
|
||||
|
@ -30,6 +30,12 @@ load_tests = testscenarios.load_tests_apply_scenarios
|
||||
|
||||
class StrUtilsTest(test_base.BaseTestCase):
|
||||
|
||||
@mock.patch("six.text_type")
|
||||
def test_bool_bool_from_string_no_text(self, mock_text):
|
||||
self.assertTrue(strutils.bool_from_string(True))
|
||||
self.assertFalse(strutils.bool_from_string(False))
|
||||
self.assertEqual(0, mock_text.call_count)
|
||||
|
||||
def test_bool_bool_from_string(self):
|
||||
self.assertTrue(strutils.bool_from_string(True))
|
||||
self.assertFalse(strutils.bool_from_string(False))
|
||||
|
Loading…
Reference in New Issue
Block a user