- Can convert the expressions into python code objects as well

- Can test that the code objects work as expected too.
This commit is contained in:
Salvo 'LtWorf' Tomaselli 2013-02-10 14:11:26 +01:00
parent 436958f40e
commit 2e0cbf94a7
2 changed files with 14 additions and 7 deletions

12
test/driver.py → driver.py Normal file → Executable file
View File

@ -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:

View File

@ -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,'<relational_expression>','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: