from neo.constants import * def test_eq(val1, val2, error, last=TRUE, failed={'status':FALSE}): """Check equality of val1 and val2. If not equal, generate appropriate documentation.""" try: assert val1 == val2, error except AssertionError, e: print "%s (%s != %s)" % (e, val1, val2) print "\n " failed['status'] = TRUE else: if last: if not failed['status']: print "passed" def test_ne(val1, val2, error, last=TRUE, failed={'status':FALSE}): """Check inequality of val1 and val2. If equal, an error occured in testing; generate appropriate documentation.""" from neo.istring import istring, CALLER error = istring(error, CALLER) try: assert val1 != val2, error except AssertionError, e: sys.stdout.write("%s (%s == %s)\n" % (e, val1, val2)) failed['status'] = TRUE else: if last: if not failed['status']: sys.stdout.write("passed\n") failed['status'] = FALSE def test_exc(eval_str, exception, last=TRUE, failed={'status':FALSE}): """Eval the string, catching the exception provided. If the exception arises, the test passes, otherwise it fails.""" import sys l_globals = sys._getframe(2).f_globals l_locals = sys._getframe(2).f_locals try: eval(eval_str, l_globals, l_locals) except exception: if last: if not failed['status']: sys.stdout.write("passed\n") failed['status'] = FALSE else: sys.stdout.write("%s (%s == %s)\n" % (e, val1, val2)) failed['status'] = TRUE def disp(text, indent=0): import sys spaces = ' ' * (indent * 4) sys.stdout.write("%s%s" % (spaces, text))