~ubuntu-branches/ubuntu/maverick/pygame/maverick

« back to all changes in this revision

Viewing changes to test/__main__.py

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-01-14 17:02:11 UTC
  • mfrom: (1.3.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100114170211-21eop2ja7mr9vdcr
Tags: 1.9.1release-0ubuntu1
* New upstream version (lp: #433304)
* debian/control:
  - build-depends on libportmidi-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Load and run the Pygame test suite
 
2
 
 
3
python -c "import pygame.tests.go" [<test options>]
 
4
 
 
5
or
 
6
 
 
7
python test/go.py [<test options>]
 
8
 
 
9
Command line option --help displays a command line usage message.
 
10
 
 
11
run_tests.py in the main distribution directory is an alternative to test.go
 
12
 
 
13
"""
 
14
 
 
15
import sys
 
16
 
 
17
if __name__ == '__main__':
 
18
    import os
 
19
    pkg_dir = os.path.split(os.path.abspath(__file__))[0]
 
20
    parent_dir, pkg_name = os.path.split(pkg_dir)
 
21
    is_pygame_pkg = (pkg_name == 'tests' and
 
22
                     os.path.split(parent_dir)[1] == 'pygame')
 
23
    if not is_pygame_pkg:
 
24
        sys.path.insert(0, parent_dir)
 
25
else:
 
26
    is_pygame_pkg = __name__.startswith('pygame.tests.')
 
27
 
 
28
if is_pygame_pkg:
 
29
    from pygame.tests.test_utils.run_tests import run
 
30
    from pygame.tests.test_utils.test_runner import opt_parser
 
31
else:
 
32
    from test.test_utils.run_tests import run
 
33
    from test.test_utils.test_runner import opt_parser
 
34
 
 
35
if is_pygame_pkg:
 
36
    test_pkg_name = "pygame.tests"
 
37
else:
 
38
    test_pkg_name = "test"
 
39
program_name = sys.argv[0]
 
40
if program_name == '-c':
 
41
    program_name = 'python -c "import %s.go"' % test_pkg_name
 
42
 
 
43
###########################################################################
 
44
# Set additional command line options
 
45
#
 
46
# Defined in test_runner.py as it shares options, added to here
 
47
 
 
48
opt_parser.set_usage("""
 
49
 
 
50
Runs all or some of the %(pkg)s.xxxx_test tests.
 
51
 
 
52
$ %(exec)s sprite threads -sd
 
53
 
 
54
Runs the sprite and threads module tests isolated in subprocesses, dumping
 
55
all failing tests info in the form of a dict.
 
56
 
 
57
""" % {'pkg': test_pkg_name, 'exec': program_name})
 
58
 
 
59
opt_parser.add_option (
 
60
     "-d",  "--dump", action = 'store_true',
 
61
     help   = "dump failures/errors as dict ready to eval" )
 
62
 
 
63
opt_parser.add_option (
 
64
     "-F",  "--file",
 
65
     help   = "dump failures/errors to a file" )
 
66
 
 
67
opt_parser.add_option (
 
68
     "-a",  "--all", action = 'store_true',
 
69
     help   = "dump all results not just errors eg. -da" )
 
70
 
 
71
opt_parser.add_option (
 
72
     "-m",  "--multi_thread", metavar = 'THREADS', type = 'int',
 
73
     help   = "run subprocessed tests in x THREADS" )
 
74
 
 
75
opt_parser.add_option (
 
76
     "-t",  "--time_out", metavar = 'SECONDS', type = 'int',
 
77
     help   = "kill stalled subprocessed tests after SECONDS" )
 
78
 
 
79
opt_parser.add_option (
 
80
     "-f",  "--fake", metavar = "DIR",
 
81
     help   = "run fake tests in run_tests__tests/$DIR" )
 
82
 
 
83
opt_parser.add_option (
 
84
     "-p",  "--python", metavar = "PYTHON",
 
85
     help   = "path to python excutable to run subproccesed tests\n"
 
86
              "default (sys.executable): %s" % sys.executable)
 
87
 
 
88
opt_parser.add_option (
 
89
     "-I",  "--interactive", action = 'store_true',
 
90
     help   = "include tests requiring user input")
 
91
 
 
92
###########################################################################
 
93
# Set run() keyword arguements according to command line arguemnts.
 
94
# args will be the test module list, passed as positional argumemts.
 
95
 
 
96
options, args = opt_parser.parse_args()
 
97
 
 
98
kwds = {}
 
99
if options.incomplete:
 
100
    kwds['incomplete'] = True
 
101
if options.nosubprocess:
 
102
    kwds['nosubprocess'] = True
 
103
if options.dump:
 
104
    kwds['dump'] = True
 
105
if options.file:
 
106
    kwds['file'] = options.file
 
107
kwds['timings'] = options.timings
 
108
if options.exclude:
 
109
    kwds['exclude'] = options.exclude
 
110
if options.show_output:
 
111
    kwds['show_output'] = True
 
112
if options.all:
 
113
    kwds['all'] = True
 
114
if options.randomize:
 
115
    kwds['randomize'] = True
 
116
if options.seed is not None:
 
117
    kwds['seed'] = options.seed
 
118
if options.multi_thread is not None:
 
119
    kwds['multi_thread'] = options.multi_thread
 
120
if options.time_out is not None:
 
121
    kwds['time_out'] = options.time_out
 
122
if options.fake:
 
123
    kwds['fake'] = options.fake
 
124
if options.python:
 
125
    kwds['python'] = options.python
 
126
if options.interactive:
 
127
    kwds['interactive'] = True
 
128
 
 
129
###########################################################################
 
130
# Run the test suite.
 
131
run(*args, **kwds)
 
132
 
 
133