summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Kölker <jason@koelker.net>2011-12-01 17:54:11 -0600
committerJason Kölker <jason@koelker.net>2011-12-01 17:54:11 -0600
commita71658d1f62fcee63cf55cc6ef7a3f1a13bfee56 (patch)
tree81eeb54e79516b952b3693197d255f640038a79e
parent3bbeb69487c70aa9ebc7fa69c93d6e3544a3aa68 (diff)
downloadoslo-a71658d1f62fcee63cf55cc6ef7a3f1a13bfee56.tar.gz
oslo-a71658d1f62fcee63cf55cc6ef7a3f1a13bfee56.tar.xz
oslo-a71658d1f62fcee63cf55cc6ef7a3f1a13bfee56.zip
add utils test
-rw-r--r--tests/unit/test_utils.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
new file mode 100644
index 0000000..9a11007
--- /dev/null
+++ b/tests/unit/test_utils.py
@@ -0,0 +1,70 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2011 OpenStack LLC.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import unittest
+
+import mock
+
+from openstack.common import exception
+from openstack.common import utils
+
+
+class UtilsTest(unittest.TestCase):
+
+ def test_bool_bool_from_string(self):
+ self.assertTrue(utils.bool_from_string(True))
+ self.assertFalse(utils.bool_from_string(False))
+
+ def test_str_bool_from_string(self):
+ self.assertTrue(utils.bool_from_string('true'))
+ self.assertTrue(utils.bool_from_string('TRUE'))
+ self.assertTrue(utils.bool_from_string('on'))
+ self.assertTrue(utils.bool_from_string('on'))
+ self.assertTrue(utils.bool_from_string('1'))
+
+ self.assertFalse(utils.bool_from_string('false'))
+ self.assertFalse(utils.bool_from_string('FALSE'))
+ self.assertFalse(utils.bool_from_string('off'))
+ self.assertFalse(utils.bool_from_string('OFF'))
+ self.assertFalse(utils.bool_from_string('0'))
+ self.assertFalse(utils.bool_from_string('42'))
+ self.assertFalse(utils.bool_from_string('This should not be True'))
+
+ def test_unicode_bool_from_string(self):
+ self.assertTrue(utils.bool_from_string(u'true'))
+ self.assertTrue(utils.bool_from_string(u'TRUE'))
+ self.assertTrue(utils.bool_from_string(u'on'))
+ self.assertTrue(utils.bool_from_string(u'on'))
+ self.assertTrue(utils.bool_from_string(u'1'))
+
+ self.assertFalse(utils.bool_from_string(u'false'))
+ self.assertFalse(utils.bool_from_string(u'FALSE'))
+ self.assertFalse(utils.bool_from_string(u'off'))
+ self.assertFalse(utils.bool_from_string(u'OFF'))
+ self.assertFalse(utils.bool_from_string(u'0'))
+ self.assertFalse(utils.bool_from_string(u'42'))
+ self.assertFalse(utils.bool_from_string(u'This should not be True'))
+
+ def test_other_bool_from_string(self):
+ self.assertFalse(utils.bool_from_string(mock.Mock()))
+
+ def test_int_from_bool_as_string(self):
+ self.assertEqual(1, utils.int_from_bool_as_string(True))
+ self.assertEqual(0, utils.int_from_bool_as_string(False))
+
+ def test_execute_unknown_kwargs(self):
+ self.assertRaises(exception.Error, utils.execute, hozer=True)