- 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:
parent
436958f40e
commit
2e0cbf94a7
12
test/driver.py → driver.py
Normal file → Executable file
12
test/driver.py → driver.py
Normal file → Executable file
@ -193,17 +193,19 @@ def run_test(testname):
|
|||||||
try:
|
try:
|
||||||
result_rel=relation.relation('%s%s.result' % (tests_path,testname))
|
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)
|
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
|
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
|
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) and (c_result==result_rel):
|
||||||
if (o_result==result_rel) and (result==result_rel):
|
|
||||||
print colored('Test passed','green')
|
print colored('Test passed','green')
|
||||||
return True
|
return True
|
||||||
except Exception as inst:
|
except Exception as inst:
|
@ -144,9 +144,14 @@ class node (object):
|
|||||||
return
|
return
|
||||||
raise ParserException(u"Unable to parse tokens")
|
raise ParserException(u"Unable to parse tokens")
|
||||||
pass
|
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):
|
def toPython(self):
|
||||||
'''This method converts the expression into python code, which will require the
|
'''This method converts the expression into a python code string, which
|
||||||
relation module to be executed.'''
|
will require the relation module to be executed.'''
|
||||||
if self.name in b_operators:
|
if self.name in b_operators:
|
||||||
return '%s.%s(%s)' % (self.left.toPython(),op_functions[self.name],self.right.toPython())
|
return '%s.%s(%s)' % (self.left.toPython(),op_functions[self.name],self.right.toPython())
|
||||||
elif self.name in u_operators:
|
elif self.name in u_operators:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user