Change how python tests are executed

Require them to have assert rather than testing the
result variables set.

This makes for way simpler code.

Now also prints stacktrace to know where the problem occurred.
This commit is contained in:
Salvo 'LtWorf' Tomaselli 2015-11-18 12:05:56 +01:00
parent 78a2e63e14
commit 5073567757
5 changed files with 17 additions and 35 deletions

View File

@ -19,6 +19,8 @@
import os import os
from sys import exit from sys import exit
import sys
import traceback
from relational import relation, parser, optimizer from relational import relation, parser, optimizer
from xtermcolor import colorize from xtermcolor import colorize
@ -85,9 +87,9 @@ def execute_tests():
py_good += 1 py_good += 1
else: else:
py_bad += 1 py_bad += 1
elif i.endswith('.exec'): elif i.endswith('.py'):
ex_tot += 1 ex_tot += 1
if run_exec_test(i[:-5]): if run_exec_test(i[:-3]):
ex_good += 1 ex_good += 1
else: else:
ex_bad += 1 ex_bad += 1
@ -128,32 +130,16 @@ def run_exec_test(testname):
glob = rels.copy() glob = rels.copy()
exp_result = {} exp_result = {}
try: expr = readfile('%s%s.py' % (tests_path, testname))
expr = readfile('%s%s.exec' % (tests_path, testname))
try: try:
exec(expr, glob) # Evaluating the expression exec(expr, glob) # Evaluating the expression
except Exception as e:
print (e)
raise Exception("")
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 (colorize('Test passed', COLOR_GREEN)) print (colorize('Test passed', COLOR_GREEN))
return True return True
except: except Exception as e:
pass
print (colorize('ERROR', COLOR_RED)) print (colorize('ERROR', COLOR_RED))
print (colorize('=====================================', COLOR_RED)) print (colorize('=====================================', COLOR_RED))
print ("Expected %s" % exp_result) traceback.print_exc(file=sys.stdout)
# print ("Got %s" % glob)
print (colorize('=====================================', COLOR_RED)) print (colorize('=====================================', COLOR_RED))
return False return False

View File

@ -1,5 +1,4 @@
p1=people.rename({"id":"ido"}) p1=people.rename({"id":"ido"})
people.insert((123,"lala",0,31)) people.insert((123,"lala",0,31))
assert people!=p1
retval=people==p1
people.delete("id==123") people.delete("id==123")

View File

@ -1 +0,0 @@
{'retval':False}

View File

@ -1,5 +1,4 @@
p1=people.rename({"id":"ido"}) p1=people.rename({"id":"ido"})
p1.insert((123,"lala",0,31)) p1.insert((123,"lala",0,31))
assert people!=p1
retval=people==p1
people.delete("id==123") people.delete("id==123")

View File

@ -1 +0,0 @@
{'retval':False}