File: runAll.py

package info (click to toggle)
python-wordaxe 0.3.2-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,228 kB
  • ctags: 786
  • sloc: python: 9,814; makefile: 5
file content (78 lines) | stat: -rw-r--r-- 1,945 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

"""Runs all test files in current folder."""

import os
import sys
from os.path import abspath, basename, dirname, isdir, join, splitext
import glob
import unittest

#we need to ensure 'tests' is on the path.  It will be if you
#run 'setup.py tests', but won't be if you CD into the tests
#directory and run this directly
testdir = dirname(abspath(__file__))
sys.path.insert(0, dirname(testdir))

from tests.utils import GlobDirectoryWalker, outputfile, printLocation


exclude = ('test_frames3f',)

keep = ('.py', '.gif', '.png', 'expected.pdf',
    'test_wordlist.txt', 'special_words.lst',
    'dokumentation_de.txt', 'dokumentation_en.txt')


def makeSuite(folder, pattern='test_*.py'):
    """Build a test suite of all available test files."""

    if isdir(folder): 
        sys.path.insert(0, folder)

    testSuite = unittest.TestSuite()
    filenames = glob.glob(join(folder, pattern))
    modnames = [basename(splitext(fn)[0]) for fn in filenames]
    loader = unittest.TestLoader()
    for mn in modnames:
        if mn in exclude:
            continue
        mod = __import__(mn)
        testSuite.addTest(loader.loadTestsFromModule(mod))

    return testSuite


def main(pattern='test_*.py'):
    try:
        folder = dirname(__file__)
        assert folder
    except:
        folder = dirname(sys.argv[0]) or os.getcwd()
    testSuite = makeSuite(folder, pattern)
    unittest.TextTestRunner().run(testSuite)


def clean():
    os.chdir(testdir)
    for fn in glob.glob("*"):
        ew = fn.endswith
        for n in keep:
            if fn.endswith(n):
                break
        else:
            print "removing", fn
            os.remove(fn)


if __name__ == '__main__':
    args = sys.argv[1:]
    if '--clean' in args:
        clean()
    else:
        try:
            pattern = args[0]
        except IndexError:
            pattern = 'test_*.py'
        main(pattern)