- Added other tests

- Driver can handle exceptions



git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@255 014f5005-505e-4b48-8d0a-63407b615a7c
master
LtWorf 2010-10-04 12:46:18 +07:00
parent 48e6ecb7ba
commit 54d1301a96
7 changed files with 71 additions and 40 deletions

@ -96,22 +96,25 @@ def run_py_test(testname):
'''Runs a python test, which executes code directly rather than queries''' '''Runs a python test, which executes code directly rather than queries'''
print "Running python test: \033[35;1m%s\033[0m" % testname print "Running python test: \033[35;1m%s\033[0m" % testname
expr=readfile('%s%s.python' % (tests_path,testname)) try:
result=eval(expr,rels) #Evaluating the expression
expr=readfile('%s%s.result' % (tests_path,testname)) expr=readfile('%s%s.python' % (tests_path,testname))
exp_result=eval(expr,rels) #Evaluating the expression result=eval(expr,rels) #Evaluating the expression
if result==exp_result: expr=readfile('%s%s.result' % (tests_path,testname))
print "\033[32;1mTest passed\033[0m" exp_result=eval(expr,rels) #Evaluating the expression
return True
else: if result==exp_result:
print "\033[31;1mERROR\033[0m" print "\033[32;1mTest passed\033[0m"
print "\033[31;1m=====================================\033[0m" return True
print "Expected %s" % exp_result except:
print "Got %s" % result pass
print "\033[31;1m=====================================\033[0m" print "\033[31;1mERROR\033[0m"
return False print "\033[31;1m=====================================\033[0m"
print "Expected %s" % exp_result
print "Got %s" % result
print "\033[31;1m=====================================\033[0m"
return False
def run_test(testname): def run_test(testname):
'''Runs a specific test executing the file '''Runs a specific test executing the file
@ -121,36 +124,45 @@ def run_test(testname):
The query will be executed both unoptimized and The query will be executed both unoptimized and
optimized''' optimized'''
print "Running test: \033[35;1m%s\033[0m" % testname print "Running test: \033[35;1m%s\033[0m" % testname
result_rel=relation.relation('%s%s.result' % (tests_path,testname))
query=readfile('%s%s.query' % (tests_path,testname)).strip() query=None;expr=None;o_query=None;o_expr=None
o_query=optimizer.optimize_all(query,rels) result_rel=None
result=None
expr=parser.parse(query)#Converting expression to python code o_result=None
result=eval(expr,rels) #Evaluating the expression
o_expr=parser.parse(o_query)#Converting expression to python code
o_result=eval(o_expr,rels) #Evaluating the expression
if (o_result==result_rel) and (result==result_rel): try:
print "\033[32;1mTest passed\033[0m" result_rel=relation.relation('%s%s.result' % (tests_path,testname))
return True
else:
print "\033[31;1mERROR\033[0m"
print "Query: %s -> %s" % (query,expr)
print "Optimized query: %s -> %s" % (o_query,o_expr)
print "\033[31;1m=====================================\033[0m"
print "\033[33;1mExpected result\033[0m"
print result_rel
print "\033[33;1mResult\033[0m"
print result
print "\033[33;1mOptimized result\033[0m"
print o_result
print "\033[33;1mResult and optimized result match\033[0m", result==o_result
print "\033[31;1m=====================================\033[0m"
return False
query=readfile('%s%s.query' % (tests_path,testname)).strip()
o_query=optimizer.optimize_all(query,rels)
expr=parser.parse(query)#Converting expression to python code
result=eval(expr,rels) #Evaluating the expression
o_expr=parser.parse(o_query)#Converting expression to python code
o_result=eval(o_expr,rels) #Evaluating the expression
if (o_result==result_rel) and (result==result_rel):
print "\033[32;1mTest passed\033[0m"
return True
except:
pass
print "\033[31;1mERROR\033[0m"
print "Query: %s -> %s" % (query,expr)
print "Optimized query: %s -> %s" % (o_query,o_expr)
print "\033[31;1m=====================================\033[0m"
print "\033[33;1mExpected result\033[0m"
print result_rel
print "\033[33;1mResult\033[0m"
print result
print "\033[33;1mOptimized result\033[0m"
print o_result
print "\033[33;1moptimized result match\033[0m", result_rel==o_result
print "\033[33;1mresult match \033[0m", result==result_rel
print "\033[31;1m=====================================\033[0m"
return False
if __name__ == '__main__': if __name__ == '__main__':

@ -0,0 +1 @@
σ (len(name)==4)(peopleᐅᐊ skills)

@ -0,0 +1,12 @@
id,name,chief,age,skill
2,john,1,30,C
7,alia,1,28,C
1,carl,0,20,C++
2,john,1,30,PHP
7,alia,1,28,Python
3,dean,1,33,C++
7,alia,1,28,PHP
0,jack,0,22,Python
1,carl,0,20,Python
0,jack,0,22,C
1,carl,0,20,System Admin

@ -0,0 +1 @@
πname,phone(((πname,id(people)- π name,id(πid(σ i!=id and room==r(ρ id➡i,room➡r(person_room)*person_room)) ᐅᐊ people)) ᐅᐊ person_room) ᐅᐊ rooms)

@ -0,0 +1 @@
σ age<30and skill=='PHP' (people ᐅᐊ skills)

@ -0,0 +1,2 @@
id,name,chief,age,skill
7,alia,1,28,PHP