tests: utility function for separate python tests

This commit is contained in:
Mickey Rose 2012-10-16 16:30:31 +02:00
parent 17e97c595a
commit 465cf0aa21
2 changed files with 25 additions and 3 deletions

View file

@ -2,7 +2,8 @@
from nose.tools import *
import os,sys
from utilities import execution_path, Todo, get_unique_colors, pixel2channels
from utilities import execution_path, run_tests, Todo
from utilities import get_unique_colors, pixel2channels
import mapnik
def setup():
@ -221,4 +222,4 @@ def test_background_image_with_alpha_and_background_color_against_composited_con
if __name__ == "__main__":
setup()
[eval(run)() for run in dir() if 'test_' in run]
run_tests(eval(x) for x in dir() if x.startswith("test_"))

View file

@ -1,8 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from nose.plugins.errorclass import ErrorClass, ErrorClassPlugin
import os, sys, inspect
import os, sys, inspect, traceback
def execution_path(filename):
return os.path.join(os.path.dirname(sys._getframe(1).f_code.co_filename), filename)
@ -55,3 +56,23 @@ def get_unique_colors(im):
pixels.append(pixel)
pixels = sorted(pixels)
return map(pixel2rgba,pixels)
def run_tests(iterable):
failed = 0
for test in iterable:
try:
test()
sys.stderr.write("\x1b[32m✓ \x1b[m" + test.__name__ + "\x1b[m\n")
except:
exc_type, exc_value, exc_tb = sys.exc_info()
failed += 1
sys.stderr.write("\x1b[31m✘ \x1b[m" + test.__name__ + "\x1b[m\n")
for mline in traceback.format_exception_only(exc_type, exc_value):
for line in mline.rstrip().split("\n"):
sys.stderr.write(" \x1b[31m" + line + "\x1b[m\n")
sys.stderr.write(" Traceback:\n")
for mline in traceback.format_tb(exc_tb):
for line in mline.rstrip().split("\n"):
sys.stderr.write(" " + line + "\n")
sys.stderr.flush()
return failed