workaround odd nose problem causing the run_tests function to be called even if the file is not main - refs #1539

This commit is contained in:
Dane Springmeyer 2012-10-16 12:49:12 -07:00
parent 1c9aa5bc09
commit 3980eea30a

View file

@ -58,24 +58,25 @@ def get_unique_colors(im):
pixels = sorted(pixels) pixels = sorted(pixels)
return map(pixel2rgba,pixels) return map(pixel2rgba,pixels)
def run_tests(iterable): def run_tests(iterable=None):
failed = 0 failed = 0
for test in iterable: if iterable:
try: for test in iterable:
test() try:
sys.stderr.write("\x1b[32m✓ \x1b[m" + test.__name__ + "\x1b[m\n") test()
except: sys.stderr.write("\x1b[32m✓ \x1b[m" + test.__name__ + "\x1b[m\n")
exc_type, exc_value, exc_tb = sys.exc_info() except:
failed += 1 exc_type, exc_value, exc_tb = sys.exc_info()
sys.stderr.write("\x1b[31m✘ \x1b[m" + test.__name__ + "\x1b[m\n") failed += 1
for mline in traceback.format_exception_only(exc_type, exc_value): sys.stderr.write("\x1b[31m✘ \x1b[m" + test.__name__ + "\x1b[m\n")
for line in mline.rstrip().split("\n"): for mline in traceback.format_exception_only(exc_type, exc_value):
sys.stderr.write(" \x1b[31m" + line + "\x1b[m\n") for line in mline.rstrip().split("\n"):
sys.stderr.write(" Traceback:\n") sys.stderr.write(" \x1b[31m" + line + "\x1b[m\n")
for mline in traceback.format_tb(exc_tb): sys.stderr.write(" Traceback:\n")
for line in mline.rstrip().split("\n"): for mline in traceback.format_tb(exc_tb):
sys.stderr.write(" " + line + "\n") for line in mline.rstrip().split("\n"):
sys.stderr.flush() sys.stderr.write(" " + line + "\n")
sys.stderr.flush()
return failed return failed
def side_by_side_image(left_im, right_im): def side_by_side_image(left_im, right_im):