diff --git a/test/driver.py b/driver.py old mode 100644 new mode 100755 similarity index 95% rename from test/driver.py rename to driver.py index ba8f14d..be6549b --- a/test/driver.py +++ b/driver.py @@ -193,17 +193,19 @@ def run_test(testname): try: result_rel=relation.relation('%s%s.result' % (tests_path,testname)) - query=readfile('%s%s.query' % (tests_path,testname)).strip() + query=unicode(readfile('%s%s.query' % (tests_path,testname)).strip(),'utf8') o_query=optimizer.optimize_all(query,rels) - expr=parser.parse(query)#Converting expression to python code + expr=parser.parse(query)#Converting expression to python string result=eval(expr,rels) #Evaluating the expression - o_expr=parser.parse(o_query)#Converting expression to python code + o_expr=parser.parse(o_query)#Converting expression to python string o_result=eval(o_expr,rels) #Evaluating the expression + + c_expr=parser.tree(query).toCode() #Converting to python code + c_result=eval(c_expr,rels) - - if (o_result==result_rel) and (result==result_rel): + if (o_result==result_rel) and (result==result_rel) and (c_result==result_rel): print colored('Test passed','green') return True except Exception as inst: diff --git a/relational/parser.py b/relational/parser.py index 35020a3..ae2627d 100644 --- a/relational/parser.py +++ b/relational/parser.py @@ -144,9 +144,14 @@ class node (object): return raise ParserException(u"Unable to parse tokens") pass + def toCode(self): + '''This method converts the tree into a python code object''' + code = self.toPython() + return compile(code,'','eval') + def toPython(self): - '''This method converts the expression into python code, which will require the - relation module to be executed.''' + '''This method converts the expression into a python code string, which + will require the relation module to be executed.''' if self.name in b_operators: return '%s.%s(%s)' % (self.left.toPython(),op_functions[self.name],self.right.toPython()) elif self.name in u_operators: