Przeglądaj źródła

Added a test for the check data functionnality of the Boolean datahandler

Roland Haroutiounian 8 lat temu
rodzic
commit
ae3335deb8

+ 3
- 2
lodel/leapi/datahandlers/datas_base.py Wyświetl plik

@@ -13,13 +13,14 @@ class Boolean(DataField):
13 13
     ##@brief A boolean field
14 14
     def __init__(self, **kwargs):
15 15
         if 'check_data_value' not in kwargs:
16
-            kwargs['check_data_value'] = self.check_value
16
+            kwargs['check_data_value'] = self.check_data_value
17 17
         super().__init__(ftype='bool', **kwargs)
18 18
 
19 19
     def _check_data_value(self, value):
20 20
         error = None
21 21
         try:
22
-            value = bool(value)
22
+            if type(value) != bool:
23
+                raise TypeError()
23 24
         except(ValueError, TypeError):
24 25
             error = TypeError("The value '%s' is not, and will never, be a boolean" % value)
25 26
         return value, error

+ 19
- 0
tests/datahandlers/test_boolean.py Wyświetl plik

@@ -0,0 +1,19 @@
1
+import unittest
2
+
3
+from lodel.leapi.datahandlers.datas import Boolean
4
+
5
+
6
+class BooleanTestCase(unittest.TestCase):
7
+
8
+    def test_boolean_check_data_value(self):
9
+        test_boolean = Boolean()
10
+
11
+        # correct values
12
+        for test_value in [True, False]:
13
+            value, error = test_boolean._check_data_value(test_value)
14
+            self.assertIsNone(error)
15
+
16
+        # incorrect values
17
+        for test_value in ['ok', 'True', 'False']:
18
+            value, error = test_boolean._check_data_value(test_value)
19
+            self.assertIsNotNone(error)

Loading…
Anuluj
Zapisz