summaryrefslogtreecommitdiff
path: root/pexpect/tools/testall.py
blob: 68b2a2bcee5e3816afb31a7eec2a7297c216e2a9 (plain)
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
#!/usr/bin/env python
'''This script runs all tests in a directory.
It does not need to know about the tests ahead of time.
It recursively descends from the current directory and
automatically builds up a list of tests to run.
Only directories named 'tests' are processed.
The path to each 'tests' directory is added to the PYTHONPATH.
Only python scripts that start with 'test_' are added to
the list of scripts in the test suite.
Noah Spurrier
'''

import unittest
import os, os.path
import sys

import pexpect
print "Testing pexpect version:", pexpect.__version__
print "Testing pexpect revision:", pexpect.__revision__

def add_tests_to_list (import_list, dirname, names):
    # Only check directories named 'tests'.
    if os.path.basename(dirname) != 'tests':
        return
    # Add any files that start with 'test_' and end with '.py'.
    for f in names:
        filename, ext = os.path.splitext(f)
        if ext != '.py':
            continue
        if filename.find('test_') == 0:
            import_list.append (os.path.join(dirname, filename))
 
def find_modules_and_add_paths (root_path):
    import_list = []
    module_list = []
    os.path.walk (root_path, add_tests_to_list, import_list)
    for module_file in import_list:
        path, module = os.path.split(module_file)
        module_list.append (module)
        print 'Adding:', module_file
        if not path in sys.path:
            sys.path.append (path)
        if not os.path.dirname(path) in sys.path:
            sys.path.append (os.path.dirname(path))
    module_list.sort()
    return module_list

def suite(): 
    modules_to_test = find_modules_and_add_paths (os.getcwd())
    alltests = unittest.TestSuite() 
    for module in map(__import__, modules_to_test): 
        alltests.addTest(unittest.findTestCases(module)) 
    return alltests 

if __name__ == '__main__':
    unittest.main(defaultTest='suite') 
#    s = all()
#    runner = unittest.TextTestRunner()
#    runner.run (s)