From 3e2d33f1d5be178b3e3be4295310d608b4bec0de Mon Sep 17 00:00:00 2001 From: LtWorf Date: Thu, 23 Dec 2010 10:11:14 +0000 Subject: [PATCH] - Added tests - Driver can test on pure python code git-svn-id: http://galileo.dmi.unict.it/svn/relational/trunk@266 014f5005-505e-4b48-8d0a-63407b615a7c --- test/driver.py | 66 ++++++++++++++++++++++++++++++++++---- test/maxdate.query | 1 + test/maxdate.result | 2 ++ test/rename_insert1.exec | 7 ++++ test/rename_insert1.result | 1 + test/rename_insert2.exec | 7 ++++ test/rename_insert2.result | 1 + test/union4.query | 1 + test/union4.result | 9 ++++++ 9 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 test/maxdate.query create mode 100644 test/maxdate.result create mode 100644 test/rename_insert1.exec create mode 100644 test/rename_insert1.result create mode 100644 test/rename_insert2.exec create mode 100644 test/rename_insert2.result create mode 100644 test/union4.query create mode 100644 test/union4.result diff --git a/test/driver.py b/test/driver.py index 5114905..d8e3ea4 100644 --- a/test/driver.py +++ b/test/driver.py @@ -59,6 +59,9 @@ def execute_tests(): q_bad=0 q_good=0 q_tot=0 + ex_bad=0 + ex_good=0 + ex_tot=0 for i in os.listdir(tests_path): @@ -74,6 +77,12 @@ def execute_tests(): py_good+=1 else: py_bad+=1 + elif i.endswith('.exec'): + ex_tot+=1 + if run_exec_test(i[:-5]): + ex_good+=1 + else: + ex_bad+=1 print "\n\033[36;1mResume of the results\033[0m" print "\n\033[35;1mQuery tests\033[0m" @@ -88,17 +97,62 @@ def execute_tests(): if py_bad>0: print "\033[31;1mFailed tests count: %d\033[0m" % py_bad - print "\n\033[36;1mTotal results\033[0m" - if q_bad+py_bad==0: - print "\033[32;1mNo failed tests\033[0m" - else: - print "\033[31;1mThere are %d failed tests\033[0m" % (py_bad+q_bad) + print "\n\033[35;1mExecute Python tests\033[0m" + print "Total test count: %d" % ex_tot + print "Passed tests: %d" % ex_good + if ex_bad>0: + print "\033[31;1mFailed tests count: %d\033[0m" % ex_bad -def run_py_test(testname): + print "\n\033[36;1mTotal results\033[0m" + if q_bad+py_bad+ex_bad==0: + print "\033[32;1mNo failed tests\033[0m" + else: + print "\033[31;1mThere are %d failed tests\033[0m" % (py_bad+q_bad+ex_bad) + + +def run_exec_test(testname): '''Runs a python test, which executes code directly rather than queries''' print "Running python test: \033[35;1m%s\033[0m" % testname + glob=rels.copy() + exp_result={} + + try: + + expr=readfile('%s%s.exec' % (tests_path,testname)) + exec(expr,glob) #Evaluating the expression + + expr=readfile('%s%s.exec' % (tests_path,testname)) + exec(expr,glob) #Evaluating the expression + + + expr=readfile('%s%s.result' % (tests_path,testname)) + exp_result=eval(expr,rels) #Evaluating the expression + + + if isinstance(exp_result,dict): + fields_ok=True + + for i in exp_result: + fields_ok = fields_ok and glob[i]==exp_result[i] + + if fields_ok: + print "\033[32;1mTest passed\033[0m" + return True + except: + pass + print "\033[31;1mERROR\033[0m" + 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_py_test(testname): + '''Runs a python test, which evaluates expressions directly rather than queries''' + print "Running expression python test: \033[35;1m%s\033[0m" % testname + try: expr=readfile('%s%s.python' % (tests_path,testname)) diff --git a/test/maxdate.query b/test/maxdate.query new file mode 100644 index 0000000..5bd2be4 --- /dev/null +++ b/test/maxdate.query @@ -0,0 +1 @@ +dates-πdate(σ d>date (ρdate➡d(dates)*dates)) diff --git a/test/maxdate.result b/test/maxdate.result new file mode 100644 index 0000000..bde2e23 --- /dev/null +++ b/test/maxdate.result @@ -0,0 +1,2 @@ +date +2008-12-12 diff --git a/test/rename_insert1.exec b/test/rename_insert1.exec new file mode 100644 index 0000000..14cb5ca --- /dev/null +++ b/test/rename_insert1.exec @@ -0,0 +1,7 @@ +p1=people.rename({"id":"ido"}) +people.insert((123,"lala",0,31)) + +print p1 +print people +retval=people==p1 +people.delete("id==123") diff --git a/test/rename_insert1.result b/test/rename_insert1.result new file mode 100644 index 0000000..b6285aa --- /dev/null +++ b/test/rename_insert1.result @@ -0,0 +1 @@ +{'retval':False} diff --git a/test/rename_insert2.exec b/test/rename_insert2.exec new file mode 100644 index 0000000..ec0ed70 --- /dev/null +++ b/test/rename_insert2.exec @@ -0,0 +1,7 @@ +p1=people.rename({"id":"ido"}) +p1.insert((123,"lala",0,31)) + +print p1 +print people +retval=people==p1 +people.delete("id==123") diff --git a/test/rename_insert2.result b/test/rename_insert2.result new file mode 100644 index 0000000..b6285aa --- /dev/null +++ b/test/rename_insert2.result @@ -0,0 +1 @@ +{'retval':False} diff --git a/test/union4.query b/test/union4.query new file mode 100644 index 0000000..e67c0f5 --- /dev/null +++ b/test/union4.query @@ -0,0 +1 @@ +people ᑌ people ᑎ people diff --git a/test/union4.result b/test/union4.result new file mode 100644 index 0000000..7081477 --- /dev/null +++ b/test/union4.result @@ -0,0 +1,9 @@ +id,name,chief,age +0,jack,0,22 +1,carl,0,20 +2,john,1,30 +3,dean,1,33 +4,eve,0,25 +5,duncan,4,30 +6,paul,4,30 +7,alia,1,28