diff options
author | Russell Bryant <rbryant@redhat.com> | 2013-02-01 03:29:01 -0500 |
---|---|---|
committer | Russell Bryant <rbryant@redhat.com> | 2013-02-02 16:15:50 +0100 |
commit | 795d1bcfd13aae2d07f52a2a1a51117e78a234c8 (patch) | |
tree | 7e66664191212b54c13bcb38ee5aae5505de1d64 | |
parent | 35ba1f88dfdc5fbef7b6208b2b4d8178e3cfa1ac (diff) | |
download | nova-795d1bcfd13aae2d07f52a2a1a51117e78a234c8.tar.gz nova-795d1bcfd13aae2d07f52a2a1a51117e78a234c8.tar.xz nova-795d1bcfd13aae2d07f52a2a1a51117e78a234c8.zip |
Tweakify is_valid_boolstr().
This function used a few backslashes for continuation. According to
HACKING, we prefer to not use this. This code gets rid of them by
changing the way the checks are done.
Look at those backslashes ... sitting there at the end of the line.
It's like they're looking down on the code that precedes them, as if
they are somehow superior to the other characters. Banish them from
this utility function!
Also add a unit test for this code.
Part of greenprint bored-on-an-airplane.
Change-Id: If88b6e63ab078916ce1b9cf2f5e99623c402996c
-rw-r--r-- | nova/tests/test_utils.py | 13 | ||||
-rw-r--r-- | nova/utils.py | 7 |
2 files changed, 15 insertions, 5 deletions
diff --git a/nova/tests/test_utils.py b/nova/tests/test_utils.py index 84d56cadf..5c5c226f9 100644 --- a/nova/tests/test_utils.py +++ b/nova/tests/test_utils.py @@ -463,6 +463,19 @@ class GenericUtilsTestCase(test.TestCase): h2 = hashlib.sha1(data).hexdigest() self.assertEquals(h1, h2) + def test_is_valid_boolstr(self): + self.assertTrue(utils.is_valid_boolstr('true')) + self.assertTrue(utils.is_valid_boolstr('false')) + self.assertTrue(utils.is_valid_boolstr('yes')) + self.assertTrue(utils.is_valid_boolstr('no')) + self.assertTrue(utils.is_valid_boolstr('y')) + self.assertTrue(utils.is_valid_boolstr('n')) + self.assertTrue(utils.is_valid_boolstr('1')) + self.assertTrue(utils.is_valid_boolstr('0')) + + self.assertFalse(utils.is_valid_boolstr('maybe')) + self.assertFalse(utils.is_valid_boolstr('only on tuesdays')) + class MonkeyPatchTestCase(test.TestCase): """Unit test for utils.monkey_patch().""" diff --git a/nova/utils.py b/nova/utils.py index 83bf55583..be441bfcc 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -876,11 +876,8 @@ def is_int_like(val): def is_valid_boolstr(val): """Check if the provided string is a valid bool string or not.""" - val = str(val).lower() - return val == 'true' or val == 'false' or \ - val == 'yes' or val == 'no' or \ - val == 'y' or val == 'n' or \ - val == '1' or val == '0' + boolstrs = ('true', 'false', 'yes', 'no', 'y', 'n', '1', '0') + return str(val).lower() in boolstrs def is_valid_ipv4(address): |