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:
parent
78a2e63e14
commit
5073567757
44
driver.py
44
driver.py
@ -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,34 +130,18 @@ def run_exec_test(testname):
|
|||||||
glob = rels.copy()
|
glob = rels.copy()
|
||||||
exp_result = {}
|
exp_result = {}
|
||||||
|
|
||||||
|
expr = readfile('%s%s.py' % (tests_path, testname))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
expr = readfile('%s%s.exec' % (tests_path, testname))
|
exec(expr, glob) # Evaluating the expression
|
||||||
try:
|
print (colorize('Test passed', COLOR_GREEN))
|
||||||
exec(expr, glob) # Evaluating the expression
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print (e)
|
print (colorize('ERROR', COLOR_RED))
|
||||||
raise Exception("")
|
print (colorize('=====================================', COLOR_RED))
|
||||||
|
traceback.print_exc(file=sys.stdout)
|
||||||
expr = readfile('%s%s.result' % (tests_path, testname))
|
print (colorize('=====================================', COLOR_RED))
|
||||||
exp_result = eval(expr, rels) # Evaluating the expression
|
return False
|
||||||
|
|
||||||
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))
|
|
||||||
return True
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
print (colorize('ERROR', COLOR_RED))
|
|
||||||
print (colorize('=====================================', COLOR_RED))
|
|
||||||
print ("Expected %s" % exp_result)
|
|
||||||
# print ("Got %s" % glob)
|
|
||||||
print (colorize('=====================================', COLOR_RED))
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def run_py_test(testname):
|
def run_py_test(testname):
|
||||||
|
@ -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")
|
@ -1 +0,0 @@
|
|||||||
{'retval':False}
|
|
@ -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")
|
@ -1 +0,0 @@
|
|||||||
{'retval':False}
|
|
Loading…
x
Reference in New Issue
Block a user