From 5073567757487f39d24f3cdf428403968d78eec0 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Wed, 18 Nov 2015 12:05:56 +0100 Subject: [PATCH] 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. --- driver.py | 44 +++++++------------ ...{rename_insert1.exec => rename_insert1.py} | 3 +- test/rename_insert1.result | 1 - ...{rename_insert2.exec => rename_insert2.py} | 3 +- test/rename_insert2.result | 1 - 5 files changed, 17 insertions(+), 35 deletions(-) rename test/{rename_insert1.exec => rename_insert1.py} (82%) delete mode 100644 test/rename_insert1.result rename test/{rename_insert2.exec => rename_insert2.py} (81%) delete mode 100644 test/rename_insert2.result diff --git a/driver.py b/driver.py index ab70df7..25fc6b8 100755 --- a/driver.py +++ b/driver.py @@ -19,6 +19,8 @@ import os from sys import exit +import sys +import traceback from relational import relation, parser, optimizer from xtermcolor import colorize @@ -85,9 +87,9 @@ def execute_tests(): py_good += 1 else: py_bad += 1 - elif i.endswith('.exec'): + elif i.endswith('.py'): ex_tot += 1 - if run_exec_test(i[:-5]): + if run_exec_test(i[:-3]): ex_good += 1 else: ex_bad += 1 @@ -128,34 +130,18 @@ def run_exec_test(testname): glob = rels.copy() exp_result = {} + expr = readfile('%s%s.py' % (tests_path, testname)) + try: - expr = readfile('%s%s.exec' % (tests_path, testname)) - try: - 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)) - 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 + exec(expr, glob) # Evaluating the expression + print (colorize('Test passed', COLOR_GREEN)) + return True + except Exception as e: + print (colorize('ERROR', COLOR_RED)) + print (colorize('=====================================', COLOR_RED)) + traceback.print_exc(file=sys.stdout) + print (colorize('=====================================', COLOR_RED)) + return False def run_py_test(testname): diff --git a/test/rename_insert1.exec b/test/rename_insert1.py similarity index 82% rename from test/rename_insert1.exec rename to test/rename_insert1.py index eb8c89c..b2ccad6 100644 --- a/test/rename_insert1.exec +++ b/test/rename_insert1.py @@ -1,5 +1,4 @@ p1=people.rename({"id":"ido"}) people.insert((123,"lala",0,31)) - -retval=people==p1 +assert people!=p1 people.delete("id==123") diff --git a/test/rename_insert1.result b/test/rename_insert1.result deleted file mode 100644 index b6285aa..0000000 --- a/test/rename_insert1.result +++ /dev/null @@ -1 +0,0 @@ -{'retval':False} diff --git a/test/rename_insert2.exec b/test/rename_insert2.py similarity index 81% rename from test/rename_insert2.exec rename to test/rename_insert2.py index a77d9a7..8e271af 100644 --- a/test/rename_insert2.exec +++ b/test/rename_insert2.py @@ -1,5 +1,4 @@ p1=people.rename({"id":"ido"}) p1.insert((123,"lala",0,31)) - -retval=people==p1 +assert people!=p1 people.delete("id==123") diff --git a/test/rename_insert2.result b/test/rename_insert2.result deleted file mode 100644 index b6285aa..0000000 --- a/test/rename_insert2.result +++ /dev/null @@ -1 +0,0 @@ -{'retval':False}