Change in vdsm[master]: Allow tobool() convert int into bool.

wudxw at linux.vnet.ibm.com wudxw at linux.vnet.ibm.com
Thu Oct 11 03:22:23 UTC 2012


Mark Wu has uploaded a new change for review.

Change subject: Allow tobool() convert int into bool.
......................................................................

Allow tobool() convert int into bool.

The original code return False for any number. This patch makes
it return the result of bool(number). That means for any nonzero nubmer
it returns True, and returns False for 0.

This patch also adds a test case for tobool().

Change-Id: I6ae878b1171fe6827441751d6f02167e12e8bc03
Signed-off-by: Mark Wu <wudxw at linux.vnet.ibm.com>
---
M tests/Makefile.am
A tests/utilsTests.py
M vdsm/utils.py
3 files changed, 39 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/80/8480/1

diff --git a/tests/Makefile.am b/tests/Makefile.am
index a5e4c64..eb21f25 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -42,12 +42,13 @@
 	parted_utils_tests.py \
 	permutationTests.py \
 	persistentDictTests.py \
-	restTests.py \
-	restData.py \
-	tcTests.py \
-	vdsClientTests.py \
 	remoteFileHandlerTests.py \
-	resourceManagerTests.py
+	resourceManagerTests.py \
+	restData.py \
+	restTests.py \
+	tcTests.py \
+	utilsTests.py \
+	vdsClientTests.py
 
 dist_noinst_DATA = \
 	run_tests_local.sh
diff --git a/tests/utilsTests.py b/tests/utilsTests.py
new file mode 100644
index 0000000..01d8de0
--- /dev/null
+++ b/tests/utilsTests.py
@@ -0,0 +1,32 @@
+#
+# Copyright IBM Corp. 2012
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+from vdsm import utils
+from testrunner import VdsmTestCase as TestCaseBase
+
+
+class TestUtils(TestCaseBase):
+
+    def test_tobool(self):
+        self.assertEqual(utils.tobool('true'), True)
+        self.assertEqual(utils.tobool('false'), False)
+        self.assertEqual(utils.tobool('foo'), False)
+        self.assertEqual(utils.tobool(None), False)
+        self.assertEqual(utils.tobool(0), False)
+        self.assertEqual(utils.tobool(1), True)
diff --git a/vdsm/utils.py b/vdsm/utils.py
index 0dbb342..96aa928 100644
--- a/vdsm/utils.py
+++ b/vdsm/utils.py
@@ -657,7 +657,7 @@
             return False
         if type(s) == bool:
             return s
-        if s.lower() == 'true':
+        if type(s) == str and s.lower() == 'true':
             return True
         return bool(int(s))
     except:


--
To view, visit http://gerrit.ovirt.org/8480
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6ae878b1171fe6827441751d6f02167e12e8bc03
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Mark Wu <wudxw at linux.vnet.ibm.com>


More information about the vdsm-patches mailing list