[PATCH 2/2] Add tests for the returns bool decorator

Martin Kolman mkolman at redhat.com
Wed Oct 23 15:33:40 UTC 2013


Signed-off-by: Martin Kolman <mkolman at redhat.com>
---
 tests/pyanaconda_tests/iutil_test.py | 42 +++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/tests/pyanaconda_tests/iutil_test.py b/tests/pyanaconda_tests/iutil_test.py
index aa1f6c0..3853a3f 100644
--- a/tests/pyanaconda_tests/iutil_test.py
+++ b/tests/pyanaconda_tests/iutil_test.py
@@ -16,7 +16,7 @@
 # Red Hat, Inc.
 #
 # Red Hat Author(s): Vratislav Podzimek <vpodzime at redhat.com>
-#
+#                    Martin Kolman <mkolman at redhat.com>
 
 from pyanaconda import iutil
 import unittest
@@ -39,3 +39,43 @@ class UpcaseFirstLetterTests(unittest.TestCase):
         # no lowercase
         self.assertEqual(iutil.upcase_first_letter("czech Republic"),
                          "Czech Republic")
+
+
+class DecoratorTests(unittest.TestCase):
+    """Test decorators provided by iutil"""
+
+    class TestClass(object):
+        pass
+
+    @iutil.returns_bool
+    def _return_input(self, input):
+        return input
+
+    # list of values that should convert to True
+    true_list = [True, "abc", u"abc", 1, 1.0, 1.1, 0.1, (1, 2, 3), [1, 2, 3],
+                 {"foo": "bar"}, set((1, 2)), iutil, TestClass,
+                 TestClass(), _return_input]
+
+    # list of values that should convert to False
+    false_list = [False, None, "", u"", 0, 0.0, (), [], {}, set()]
+
+    def returns_bool_test(self):
+        """Check if a bool instance is returned"""
+
+        for value in self.true_list:
+            self.assertIsInstance(self._return_input(value), bool)
+
+        for value in self.false_list:
+            self.assertIsInstance(self._return_input(value), bool)
+
+    def returns_true_test(self):
+        """Check if values are correctly converted to True"""
+
+        for value in self.true_list:
+            self.assertIs(self._return_input(value), True)
+
+    def returns_false_test(self):
+        """Check if values are correctly converted to False"""
+
+        for value in self.false_list:
+            self.assertIs(self._return_input(value), False)
-- 
1.8.3.1



More information about the anaconda-patches mailing list