| 1 |
import glob, os, new, sys |
| 2 |
import unittest |
| 3 |
import LatexTest |
| 4 |
|
| 5 |
# |
| 6 |
# Settings |
| 7 |
# |
| 8 |
class Settings: |
| 9 |
def __init__(self): |
| 10 |
sty_dir = os.path.normpath(os.path.join(os.getcwd(), '..', 'dev')) |
| 11 |
old_ti = os.getenv('TEXINPUTS', '') |
| 12 |
os.environ['TEXINPUTS'] = sty_dir + ':' + old_ti |
| 13 |
def get_tmp_dir(self): |
| 14 |
return 'tmp' |
| 15 |
def get_latex(self): |
| 16 |
return 'pdflatex' |
| 17 |
LatexTest.settings = Settings() |
| 18 |
|
| 19 |
# |
| 20 |
# Collect tests |
| 21 |
# |
| 22 |
filter = None |
| 23 |
if len(sys.argv) > 1: |
| 24 |
filter = sys.argv[1] |
| 25 |
test_files = glob.glob('*/test_*.tex') |
| 26 |
test_files = [x for x in test_files if 'visual_tables' not in x] |
| 27 |
modules_and_tests = {} |
| 28 |
for fname in test_files: |
| 29 |
(dir, basename) = os.path.split(fname) |
| 30 |
if 'tmp' == dir: |
| 31 |
continue |
| 32 |
if filter: |
| 33 |
if filter not in fname: |
| 34 |
continue |
| 35 |
modules_and_tests.setdefault(dir, []).append(basename) |
| 36 |
|
| 37 |
# |
| 38 |
# Test function |
| 39 |
# |
| 40 |
def generic_test_func(self, modname, testname): |
| 41 |
print 'I am a test case with parameters:', self.__class__, modname, testname |
| 42 |
self.assertEqual(1, 1) |
| 43 |
|
| 44 |
# |
| 45 |
# Create test classes and functions |
| 46 |
# |
| 47 |
test_classes = [] |
| 48 |
for module in modules_and_tests.iterkeys(): |
| 49 |
mtname = 'Test' + module.capitalize() |
| 50 |
cls = new.classobj(mtname, (LatexTest.LatexTestCase,), {}) |
| 51 |
for test_file in modules_and_tests[module]: |
| 52 |
test_name = os.path.splitext(test_file)[0] |
| 53 |
def get_test_func(func, module, test_name): |
| 54 |
def proxied(self): |
| 55 |
func(self, module, test_name) |
| 56 |
return proxied |
| 57 |
setattr(cls, test_name, get_test_func(LatexTest.LatexTestCase.run_test_case, module, test_name)) |
| 58 |
test_classes.append(cls) |
| 59 |
|
| 60 |
# |
| 61 |
# Run the tests |
| 62 |
# |
| 63 |
if __name__ == '__main__': |
| 64 |
tl = unittest.TestLoader() |
| 65 |
tests = [tl.loadTestsFromTestCase(x) for x in test_classes] |
| 66 |
tests = unittest.TestSuite(tests) |
| 67 |
unittest.TextTestRunner(verbosity=2).run(tests) |