[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.
--- 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():