[R] dataimport: refine error detection stable
authorJulien Jehannet <julien.jehannet@logilab.fr>
Wed, 17 Feb 2010 10:39:35 +0100
branchstable
changeset 4613 141a4f613f8a
parent 4612 d6ae30c5d055
child 4614 95ccd84c892b
[R] dataimport: refine error detection Consider only None as non-expected value after parsing the input file. False is now allowed because of the boolean yesno checker that returns False by default.
devtools/dataimport.py
--- a/devtools/dataimport.py	Wed Feb 17 13:23:36 2010 +0100
+++ b/devtools/dataimport.py	Wed Feb 17 10:39:35 2010 +0100
@@ -134,7 +134,7 @@
         try:
             for func in funcs:
                 res[dest] = func(res[dest])
-            if res[dest] is None or res[dest]==False:
+            if res[dest] is None:
                 raise AssertionError('undetermined value')
         except AssertionError, err:
             if optional in funcs:
@@ -220,7 +220,26 @@
     return txt.strip()
 
 def yesno(value):
-    return value.lower()[0] in 'yo1'
+    """simple heuristic that returns boolean value
+
+    >>> yesno("Yes")
+    True
+    >>> yesno("oui")
+    True
+    >>> yesno("1")
+    True
+    >>> yesno("11")
+    True
+    >>> yesno("")
+    False
+    >>> yesno("Non")
+    False
+    >>> yesno("blablabla")
+    False
+    """
+    if value:
+        return value.lower()[0] in 'yo1'
+    return False
 
 def isalpha(value):
     if value.isalpha():