~ubuntu-branches/ubuntu/trusty/pexpect/trusty-proposed

« back to all changes in this revision

Viewing changes to tools/testall.py

  • Committer: Package Import Robot
  • Author(s): Andrew Starr-Bochicchio, Thomas Kluyver, Jakub Wilk, Jackson Doak, Andrew Starr-Bochicchio
  • Date: 2013-12-06 20:20:26 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20131206202026-9k9oixbv7e8ke30q
Tags: 3.0-1
* Team upload.

[ Thomas Kluyver ]
* New upstream release. Closes: #729518
* Add packaging for Python 3.
* Use pybuild for packaging.

[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Jackson Doak ]
* Create debian/python3-pexpect.docs

[ Andrew Starr-Bochicchio ]
* Remove empty debian/patches dir.
* Move documentation and examples into a new python-pexpect-doc
  package. They are shared between the Python 2 and Python 3 packages,
  so there is no need to install them with both.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
'''This script runs all tests in a directory.
 
3
It does not need to know about the tests ahead of time.
 
4
It recursively descends from the current directory and
 
5
automatically builds up a list of tests to run.
 
6
Only directories named 'tests' are processed.
 
7
The path to each 'tests' directory is added to the PYTHONPATH.
 
8
Only python scripts that start with 'test_' are added to
 
9
the list of scripts in the test suite.
 
10
Noah Spurrier
 
11
 
 
12
PEXPECT LICENSE
 
13
 
 
14
    This license is approved by the OSI and FSF as GPL-compatible.
 
15
        http://opensource.org/licenses/isc-license.txt
 
16
 
 
17
    Copyright (c) 2012, Noah Spurrier <noah@noah.org>
 
18
    PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY
 
19
    PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE
 
20
    COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES.
 
21
    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 
22
    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 
23
    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 
24
    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 
25
    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 
26
    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 
27
    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
28
 
 
29
'''
 
30
from __future__ import print_function
 
31
 
 
32
import unittest
 
33
import os, os.path
 
34
import sys
 
35
import platform
 
36
 
 
37
import pexpect
 
38
 
 
39
print("Testing pexpect %s using python %s:" % (
 
40
    pexpect.__version__, platform.python_version()))
 
41
 
 
42
# Don't bother checking performance on Travis, we know it's slow.
 
43
TEST_PERFORMANCE = 'TRAVIS' not in os.environ
 
44
 
 
45
def add_tests_to_list (import_list, dirname, names):
 
46
    # Only check directories named 'tests'.
 
47
    if os.path.basename(dirname) != 'tests':
 
48
        return
 
49
    # Add any files that start with 'test_' and end with '.py'.
 
50
    for f in names:
 
51
        filename, ext = os.path.splitext(f)
 
52
        if ext != '.py':
 
53
            continue
 
54
        if (not TEST_PERFORMANCE) and (filename == 'test_performance'):
 
55
            continue
 
56
        if filename.find('test_') == 0:
 
57
            import_list.append (os.path.join(dirname, filename))
 
58
 
 
59
def find_modules_and_add_paths (root_path):
 
60
    import_list = []
 
61
    module_list = []
 
62
    for (dirpath, dirnames, filenames) in os.walk(root_path):
 
63
        add_tests_to_list(import_list, dirpath, filenames)
 
64
 
 
65
    for module_file in import_list:
 
66
        path, module = os.path.split(module_file)
 
67
        module_list.append (module)
 
68
        print('Adding:', os.path.relpath(module_file))
 
69
        if not path in sys.path:
 
70
            sys.path.append (path)
 
71
        if not os.path.dirname(path) in sys.path:
 
72
            sys.path.append (os.path.dirname(path))
 
73
 
 
74
    module_list.sort()
 
75
    return module_list
 
76
 
 
77
def suite():
 
78
    modules_to_test = find_modules_and_add_paths (os.getcwd())
 
79
    alltests = unittest.TestSuite()
 
80
    for module in map(__import__, modules_to_test):
 
81
        alltests.addTest(unittest.findTestCases(module))
 
82
    return alltests
 
83
 
 
84
if __name__ == '__main__':
 
85
    unittest.main(defaultTest='suite')
 
86
#    s = all()
 
87
#    runner = unittest.TextTestRunner()
 
88
#    runner.run (s)
 
89