- Added other tests
- Driver can handle exceptions git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@255 014f5005-505e-4b48-8d0a-63407b615a7c
This commit is contained in:
parent
48e6ecb7ba
commit
54d1301a96
@ -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__':
|
||||||
|
1
test/fixed_len_name.query
Normal file
1
test/fixed_len_name.query
Normal file
@ -0,0 +1 @@
|
|||||||
|
σ (len(name)==4)(peopleᐅᐊ skills)
|
12
test/fixed_len_name.result
Normal file
12
test/fixed_len_name.result
Normal file
@ -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
|
1
test/phones_of_people_with_personal_room.query
Normal file
1
test/phones_of_people_with_personal_room.query
Normal file
@ -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)
|
2
test/phones_of_people_with_personal_room.result
Normal file
2
test/phones_of_people_with_personal_room.result
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
phone,name
|
||||||
|
1041,carl
|
1
test/php.query
Normal file
1
test/php.query
Normal file
@ -0,0 +1 @@
|
|||||||
|
σ age<30and skill=='PHP' (people ᐅᐊ skills)
|
2
test/php.result
Normal file
2
test/php.result
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
id,name,chief,age,skill
|
||||||
|
7,alia,1,28,PHP
|
Loading…
x
Reference in New Issue
Block a user