blob: 842dff7e86e10087b2cbc1b14454150fc1ac384a [file] [log] [blame]
Guido van Rossum152494a1996-12-20 03:12:20 +00001#! /usr/bin/env python
2
3"""Regression test.
4
5This will find all modules whose name is "test_*" in the test
6directory, and run them. Various command line options provide
7additional facilities.
8
9Command line options:
10
Barry Warsawa873b032000-08-03 15:50:37 +000011-v: verbose -- run tests in verbose mode with output to stdout
12-q: quiet -- don't print anything except if a test fails
13-g: generate -- write the output file for a test instead of comparing it
14-x: exclude -- arguments are tests to *exclude*
15-s: single -- run only a single test (see below)
16-r: random -- randomize test execution order
Tim Petersc5000df2002-06-02 21:42:01 +000017-f: fromfile -- read names of tests to run from a file (see below)
Neil Schemenauer8a00abc2000-10-13 01:32:42 +000018-l: findleaks -- if GC is available detect tests that leak memory
Barry Warsaw08fca522001-08-20 22:33:46 +000019-u: use -- specify which special resource intensive tests to run
20-h: help -- print this text and exit
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000021-t: threshold -- call gc.set_threshold(N)
Barry Warsaw3b6d0252004-02-07 22:43:03 +000022-T: coverage -- turn on code coverage using the trace module
Skip Montanaro0179a182004-06-06 15:53:18 +000023-L: runleaks -- run the leaks(1) command just before exit
Guido van Rossum152494a1996-12-20 03:12:20 +000024
25If non-option arguments are present, they are names for tests to run,
26unless -x is given, in which case they are names for tests not to run.
27If no test names are given, all tests are run.
Guido van Rossumf58ed251997-03-07 21:04:33 +000028
Guido van Rossuma4122201997-08-18 20:08:24 +000029-v is incompatible with -g and does not compare test output files.
Barry Warsawe11e3de1999-01-28 19:51:51 +000030
Barry Warsaw3b6d0252004-02-07 22:43:03 +000031-T turns on code coverage tracing with the trace module.
32
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000033-s means to run only a single test and exit. This is useful when
34doing memory analysis on the Python interpreter (which tend to consume
35too many resources to run the full regression test non-stop). The
36file /tmp/pynexttest is read to find the next test to run. If this
37file is missing, the first test_*.py file in testdir or on the command
38line is used. (actually tempfile.gettempdir() is used instead of
39/tmp).
Barry Warsawe11e3de1999-01-28 19:51:51 +000040
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000041-f reads the names of tests from the file given as f's argument, one
42or more test names per line. Whitespace is ignored. Blank lines and
43lines beginning with '#' are ignored. This is especially useful for
44whittling down failures involving interactions among tests.
Tim Petersc5000df2002-06-02 21:42:01 +000045
Skip Montanaro0179a182004-06-06 15:53:18 +000046-L causes the leaks(1) command to be run just before exit if it exists.
47leaks(1) is available on Mac OS X and presumably on some other
48FreeBSD-derived systems.
49
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000050-u is used to specify which special resource intensive tests to run,
51such as those requiring large file support or network connectivity.
52The argument is a comma-separated list of words indicating the
53resources to test. Currently only the following are defined:
Barry Warsaw08fca522001-08-20 22:33:46 +000054
Fred Drake3a15dac2002-04-11 16:39:16 +000055 all - Enable all special resources.
56
Guido van Rossum315aa362003-03-11 14:46:48 +000057 audio - Tests that use the audio device. (There are known
58 cases of broken audio drivers that can crash Python or
59 even the Linux kernel.)
60
Andrew M. Kuchling2158df02001-10-22 15:26:09 +000061 curses - Tests that use curses and will modify the terminal's
62 state and output modes.
Tim Peters1633a2e2001-10-30 05:56:40 +000063
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000064 largefile - It is okay to run some test that may create huge
65 files. These tests can take a long time and may
66 consume >2GB of disk space temporarily.
Barry Warsaw08fca522001-08-20 22:33:46 +000067
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000068 network - It is okay to run tests that use external network
69 resource, e.g. testing SSL support for sockets.
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000070
71 bsddb - It is okay to run the bsddb testsuite, which takes
72 a long time to complete.
Fred Drake4dd0f7e2002-11-26 21:44:56 +000073
Raymond Hettinger7c85fa42004-07-01 11:01:35 +000074 decimal - Test the decimal module against a large suite that
75 verifies compliance with standards.
76
Fred Drake4dd0f7e2002-11-26 21:44:56 +000077To enable all resources except one, use '-uall,-<resource>'. For
78example, to run all the tests except for the bsddb tests, give the
79option '-uall,-bsddb'.
Guido van Rossum152494a1996-12-20 03:12:20 +000080"""
81
Guido van Rossum152494a1996-12-20 03:12:20 +000082import os
Barry Warsaw3b6d0252004-02-07 22:43:03 +000083import sys
Guido van Rossum152494a1996-12-20 03:12:20 +000084import getopt
Skip Montanaroab1c7912000-06-30 16:39:27 +000085import random
Guido van Rossumdc15c272002-08-12 21:55:51 +000086import warnings
Barry Warsaw3b6d0252004-02-07 22:43:03 +000087import cStringIO
88import traceback
Guido van Rossumdc15c272002-08-12 21:55:51 +000089
90# I see no other way to suppress these warnings;
91# putting them in test_grammar.py has no effect:
Guido van Rossum88b1def2002-08-14 17:54:48 +000092warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
Guido van Rossumdc15c272002-08-12 21:55:51 +000093 ".*test.test_grammar$")
Guido van Rossumc34c4fc2002-09-19 00:42:16 +000094if sys.maxint > 0x7fffffff:
95 # Also suppress them in <string>, because for 64-bit platforms,
96 # that's where test_grammar.py hides them.
97 warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
98 "<string>")
Guido van Rossum152494a1996-12-20 03:12:20 +000099
Guido van Rossumbb484652002-12-02 09:56:21 +0000100# MacOSX (a.k.a. Darwin) has a default stack size that is too small
101# for deeply recursive regular expressions. We see this as crashes in
102# the Python test suite when running test_re.py and test_sre.py. The
103# fix is to set the stack limit to 2048.
104# This approach may also be useful for other Unixy platforms that
105# suffer from small default stack limits.
106if sys.platform == 'darwin':
107 try:
108 import resource
109 except ImportError:
110 pass
111 else:
112 soft, hard = resource.getrlimit(resource.RLIMIT_STACK)
113 newsoft = min(hard, max(soft, 1024*2048))
114 resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard))
115
Barry Warsaw04f357c2002-07-23 19:04:11 +0000116from test import test_support
Fred Drake3a15dac2002-04-11 16:39:16 +0000117
Raymond Hettinger7c85fa42004-07-01 11:01:35 +0000118RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', 'bsddb',
119 'decimal')
Fred Drake3a15dac2002-04-11 16:39:16 +0000120
121
Barry Warsaw08fca522001-08-20 22:33:46 +0000122def usage(code, msg=''):
123 print __doc__
124 if msg: print msg
125 sys.exit(code)
126
127
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000128def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
129 exclude=False, single=False, randomize=False, fromfile=None,
Skip Montanaro0179a182004-06-06 15:53:18 +0000130 findleaks=False, use_resources=None, trace=False, runleaks=False):
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000131 """Execute a test suite.
132
Thomas Wouters7e474022000-07-16 12:04:32 +0000133 This also parses command-line options and modifies its behavior
Fred Drake004d5e62000-10-23 17:22:08 +0000134 accordingly.
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000135
136 tests -- a list of strings containing test names (optional)
137 testdir -- the directory in which to look for tests (optional)
138
139 Users other than the Python test suite will certainly want to
140 specify testdir; if it's omitted, the directory containing the
Fred Drake004d5e62000-10-23 17:22:08 +0000141 Python test suite is searched for.
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000142
143 If the tests argument is omitted, the tests listed on the
144 command-line will be used. If that's empty, too, then all *.py
145 files beginning with test_ will be used.
Skip Montanaroab1c7912000-06-30 16:39:27 +0000146
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000147 The other default arguments (verbose, quiet, generate, exclude, single,
148 randomize, findleaks, use_resources, and trace) allow programmers calling
149 main() directly to set the values that would normally be set by flags on
150 the command line.
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000151 """
Fred Drake004d5e62000-10-23 17:22:08 +0000152
Tim Peters8dee8092001-09-25 20:05:11 +0000153 test_support.record_original_stdout(sys.stdout)
Guido van Rossum152494a1996-12-20 03:12:20 +0000154 try:
Skip Montanaro0179a182004-06-06 15:53:18 +0000155 opts, args = getopt.getopt(sys.argv[1:], 'hvgqxsrf:lu:t:TL',
Barry Warsaw08fca522001-08-20 22:33:46 +0000156 ['help', 'verbose', 'quiet', 'generate',
Tim Petersc5000df2002-06-02 21:42:01 +0000157 'exclude', 'single', 'random', 'fromfile',
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000158 'findleaks', 'use=', 'threshold=', 'trace',
Skip Montanaro0179a182004-06-06 15:53:18 +0000159 'runleaks'
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000160 ])
Guido van Rossum152494a1996-12-20 03:12:20 +0000161 except getopt.error, msg:
Barry Warsaw08fca522001-08-20 22:33:46 +0000162 usage(2, msg)
163
164 # Defaults
165 if use_resources is None:
166 use_resources = []
Guido van Rossum152494a1996-12-20 03:12:20 +0000167 for o, a in opts:
Barry Warsaw08fca522001-08-20 22:33:46 +0000168 if o in ('-h', '--help'):
169 usage(0)
170 elif o in ('-v', '--verbose'):
171 verbose += 1
172 elif o in ('-q', '--quiet'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000173 quiet = True;
Barry Warsaw08fca522001-08-20 22:33:46 +0000174 verbose = 0
175 elif o in ('-g', '--generate'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000176 generate = True
Barry Warsaw08fca522001-08-20 22:33:46 +0000177 elif o in ('-x', '--exclude'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000178 exclude = True
Barry Warsaw08fca522001-08-20 22:33:46 +0000179 elif o in ('-s', '--single'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000180 single = True
Barry Warsaw08fca522001-08-20 22:33:46 +0000181 elif o in ('-r', '--randomize'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000182 randomize = True
Tim Petersc5000df2002-06-02 21:42:01 +0000183 elif o in ('-f', '--fromfile'):
184 fromfile = a
Barry Warsaw08fca522001-08-20 22:33:46 +0000185 elif o in ('-l', '--findleaks'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000186 findleaks = True
Skip Montanaro0179a182004-06-06 15:53:18 +0000187 elif o in ('-L', '--runleaks'):
188 runleaks = True
Guido van Rossum9e9d4f82002-06-07 15:17:03 +0000189 elif o in ('-t', '--threshold'):
190 import gc
191 gc.set_threshold(int(a))
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000192 elif o in ('-T', '--coverage'):
193 trace = True
Barry Warsaw08fca522001-08-20 22:33:46 +0000194 elif o in ('-u', '--use'):
Guido van Rossumfe3f6962001-09-06 16:09:41 +0000195 u = [x.lower() for x in a.split(',')]
196 for r in u:
Fred Drake3a15dac2002-04-11 16:39:16 +0000197 if r == 'all':
Fred Drake4dd0f7e2002-11-26 21:44:56 +0000198 use_resources[:] = RESOURCE_NAMES
199 continue
200 remove = False
201 if r[0] == '-':
202 remove = True
203 r = r[1:]
Fred Drake3a15dac2002-04-11 16:39:16 +0000204 if r not in RESOURCE_NAMES:
205 usage(1, 'Invalid -u/--use option: ' + a)
Fred Drake4dd0f7e2002-11-26 21:44:56 +0000206 if remove:
207 if r in use_resources:
208 use_resources.remove(r)
209 elif r not in use_resources:
Andrew MacIntyree41abab2002-04-30 12:11:04 +0000210 use_resources.append(r)
Guido van Rossuma4122201997-08-18 20:08:24 +0000211 if generate and verbose:
Barry Warsaw08fca522001-08-20 22:33:46 +0000212 usage(2, "-g and -v don't go together!")
Tim Petersc5000df2002-06-02 21:42:01 +0000213 if single and fromfile:
214 usage(2, "-s and -f don't go together!")
Barry Warsaw08fca522001-08-20 22:33:46 +0000215
Guido van Rossum152494a1996-12-20 03:12:20 +0000216 good = []
217 bad = []
218 skipped = []
Fred Drake9a0db072003-02-03 15:19:30 +0000219 resource_denieds = []
Barry Warsawe11e3de1999-01-28 19:51:51 +0000220
Neil Schemenauerd569f232000-09-22 15:29:28 +0000221 if findleaks:
Barry Warsawa873b032000-08-03 15:50:37 +0000222 try:
223 import gc
224 except ImportError:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000225 print 'No GC available, disabling findleaks.'
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000226 findleaks = False
Barry Warsawa873b032000-08-03 15:50:37 +0000227 else:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000228 # Uncomment the line below to report garbage that is not
229 # freeable by reference counting alone. By default only
230 # garbage that is not collectable by the GC is reported.
231 #gc.set_debug(gc.DEBUG_SAVEALL)
Neil Schemenauerd569f232000-09-22 15:29:28 +0000232 found_garbage = []
Barry Warsawa873b032000-08-03 15:50:37 +0000233
Barry Warsawe11e3de1999-01-28 19:51:51 +0000234 if single:
235 from tempfile import gettempdir
236 filename = os.path.join(gettempdir(), 'pynexttest')
237 try:
238 fp = open(filename, 'r')
Eric S. Raymondfc170b12001-02-09 11:51:27 +0000239 next = fp.read().strip()
Barry Warsawe11e3de1999-01-28 19:51:51 +0000240 tests = [next]
241 fp.close()
242 except IOError:
243 pass
Tim Petersc5000df2002-06-02 21:42:01 +0000244
245 if fromfile:
246 tests = []
247 fp = open(fromfile)
248 for line in fp:
249 guts = line.split() # assuming no test has whitespace in its name
250 if guts and not guts[0].startswith('#'):
251 tests.extend(guts)
252 fp.close()
253
254 # Strip .py extensions.
255 if args:
256 args = map(removepy, args)
257 if tests:
258 tests = map(removepy, tests)
259
Guido van Rossum6c74fea1998-08-25 12:29:08 +0000260 stdtests = STDTESTS[:]
261 nottests = NOTTESTS[:]
Guido van Rossum152494a1996-12-20 03:12:20 +0000262 if exclude:
Guido van Rossum6c74fea1998-08-25 12:29:08 +0000263 for arg in args:
264 if arg in stdtests:
265 stdtests.remove(arg)
266 nottests[:0] = args
Guido van Rossum41360a41998-03-26 19:42:58 +0000267 args = []
Guido van Rossum747e1ca1998-08-24 13:48:36 +0000268 tests = tests or args or findtests(testdir, stdtests, nottests)
Barry Warsawe11e3de1999-01-28 19:51:51 +0000269 if single:
270 tests = tests[:1]
Skip Montanaroab1c7912000-06-30 16:39:27 +0000271 if randomize:
272 random.shuffle(tests)
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000273 if trace:
274 import trace
275 tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix],
276 trace=False, count=True)
277 coverdir = os.path.join(os.getcwd(), 'coverage')
Guido van Rossum41360a41998-03-26 19:42:58 +0000278 test_support.verbose = verbose # Tell tests to be moderately quiet
Barry Warsaw08fca522001-08-20 22:33:46 +0000279 test_support.use_resources = use_resources
Guido van Rossum5796d262000-04-21 21:35:06 +0000280 save_modules = sys.modules.keys()
Guido van Rossum152494a1996-12-20 03:12:20 +0000281 for test in tests:
Guido van Rossum41360a41998-03-26 19:42:58 +0000282 if not quiet:
283 print test
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000284 sys.stdout.flush()
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000285 if trace:
286 # If we're tracing code coverage, then we don't exit with status
287 # if on a false return value from main.
288 tracer.runctx('runtest(test, generate, verbose, quiet, testdir)',
289 globals=globals(), locals=vars())
Guido van Rossum41360a41998-03-26 19:42:58 +0000290 else:
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000291 ok = runtest(test, generate, verbose, quiet, testdir)
292 if ok > 0:
293 good.append(test)
294 elif ok == 0:
295 bad.append(test)
296 else:
297 skipped.append(test)
298 if ok == -2:
299 resource_denieds.append(test)
Neil Schemenauerd569f232000-09-22 15:29:28 +0000300 if findleaks:
301 gc.collect()
302 if gc.garbage:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000303 print "Warning: test created", len(gc.garbage),
304 print "uncollectable object(s)."
305 # move the uncollectable objects somewhere so we don't see
306 # them again
Neil Schemenauerd569f232000-09-22 15:29:28 +0000307 found_garbage.extend(gc.garbage)
308 del gc.garbage[:]
Guido van Rossum5796d262000-04-21 21:35:06 +0000309 # Unload the newly imported modules (best effort finalization)
310 for module in sys.modules.keys():
Guido van Rossum51931142000-05-05 14:27:39 +0000311 if module not in save_modules and module.startswith("test."):
Guido van Rossum5796d262000-04-21 21:35:06 +0000312 test_support.unload(module)
Jeremy Hylton7a1ea0e2001-10-17 13:45:28 +0000313
314 # The lists won't be sorted if running with -r
315 good.sort()
316 bad.sort()
317 skipped.sort()
Tim Peterse0c446b2001-10-18 21:57:37 +0000318
Guido van Rossum152494a1996-12-20 03:12:20 +0000319 if good and not quiet:
Guido van Rossum41360a41998-03-26 19:42:58 +0000320 if not bad and not skipped and len(good) > 1:
321 print "All",
322 print count(len(good), "test"), "OK."
Tim Peters1a4d77b2000-12-30 22:21:22 +0000323 if verbose:
Barry Warsaw408b6d32002-07-30 23:27:12 +0000324 print "CAUTION: stdout isn't compared in verbose mode:"
325 print "a test that passes in verbose mode may fail without it."
Guido van Rossum152494a1996-12-20 03:12:20 +0000326 if bad:
Tim Petersa45da922001-08-12 03:45:50 +0000327 print count(len(bad), "test"), "failed:"
328 printlist(bad)
Guido van Rossum152494a1996-12-20 03:12:20 +0000329 if skipped and not quiet:
Tim Petersa45da922001-08-12 03:45:50 +0000330 print count(len(skipped), "test"), "skipped:"
331 printlist(skipped)
Barry Warsawe11e3de1999-01-28 19:51:51 +0000332
Tim Petersb5b7b782001-08-12 01:20:39 +0000333 e = _ExpectedSkips()
Tim Petersa2be2d62001-08-12 02:01:09 +0000334 plat = sys.platform
Tim Petersb5b7b782001-08-12 01:20:39 +0000335 if e.isvalid():
Raymond Hettingera690a992003-11-16 16:17:49 +0000336 surprise = set(skipped) - e.getexpected() - set(resource_denieds)
Tim Petersb5b7b782001-08-12 01:20:39 +0000337 if surprise:
338 print count(len(surprise), "skip"), \
Tim Petersa45da922001-08-12 03:45:50 +0000339 "unexpected on", plat + ":"
340 printlist(surprise)
Tim Petersb5b7b782001-08-12 01:20:39 +0000341 else:
342 print "Those skips are all expected on", plat + "."
343 else:
344 print "Ask someone to teach regrtest.py about which tests are"
345 print "expected to get skipped on", plat + "."
346
Barry Warsawe11e3de1999-01-28 19:51:51 +0000347 if single:
348 alltests = findtests(testdir, stdtests, nottests)
349 for i in range(len(alltests)):
350 if tests[0] == alltests[i]:
351 if i == len(alltests) - 1:
352 os.unlink(filename)
353 else:
354 fp = open(filename, 'w')
355 fp.write(alltests[i+1] + '\n')
356 fp.close()
357 break
358 else:
359 os.unlink(filename)
360
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000361 if trace:
362 r = tracer.results()
363 r.write_results(show_missing=True, summary=True, coverdir=coverdir)
364
Skip Montanaro0179a182004-06-06 15:53:18 +0000365 if runleaks:
366 os.system("leaks %d" % os.getpid())
367
Tim Peters5943b4a2003-07-23 00:30:39 +0000368 sys.exit(len(bad) > 0)
Barry Warsaw08fca522001-08-20 22:33:46 +0000369
Guido van Rossum152494a1996-12-20 03:12:20 +0000370
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000371STDTESTS = [
Guido van Rossum152494a1996-12-20 03:12:20 +0000372 'test_grammar',
373 'test_opcodes',
374 'test_operations',
375 'test_builtin',
376 'test_exceptions',
377 'test_types',
378 ]
379
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000380NOTTESTS = [
Guido van Rossum152494a1996-12-20 03:12:20 +0000381 'test_support',
Jeremy Hylton62e2c7e2001-02-28 17:48:06 +0000382 'test_future1',
383 'test_future2',
Jeremy Hylton8471a352001-08-20 20:33:42 +0000384 'test_future3',
Guido van Rossum152494a1996-12-20 03:12:20 +0000385 ]
386
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000387def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
Guido van Rossum152494a1996-12-20 03:12:20 +0000388 """Return a list of all applicable test modules."""
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000389 if not testdir: testdir = findtestdir()
Guido van Rossum152494a1996-12-20 03:12:20 +0000390 names = os.listdir(testdir)
391 tests = []
392 for name in names:
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000393 if name[:5] == "test_" and name[-3:] == os.extsep+"py":
Guido van Rossum41360a41998-03-26 19:42:58 +0000394 modname = name[:-3]
395 if modname not in stdtests and modname not in nottests:
396 tests.append(modname)
Guido van Rossum152494a1996-12-20 03:12:20 +0000397 tests.sort()
398 return stdtests + tests
399
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000400def runtest(test, generate, verbose, quiet, testdir=None):
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000401 """Run a single test.
402 test -- the name of the test
403 generate -- if true, generate output, instead of running the test
404 and comparing it to a previously created output file
405 verbose -- if true, print more messages
Trent Mickf29f47b2000-08-11 19:02:59 +0000406 quiet -- if true, don't print 'skipped' messages (probably redundant)
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000407 testdir -- test directory
408 """
Guido van Rossum152494a1996-12-20 03:12:20 +0000409 test_support.unload(test)
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000410 if not testdir:
411 testdir = findtestdir()
Guido van Rossum152494a1996-12-20 03:12:20 +0000412 outputdir = os.path.join(testdir, "output")
413 outputfile = os.path.join(outputdir, test)
Tim Peters9390cc12001-09-28 20:14:46 +0000414 if verbose:
Guido van Rossum41360a41998-03-26 19:42:58 +0000415 cfp = None
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000416 else:
Raymond Hettinger74e67662003-05-17 20:44:12 +0000417 cfp = cStringIO.StringIO()
Guido van Rossum152494a1996-12-20 03:12:20 +0000418 try:
Tim Peters342ca752001-09-25 19:13:20 +0000419 save_stdout = sys.stdout
Guido van Rossum41360a41998-03-26 19:42:58 +0000420 try:
421 if cfp:
422 sys.stdout = cfp
423 print test # Output file starts with test name
Barry Warsaw408b6d32002-07-30 23:27:12 +0000424 if test.startswith('test.'):
425 abstest = test
426 else:
427 # Always import it from the test package
428 abstest = 'test.' + test
429 the_package = __import__(abstest, globals(), locals(), [])
430 the_module = getattr(the_package, test)
Tim Petersd9742212001-05-22 18:28:25 +0000431 # Most tests run to completion simply as a side-effect of
432 # being imported. For the benefit of tests that can't run
433 # that way (like test_threaded_import), explicitly invoke
434 # their test_main() function (if it exists).
435 indirect_test = getattr(the_module, "test_main", None)
436 if indirect_test is not None:
437 indirect_test()
Guido van Rossum41360a41998-03-26 19:42:58 +0000438 finally:
Tim Peters342ca752001-09-25 19:13:20 +0000439 sys.stdout = save_stdout
Fred Drake9a0db072003-02-03 15:19:30 +0000440 except test_support.ResourceDenied, msg:
441 if not quiet:
442 print test, "skipped --", msg
443 sys.stdout.flush()
444 return -2
Thomas Wouters3af826e2000-08-04 13:17:51 +0000445 except (ImportError, test_support.TestSkipped), msg:
Trent Mickf29f47b2000-08-11 19:02:59 +0000446 if not quiet:
Fred Drakede4742b2002-10-17 20:36:08 +0000447 print test, "skipped --", msg
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000448 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000449 return -1
Fred Drakefe5c22a2000-08-18 16:04:05 +0000450 except KeyboardInterrupt:
451 raise
Guido van Rossum152494a1996-12-20 03:12:20 +0000452 except test_support.TestFailed, msg:
Guido van Rossum41360a41998-03-26 19:42:58 +0000453 print "test", test, "failed --", msg
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000454 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000455 return 0
Guido van Rossum9e48b271997-07-16 01:56:13 +0000456 except:
Guido van Rossum41360a41998-03-26 19:42:58 +0000457 type, value = sys.exc_info()[:2]
Fred Drake27c4b392000-08-23 20:34:40 +0000458 print "test", test, "crashed --", str(type) + ":", value
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000459 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000460 if verbose:
461 traceback.print_exc(file=sys.stdout)
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000462 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000463 return 0
Guido van Rossum152494a1996-12-20 03:12:20 +0000464 else:
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000465 if not cfp:
466 return 1
467 output = cfp.getvalue()
Fred Drakee51fe8d2001-05-29 17:10:51 +0000468 if generate:
Fred Drakee51fe8d2001-05-29 17:10:51 +0000469 if output == test + "\n":
470 if os.path.exists(outputfile):
471 # Write it since it already exists (and the contents
472 # may have changed), but let the user know it isn't
473 # needed:
Fred Drakee51fe8d2001-05-29 17:10:51 +0000474 print "output file", outputfile, \
475 "is no longer needed; consider removing it"
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000476 else:
477 # We don't need it, so don't create it.
478 return 1
479 fp = open(outputfile, "w")
480 fp.write(output)
481 fp.close()
482 return 1
483 if os.path.exists(outputfile):
484 fp = open(outputfile, "r")
485 expected = fp.read()
486 fp.close()
487 else:
488 expected = test + "\n"
489 if output == expected:
490 return 1
491 print "test", test, "produced unexpected output:"
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000492 sys.stdout.flush()
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000493 reportdiff(expected, output)
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000494 sys.stdout.flush()
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000495 return 0
496
497def reportdiff(expected, output):
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000498 import difflib
Tim Petersc377b162001-09-22 05:31:03 +0000499 print "*" * 70
500 a = expected.splitlines(1)
501 b = output.splitlines(1)
Guido van Rossumcf691932001-09-21 21:06:22 +0000502 sm = difflib.SequenceMatcher(a=a, b=b)
503 tuples = sm.get_opcodes()
Tim Petersc377b162001-09-22 05:31:03 +0000504
Guido van Rossumcf691932001-09-21 21:06:22 +0000505 def pair(x0, x1):
Tim Petersc377b162001-09-22 05:31:03 +0000506 # x0:x1 are 0-based slice indices; convert to 1-based line indices.
Guido van Rossumcf691932001-09-21 21:06:22 +0000507 x0 += 1
508 if x0 >= x1:
Tim Petersc377b162001-09-22 05:31:03 +0000509 return "line " + str(x0)
Guido van Rossumcf691932001-09-21 21:06:22 +0000510 else:
Tim Petersc377b162001-09-22 05:31:03 +0000511 return "lines %d-%d" % (x0, x1)
512
Guido van Rossumcf691932001-09-21 21:06:22 +0000513 for op, a0, a1, b0, b1 in tuples:
514 if op == 'equal':
515 pass
Tim Petersc377b162001-09-22 05:31:03 +0000516
Guido van Rossumcf691932001-09-21 21:06:22 +0000517 elif op == 'delete':
Tim Petersc377b162001-09-22 05:31:03 +0000518 print "***", pair(a0, a1), "of expected output missing:"
Guido van Rossumcf691932001-09-21 21:06:22 +0000519 for line in a[a0:a1]:
Tim Petersc377b162001-09-22 05:31:03 +0000520 print "-", line,
521
Guido van Rossumcf691932001-09-21 21:06:22 +0000522 elif op == 'replace':
Tim Petersc377b162001-09-22 05:31:03 +0000523 print "*** mismatch between", pair(a0, a1), "of expected", \
524 "output and", pair(b0, b1), "of actual output:"
525 for line in difflib.ndiff(a[a0:a1], b[b0:b1]):
526 print line,
527
Guido van Rossumcf691932001-09-21 21:06:22 +0000528 elif op == 'insert':
Tim Petersc377b162001-09-22 05:31:03 +0000529 print "***", pair(b0, b1), "of actual output doesn't appear", \
530 "in expected output after line", str(a1)+":"
Guido van Rossumcf691932001-09-21 21:06:22 +0000531 for line in b[b0:b1]:
Tim Petersc377b162001-09-22 05:31:03 +0000532 print "+", line,
533
Guido van Rossumcf691932001-09-21 21:06:22 +0000534 else:
535 print "get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1)
Tim Petersc377b162001-09-22 05:31:03 +0000536
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000537 print "*" * 70
Guido van Rossum152494a1996-12-20 03:12:20 +0000538
539def findtestdir():
540 if __name__ == '__main__':
Guido van Rossum41360a41998-03-26 19:42:58 +0000541 file = sys.argv[0]
Guido van Rossum152494a1996-12-20 03:12:20 +0000542 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000543 file = __file__
Guido van Rossum152494a1996-12-20 03:12:20 +0000544 testdir = os.path.dirname(file) or os.curdir
545 return testdir
546
Tim Petersc5000df2002-06-02 21:42:01 +0000547def removepy(name):
548 if name.endswith(os.extsep + "py"):
549 name = name[:-3]
550 return name
551
Guido van Rossum152494a1996-12-20 03:12:20 +0000552def count(n, word):
553 if n == 1:
Guido van Rossum41360a41998-03-26 19:42:58 +0000554 return "%d %s" % (n, word)
Guido van Rossum152494a1996-12-20 03:12:20 +0000555 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000556 return "%d %ss" % (n, word)
Guido van Rossum152494a1996-12-20 03:12:20 +0000557
Tim Petersa45da922001-08-12 03:45:50 +0000558def printlist(x, width=70, indent=4):
Tim Peters7c7efe92002-08-23 17:55:54 +0000559 """Print the elements of iterable x to stdout.
Tim Petersa45da922001-08-12 03:45:50 +0000560
561 Optional arg width (default 70) is the maximum line length.
562 Optional arg indent (default 4) is the number of blanks with which to
563 begin each line.
564 """
565
Tim Petersba78bc42002-07-04 19:45:06 +0000566 from textwrap import fill
567 blanks = ' ' * indent
568 print fill(' '.join(map(str, x)), width,
569 initial_indent=blanks, subsequent_indent=blanks)
Tim Petersa45da922001-08-12 03:45:50 +0000570
Tim Petersde14a302002-04-01 05:04:46 +0000571# Map sys.platform to a string containing the basenames of tests
572# expected to be skipped on that platform.
Tim Peters2a182db2002-10-09 01:07:11 +0000573#
574# Special cases:
575# test_pep277
576# The _ExpectedSkips constructor adds this to the set of expected
577# skips if not os.path.supports_unicode_filenames.
Tim Peters1b445d32002-11-24 18:53:11 +0000578# test_normalization
579# Whether a skip is expected here depends on whether a large test
580# input file has been downloaded. test_normalization.skip_expected
Tim Peters1babdfc2002-11-24 19:19:09 +0000581# controls that.
Tim Petersb4ee4eb2002-12-04 03:26:57 +0000582# test_socket_ssl
583# Controlled by test_socket_ssl.skip_expected. Requires the network
584# resource, and a socket module with ssl support.
Neal Norwitz55b61d22003-02-28 19:57:03 +0000585# test_timeout
586# Controlled by test_timeout.skip_expected. Requires the network
587# resource and a socket module.
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +0000588# test_codecmaps_*
589# Whether a skip is expected here depends on whether a large test
590# input file has been downloaded. test_codecmaps_*.skip_expected
591# controls that.
Tim Petersde14a302002-04-01 05:04:46 +0000592
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000593_expectations = {
594 'win32':
595 """
Tim Petersc7c516a2003-09-20 22:06:13 +0000596 test__locale
Raymond Hettinger901dc982003-11-20 19:02:02 +0000597 test_applesingle
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000598 test_al
Skip Montanaro823ba282003-05-06 20:36:24 +0000599 test_bsddb185
Tim Peters78e35f92002-11-22 20:00:34 +0000600 test_bsddb3
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000601 test_cd
602 test_cl
603 test_commands
604 test_crypt
Tim Petersd7030572001-10-22 22:06:08 +0000605 test_curses
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000606 test_dbm
607 test_dl
608 test_fcntl
609 test_fork1
610 test_gdbm
611 test_gl
612 test_grp
613 test_imgfile
Tim Petersfd8e6e52003-03-04 00:26:38 +0000614 test_ioctl
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000615 test_largefile
616 test_linuxaudiodev
617 test_mhlib
Tim Petersde14a302002-04-01 05:04:46 +0000618 test_mpz
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000619 test_nis
620 test_openpty
Tim Petersefc4b122002-12-10 18:47:56 +0000621 test_ossaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000622 test_poll
Tim Peters003eb302003-02-17 21:48:48 +0000623 test_posix
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000624 test_pty
625 test_pwd
Tim Peters1e33ffa2002-04-23 23:09:02 +0000626 test_resource
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000627 test_signal
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000628 test_sunaudiodev
629 test_timing
630 """,
631 'linux2':
632 """
633 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000634 test_applesingle
Skip Montanaro823ba282003-05-06 20:36:24 +0000635 test_bsddb185
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000636 test_cd
637 test_cl
Guido van Rossumf66dacd2001-10-23 15:10:55 +0000638 test_curses
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000639 test_dl
640 test_gl
641 test_imgfile
642 test_largefile
Guido van Rossum4507ec72003-02-14 19:29:22 +0000643 test_linuxaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000644 test_nis
645 test_ntpath
Guido van Rossum4507ec72003-02-14 19:29:22 +0000646 test_ossaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000647 test_sunaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000648 """,
Jack Jansen49a806e2001-08-28 14:49:00 +0000649 'mac':
Guido van Rossumaa782362001-09-02 03:58:41 +0000650 """
651 test_al
Jack Jansen67975142003-01-08 16:31:11 +0000652 test_atexit
Guido van Rossumaa782362001-09-02 03:58:41 +0000653 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000654 test_bsddb185
Jack Jansen67975142003-01-08 16:31:11 +0000655 test_bsddb3
656 test_bz2
Guido van Rossumaa782362001-09-02 03:58:41 +0000657 test_cd
658 test_cl
659 test_commands
660 test_crypt
Jack Jansenb3be2162001-11-30 14:16:36 +0000661 test_curses
Guido van Rossumaa782362001-09-02 03:58:41 +0000662 test_dbm
663 test_dl
664 test_fcntl
665 test_fork1
666 test_gl
667 test_grp
Jack Jansenc4d6bdd2003-03-07 15:38:11 +0000668 test_ioctl
Guido van Rossumaa782362001-09-02 03:58:41 +0000669 test_imgfile
670 test_largefile
671 test_linuxaudiodev
672 test_locale
673 test_mmap
Jack Jansen67975142003-01-08 16:31:11 +0000674 test_mpz
Guido van Rossumaa782362001-09-02 03:58:41 +0000675 test_nis
676 test_ntpath
677 test_openpty
Jack Jansen67975142003-01-08 16:31:11 +0000678 test_ossaudiodev
Guido van Rossumaa782362001-09-02 03:58:41 +0000679 test_poll
Jack Jansen67975142003-01-08 16:31:11 +0000680 test_popen
Guido van Rossumaa782362001-09-02 03:58:41 +0000681 test_popen2
Jack Jansen5bb97e62003-02-21 22:33:55 +0000682 test_posix
Guido van Rossumaa782362001-09-02 03:58:41 +0000683 test_pty
684 test_pwd
Jack Jansen67975142003-01-08 16:31:11 +0000685 test_resource
Guido van Rossumaa782362001-09-02 03:58:41 +0000686 test_signal
Guido van Rossumaa782362001-09-02 03:58:41 +0000687 test_sunaudiodev
688 test_sundry
Jack Jansenc4d6bdd2003-03-07 15:38:11 +0000689 test_tarfile
Guido van Rossumaa782362001-09-02 03:58:41 +0000690 test_timing
Guido van Rossumaa782362001-09-02 03:58:41 +0000691 """,
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000692 'unixware7':
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000693 """
694 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000695 test_applesingle
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000696 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000697 test_bsddb185
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000698 test_cd
699 test_cl
700 test_dl
701 test_gl
702 test_imgfile
703 test_largefile
704 test_linuxaudiodev
705 test_minidom
706 test_nis
707 test_ntpath
708 test_openpty
709 test_pyexpat
710 test_sax
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000711 test_sunaudiodev
712 test_sundry
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000713 """,
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000714 'openunix8':
715 """
716 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000717 test_applesingle
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000718 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000719 test_bsddb185
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000720 test_cd
721 test_cl
722 test_dl
723 test_gl
724 test_imgfile
725 test_largefile
726 test_linuxaudiodev
727 test_minidom
728 test_nis
729 test_ntpath
730 test_openpty
731 test_pyexpat
732 test_sax
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000733 test_sunaudiodev
734 test_sundry
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000735 """,
736 'sco_sv3':
737 """
738 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000739 test_applesingle
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000740 test_asynchat
741 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000742 test_bsddb185
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000743 test_cd
744 test_cl
745 test_dl
746 test_fork1
747 test_gettext
748 test_gl
749 test_imgfile
750 test_largefile
751 test_linuxaudiodev
752 test_locale
753 test_minidom
754 test_nis
755 test_ntpath
756 test_openpty
757 test_pyexpat
758 test_queue
759 test_sax
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000760 test_sunaudiodev
761 test_sundry
762 test_thread
763 test_threaded_import
764 test_threadedtempfile
765 test_threading
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000766 """,
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000767 'riscos':
768 """
769 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000770 test_applesingle
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000771 test_asynchat
Martin v. Löwisa94568a2003-05-10 07:36:56 +0000772 test_atexit
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000773 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000774 test_bsddb185
Martin v. Löwisa94568a2003-05-10 07:36:56 +0000775 test_bsddb3
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000776 test_cd
777 test_cl
778 test_commands
779 test_crypt
780 test_dbm
781 test_dl
782 test_fcntl
783 test_fork1
784 test_gdbm
785 test_gl
786 test_grp
787 test_imgfile
788 test_largefile
789 test_linuxaudiodev
790 test_locale
791 test_mmap
792 test_nis
793 test_ntpath
794 test_openpty
795 test_poll
796 test_popen2
797 test_pty
798 test_pwd
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000799 test_strop
800 test_sunaudiodev
801 test_sundry
802 test_thread
803 test_threaded_import
804 test_threadedtempfile
805 test_threading
806 test_timing
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000807 """,
Jack Jansen8a97f4a2001-12-05 23:27:32 +0000808 'darwin':
Jack Jansen398c2362001-12-02 21:41:36 +0000809 """
Brett Cannon2bfb94c2003-10-13 04:27:47 +0000810 test__locale
Jack Jansen398c2362001-12-02 21:41:36 +0000811 test_al
Jack Jansenacda3392002-12-30 23:03:13 +0000812 test_bsddb
Guido van Rossum9d427002002-12-03 10:24:56 +0000813 test_bsddb3
Jack Jansen398c2362001-12-02 21:41:36 +0000814 test_cd
815 test_cl
816 test_curses
817 test_dl
818 test_gdbm
819 test_gl
820 test_imgfile
821 test_largefile
822 test_linuxaudiodev
Jack Jansenacda3392002-12-30 23:03:13 +0000823 test_locale
Jack Jansen398c2362001-12-02 21:41:36 +0000824 test_minidom
Guido van Rossum9d427002002-12-03 10:24:56 +0000825 test_mpz
Jack Jansen398c2362001-12-02 21:41:36 +0000826 test_nis
827 test_ntpath
Jack Jansenacda3392002-12-30 23:03:13 +0000828 test_ossaudiodev
Jack Jansen398c2362001-12-02 21:41:36 +0000829 test_poll
Jack Jansen398c2362001-12-02 21:41:36 +0000830 test_sunaudiodev
Jack Jansen398c2362001-12-02 21:41:36 +0000831 """,
Guido van Rossum11c3f092002-07-17 15:08:24 +0000832 'sunos5':
833 """
834 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000835 test_applesingle
Guido van Rossum11c3f092002-07-17 15:08:24 +0000836 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000837 test_bsddb185
Guido van Rossum11c3f092002-07-17 15:08:24 +0000838 test_cd
839 test_cl
840 test_curses
841 test_dbm
Guido van Rossum11c3f092002-07-17 15:08:24 +0000842 test_gdbm
843 test_gl
844 test_gzip
845 test_imgfile
846 test_linuxaudiodev
847 test_mpz
848 test_openpty
Guido van Rossum11c3f092002-07-17 15:08:24 +0000849 test_zipfile
850 test_zlib
Jeremy Hyltoned375e12002-07-17 15:56:55 +0000851 """,
Skip Montanarob3230212002-03-15 02:54:03 +0000852 'hp-ux11':
853 """
854 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000855 test_applesingle
Skip Montanarob3230212002-03-15 02:54:03 +0000856 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000857 test_bsddb185
Skip Montanarob3230212002-03-15 02:54:03 +0000858 test_cd
859 test_cl
860 test_curses
861 test_dl
862 test_gdbm
863 test_gl
864 test_gzip
865 test_imgfile
866 test_largefile
867 test_linuxaudiodev
868 test_locale
869 test_minidom
870 test_nis
871 test_ntpath
872 test_openpty
873 test_pyexpat
874 test_sax
Skip Montanarob3230212002-03-15 02:54:03 +0000875 test_sunaudiodev
Skip Montanarob3230212002-03-15 02:54:03 +0000876 test_zipfile
877 test_zlib
878 """,
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000879 'atheos':
Tim Petersc411dba2002-07-16 21:35:23 +0000880 """
881 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000882 test_applesingle
Skip Montanaro823ba282003-05-06 20:36:24 +0000883 test_bsddb185
Tim Petersc411dba2002-07-16 21:35:23 +0000884 test_cd
885 test_cl
886 test_curses
887 test_dl
Tim Petersc411dba2002-07-16 21:35:23 +0000888 test_gdbm
889 test_gl
890 test_imgfile
891 test_largefile
892 test_linuxaudiodev
893 test_locale
894 test_mhlib
895 test_mmap
896 test_mpz
897 test_nis
898 test_poll
899 test_popen2
900 test_resource
Tim Petersc411dba2002-07-16 21:35:23 +0000901 test_sunaudiodev
Tim Petersc411dba2002-07-16 21:35:23 +0000902 """,
Jason Tishler25115942002-12-05 15:18:15 +0000903 'cygwin':
904 """
905 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000906 test_applesingle
Skip Montanaro823ba282003-05-06 20:36:24 +0000907 test_bsddb185
Tim Petersb0f89e02002-12-05 17:20:25 +0000908 test_bsddb3
Jason Tishler25115942002-12-05 15:18:15 +0000909 test_cd
910 test_cl
911 test_curses
912 test_dbm
Jason Tishler25115942002-12-05 15:18:15 +0000913 test_gl
914 test_imgfile
Jason Tishlerc23f39c2003-07-22 18:35:58 +0000915 test_ioctl
Jason Tishler25115942002-12-05 15:18:15 +0000916 test_largefile
917 test_linuxaudiodev
918 test_locale
919 test_mpz
920 test_nis
Jason Tishler5c4ded22003-02-05 16:46:01 +0000921 test_ossaudiodev
Jason Tishler25115942002-12-05 15:18:15 +0000922 test_socketserver
923 test_sunaudiodev
Jason Tishler25115942002-12-05 15:18:15 +0000924 """,
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000925 'os2emx':
926 """
927 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000928 test_applesingle
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000929 test_audioop
Skip Montanaro823ba282003-05-06 20:36:24 +0000930 test_bsddb185
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000931 test_bsddb3
932 test_cd
933 test_cl
934 test_commands
935 test_curses
936 test_dl
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000937 test_gl
938 test_imgfile
939 test_largefile
940 test_linuxaudiodev
941 test_mhlib
942 test_mmap
943 test_nis
944 test_openpty
945 test_ossaudiodev
946 test_pty
947 test_resource
948 test_signal
949 test_sunaudiodev
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000950 """,
Guido van Rossum944a6c32003-11-20 22:11:29 +0000951 'freebsd4':
952 """
953 test_aepack
954 test_al
955 test_applesingle
956 test_bsddb
957 test_bsddb3
958 test_cd
959 test_cl
Guido van Rossum944a6c32003-11-20 22:11:29 +0000960 test_gl
961 test_imgfile
962 test_linuxaudiodev
963 test_locale
964 test_macfs
965 test_macostools
966 test_nis
967 test_normalization
968 test_ossaudiodev
969 test_pep277
970 test_plistlib
971 test_scriptpackages
972 test_socket_ssl
973 test_socketserver
974 test_sunaudiodev
975 test_timeout
976 test_unicode_file
977 test_urllibnet
978 test_winreg
979 test_winsound
Martin v. Löwis56f88112003-06-07 20:01:37 +0000980 """,
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000981}
982
Tim Petersb5b7b782001-08-12 01:20:39 +0000983class _ExpectedSkips:
984 def __init__(self):
Tim Peters2a182db2002-10-09 01:07:11 +0000985 import os.path
Tim Peters1b445d32002-11-24 18:53:11 +0000986 from test import test_normalization
Tim Petersb4ee4eb2002-12-04 03:26:57 +0000987 from test import test_socket_ssl
Neal Norwitz55b61d22003-02-28 19:57:03 +0000988 from test import test_timeout
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +0000989 from test import test_codecmaps_cn, test_codecmaps_jp
990 from test import test_codecmaps_kr, test_codecmaps_tw
Hye-Shik Chang5ef60182004-07-19 06:39:37 +0000991 from test import test_codecmaps_hk
Tim Peters1b445d32002-11-24 18:53:11 +0000992
Tim Peters7c7efe92002-08-23 17:55:54 +0000993 self.valid = False
Tim Petersde14a302002-04-01 05:04:46 +0000994 if sys.platform in _expectations:
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000995 s = _expectations[sys.platform]
Raymond Hettingera690a992003-11-16 16:17:49 +0000996 self.expected = set(s.split())
Tim Peters1b445d32002-11-24 18:53:11 +0000997
Tim Peters2a182db2002-10-09 01:07:11 +0000998 if not os.path.supports_unicode_filenames:
999 self.expected.add('test_pep277')
Tim Peters1b445d32002-11-24 18:53:11 +00001000
1001 if test_normalization.skip_expected:
1002 self.expected.add('test_normalization')
1003
Tim Petersb4ee4eb2002-12-04 03:26:57 +00001004 if test_socket_ssl.skip_expected:
1005 self.expected.add('test_socket_ssl')
1006
Neal Norwitz55b61d22003-02-28 19:57:03 +00001007 if test_timeout.skip_expected:
1008 self.expected.add('test_timeout')
1009
Hye-Shik Chang5ef60182004-07-19 06:39:37 +00001010 for cc in ('cn', 'jp', 'kr', 'tw', 'hk'):
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001011 if eval('test_codecmaps_' + cc).skip_expected:
1012 self.expected.add('test_codecmaps_' + cc)
1013
Jack Jansen6afc5e02003-01-29 16:24:16 +00001014 if not sys.platform in ("mac", "darwin"):
Neal Norwitz7035c982003-03-29 22:01:17 +00001015 MAC_ONLY = ["test_macostools", "test_macfs", "test_aepack",
1016 "test_plistlib", "test_scriptpackages"]
1017 for skip in MAC_ONLY:
1018 self.expected.add(skip)
Tim Petersecd79eb2003-01-29 00:35:32 +00001019
1020 if sys.platform != "win32":
Neal Norwitz7035c982003-03-29 22:01:17 +00001021 WIN_ONLY = ["test_unicode_file", "test_winreg",
1022 "test_winsound"]
1023 for skip in WIN_ONLY:
1024 self.expected.add(skip)
Tim Petersf2715e02003-02-19 02:35:07 +00001025
Tim Peters7c7efe92002-08-23 17:55:54 +00001026 self.valid = True
Tim Petersb5b7b782001-08-12 01:20:39 +00001027
1028 def isvalid(self):
1029 "Return true iff _ExpectedSkips knows about the current platform."
1030 return self.valid
1031
1032 def getexpected(self):
1033 """Return set of test names we expect to skip on current platform.
1034
1035 self.isvalid() must be true.
1036 """
1037
1038 assert self.isvalid()
1039 return self.expected
1040
Guido van Rossum152494a1996-12-20 03:12:20 +00001041if __name__ == '__main__':
Barry Warsaw408b6d32002-07-30 23:27:12 +00001042 # Remove regrtest.py's own directory from the module search path. This
1043 # prevents relative imports from working, and relative imports will screw
1044 # up the testing framework. E.g. if both test.test_support and
1045 # test_support are imported, they will not contain the same globals, and
1046 # much of the testing framework relies on the globals in the
1047 # test.test_support module.
1048 mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
1049 i = pathlen = len(sys.path)
1050 while i >= 0:
1051 i -= 1
1052 if os.path.abspath(os.path.normpath(sys.path[i])) == mydir:
1053 del sys.path[i]
1054 if len(sys.path) == pathlen:
1055 print 'Could not find %r in sys.path to remove it' % mydir
Barry Warsaw08fca522001-08-20 22:33:46 +00001056 main()