blob: 8f5da02906b0e78595cd69d10aacad70ce341a02 [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
Guido van Rossum152494a1996-12-20 03:12:20 +000023
24If non-option arguments are present, they are names for tests to run,
25unless -x is given, in which case they are names for tests not to run.
26If no test names are given, all tests are run.
Guido van Rossumf58ed251997-03-07 21:04:33 +000027
Guido van Rossuma4122201997-08-18 20:08:24 +000028-v is incompatible with -g and does not compare test output files.
Barry Warsawe11e3de1999-01-28 19:51:51 +000029
Barry Warsaw3b6d0252004-02-07 22:43:03 +000030-T turns on code coverage tracing with the trace module.
31
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000032-s means to run only a single test and exit. This is useful when
33doing memory analysis on the Python interpreter (which tend to consume
34too many resources to run the full regression test non-stop). The
35file /tmp/pynexttest is read to find the next test to run. If this
36file is missing, the first test_*.py file in testdir or on the command
37line is used. (actually tempfile.gettempdir() is used instead of
38/tmp).
Barry Warsawe11e3de1999-01-28 19:51:51 +000039
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000040-f reads the names of tests from the file given as f's argument, one
41or more test names per line. Whitespace is ignored. Blank lines and
42lines beginning with '#' are ignored. This is especially useful for
43whittling down failures involving interactions among tests.
Tim Petersc5000df2002-06-02 21:42:01 +000044
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000045-u is used to specify which special resource intensive tests to run,
46such as those requiring large file support or network connectivity.
47The argument is a comma-separated list of words indicating the
48resources to test. Currently only the following are defined:
Barry Warsaw08fca522001-08-20 22:33:46 +000049
Fred Drake3a15dac2002-04-11 16:39:16 +000050 all - Enable all special resources.
51
Guido van Rossum315aa362003-03-11 14:46:48 +000052 audio - Tests that use the audio device. (There are known
53 cases of broken audio drivers that can crash Python or
54 even the Linux kernel.)
55
Andrew M. Kuchling2158df02001-10-22 15:26:09 +000056 curses - Tests that use curses and will modify the terminal's
57 state and output modes.
Tim Peters1633a2e2001-10-30 05:56:40 +000058
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000059 largefile - It is okay to run some test that may create huge
60 files. These tests can take a long time and may
61 consume >2GB of disk space temporarily.
Barry Warsaw08fca522001-08-20 22:33:46 +000062
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000063 network - It is okay to run tests that use external network
64 resource, e.g. testing SSL support for sockets.
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000065
66 bsddb - It is okay to run the bsddb testsuite, which takes
67 a long time to complete.
Fred Drake4dd0f7e2002-11-26 21:44:56 +000068
69To enable all resources except one, use '-uall,-<resource>'. For
70example, to run all the tests except for the bsddb tests, give the
71option '-uall,-bsddb'.
Guido van Rossum152494a1996-12-20 03:12:20 +000072"""
73
Guido van Rossum152494a1996-12-20 03:12:20 +000074import os
Barry Warsaw3b6d0252004-02-07 22:43:03 +000075import sys
Guido van Rossum152494a1996-12-20 03:12:20 +000076import getopt
Skip Montanaroab1c7912000-06-30 16:39:27 +000077import random
Guido van Rossumdc15c272002-08-12 21:55:51 +000078import warnings
Barry Warsaw3b6d0252004-02-07 22:43:03 +000079import cStringIO
80import traceback
Guido van Rossumdc15c272002-08-12 21:55:51 +000081
82# I see no other way to suppress these warnings;
83# putting them in test_grammar.py has no effect:
Guido van Rossum88b1def2002-08-14 17:54:48 +000084warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
Guido van Rossumdc15c272002-08-12 21:55:51 +000085 ".*test.test_grammar$")
Guido van Rossumc34c4fc2002-09-19 00:42:16 +000086if sys.maxint > 0x7fffffff:
87 # Also suppress them in <string>, because for 64-bit platforms,
88 # that's where test_grammar.py hides them.
89 warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
90 "<string>")
Guido van Rossum152494a1996-12-20 03:12:20 +000091
Guido van Rossumbb484652002-12-02 09:56:21 +000092# MacOSX (a.k.a. Darwin) has a default stack size that is too small
93# for deeply recursive regular expressions. We see this as crashes in
94# the Python test suite when running test_re.py and test_sre.py. The
95# fix is to set the stack limit to 2048.
96# This approach may also be useful for other Unixy platforms that
97# suffer from small default stack limits.
98if sys.platform == 'darwin':
99 try:
100 import resource
101 except ImportError:
102 pass
103 else:
104 soft, hard = resource.getrlimit(resource.RLIMIT_STACK)
105 newsoft = min(hard, max(soft, 1024*2048))
106 resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard))
107
Barry Warsaw04f357c2002-07-23 19:04:11 +0000108from test import test_support
Fred Drake3a15dac2002-04-11 16:39:16 +0000109
Guido van Rossum315aa362003-03-11 14:46:48 +0000110RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', 'bsddb')
Fred Drake3a15dac2002-04-11 16:39:16 +0000111
112
Barry Warsaw08fca522001-08-20 22:33:46 +0000113def usage(code, msg=''):
114 print __doc__
115 if msg: print msg
116 sys.exit(code)
117
118
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000119def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
120 exclude=False, single=False, randomize=False, fromfile=None,
121 findleaks=False, use_resources=None, trace=False):
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000122 """Execute a test suite.
123
Thomas Wouters7e474022000-07-16 12:04:32 +0000124 This also parses command-line options and modifies its behavior
Fred Drake004d5e62000-10-23 17:22:08 +0000125 accordingly.
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000126
127 tests -- a list of strings containing test names (optional)
128 testdir -- the directory in which to look for tests (optional)
129
130 Users other than the Python test suite will certainly want to
131 specify testdir; if it's omitted, the directory containing the
Fred Drake004d5e62000-10-23 17:22:08 +0000132 Python test suite is searched for.
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000133
134 If the tests argument is omitted, the tests listed on the
135 command-line will be used. If that's empty, too, then all *.py
136 files beginning with test_ will be used.
Skip Montanaroab1c7912000-06-30 16:39:27 +0000137
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000138 The other default arguments (verbose, quiet, generate, exclude, single,
139 randomize, findleaks, use_resources, and trace) allow programmers calling
140 main() directly to set the values that would normally be set by flags on
141 the command line.
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000142 """
Fred Drake004d5e62000-10-23 17:22:08 +0000143
Tim Peters8dee8092001-09-25 20:05:11 +0000144 test_support.record_original_stdout(sys.stdout)
Guido van Rossum152494a1996-12-20 03:12:20 +0000145 try:
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000146 opts, args = getopt.getopt(sys.argv[1:], 'hvgqxsrf:lu:t:T',
Barry Warsaw08fca522001-08-20 22:33:46 +0000147 ['help', 'verbose', 'quiet', 'generate',
Tim Petersc5000df2002-06-02 21:42:01 +0000148 'exclude', 'single', 'random', 'fromfile',
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000149 'findleaks', 'use=', 'threshold=', 'trace',
150 ])
Guido van Rossum152494a1996-12-20 03:12:20 +0000151 except getopt.error, msg:
Barry Warsaw08fca522001-08-20 22:33:46 +0000152 usage(2, msg)
153
154 # Defaults
155 if use_resources is None:
156 use_resources = []
Guido van Rossum152494a1996-12-20 03:12:20 +0000157 for o, a in opts:
Barry Warsaw08fca522001-08-20 22:33:46 +0000158 if o in ('-h', '--help'):
159 usage(0)
160 elif o in ('-v', '--verbose'):
161 verbose += 1
162 elif o in ('-q', '--quiet'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000163 quiet = True;
Barry Warsaw08fca522001-08-20 22:33:46 +0000164 verbose = 0
165 elif o in ('-g', '--generate'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000166 generate = True
Barry Warsaw08fca522001-08-20 22:33:46 +0000167 elif o in ('-x', '--exclude'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000168 exclude = True
Barry Warsaw08fca522001-08-20 22:33:46 +0000169 elif o in ('-s', '--single'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000170 single = True
Barry Warsaw08fca522001-08-20 22:33:46 +0000171 elif o in ('-r', '--randomize'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000172 randomize = True
Tim Petersc5000df2002-06-02 21:42:01 +0000173 elif o in ('-f', '--fromfile'):
174 fromfile = a
Barry Warsaw08fca522001-08-20 22:33:46 +0000175 elif o in ('-l', '--findleaks'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000176 findleaks = True
Guido van Rossum9e9d4f82002-06-07 15:17:03 +0000177 elif o in ('-t', '--threshold'):
178 import gc
179 gc.set_threshold(int(a))
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000180 elif o in ('-T', '--coverage'):
181 trace = True
Barry Warsaw08fca522001-08-20 22:33:46 +0000182 elif o in ('-u', '--use'):
Guido van Rossumfe3f6962001-09-06 16:09:41 +0000183 u = [x.lower() for x in a.split(',')]
184 for r in u:
Fred Drake3a15dac2002-04-11 16:39:16 +0000185 if r == 'all':
Fred Drake4dd0f7e2002-11-26 21:44:56 +0000186 use_resources[:] = RESOURCE_NAMES
187 continue
188 remove = False
189 if r[0] == '-':
190 remove = True
191 r = r[1:]
Fred Drake3a15dac2002-04-11 16:39:16 +0000192 if r not in RESOURCE_NAMES:
193 usage(1, 'Invalid -u/--use option: ' + a)
Fred Drake4dd0f7e2002-11-26 21:44:56 +0000194 if remove:
195 if r in use_resources:
196 use_resources.remove(r)
197 elif r not in use_resources:
Andrew MacIntyree41abab2002-04-30 12:11:04 +0000198 use_resources.append(r)
Guido van Rossuma4122201997-08-18 20:08:24 +0000199 if generate and verbose:
Barry Warsaw08fca522001-08-20 22:33:46 +0000200 usage(2, "-g and -v don't go together!")
Tim Petersc5000df2002-06-02 21:42:01 +0000201 if single and fromfile:
202 usage(2, "-s and -f don't go together!")
Barry Warsaw08fca522001-08-20 22:33:46 +0000203
Guido van Rossum152494a1996-12-20 03:12:20 +0000204 good = []
205 bad = []
206 skipped = []
Fred Drake9a0db072003-02-03 15:19:30 +0000207 resource_denieds = []
Barry Warsawe11e3de1999-01-28 19:51:51 +0000208
Neil Schemenauerd569f232000-09-22 15:29:28 +0000209 if findleaks:
Barry Warsawa873b032000-08-03 15:50:37 +0000210 try:
211 import gc
212 except ImportError:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000213 print 'No GC available, disabling findleaks.'
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000214 findleaks = False
Barry Warsawa873b032000-08-03 15:50:37 +0000215 else:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000216 # Uncomment the line below to report garbage that is not
217 # freeable by reference counting alone. By default only
218 # garbage that is not collectable by the GC is reported.
219 #gc.set_debug(gc.DEBUG_SAVEALL)
Neil Schemenauerd569f232000-09-22 15:29:28 +0000220 found_garbage = []
Barry Warsawa873b032000-08-03 15:50:37 +0000221
Barry Warsawe11e3de1999-01-28 19:51:51 +0000222 if single:
223 from tempfile import gettempdir
224 filename = os.path.join(gettempdir(), 'pynexttest')
225 try:
226 fp = open(filename, 'r')
Eric S. Raymondfc170b12001-02-09 11:51:27 +0000227 next = fp.read().strip()
Barry Warsawe11e3de1999-01-28 19:51:51 +0000228 tests = [next]
229 fp.close()
230 except IOError:
231 pass
Tim Petersc5000df2002-06-02 21:42:01 +0000232
233 if fromfile:
234 tests = []
235 fp = open(fromfile)
236 for line in fp:
237 guts = line.split() # assuming no test has whitespace in its name
238 if guts and not guts[0].startswith('#'):
239 tests.extend(guts)
240 fp.close()
241
242 # Strip .py extensions.
243 if args:
244 args = map(removepy, args)
245 if tests:
246 tests = map(removepy, tests)
247
Guido van Rossum6c74fea1998-08-25 12:29:08 +0000248 stdtests = STDTESTS[:]
249 nottests = NOTTESTS[:]
Guido van Rossum152494a1996-12-20 03:12:20 +0000250 if exclude:
Guido van Rossum6c74fea1998-08-25 12:29:08 +0000251 for arg in args:
252 if arg in stdtests:
253 stdtests.remove(arg)
254 nottests[:0] = args
Guido van Rossum41360a41998-03-26 19:42:58 +0000255 args = []
Guido van Rossum747e1ca1998-08-24 13:48:36 +0000256 tests = tests or args or findtests(testdir, stdtests, nottests)
Barry Warsawe11e3de1999-01-28 19:51:51 +0000257 if single:
258 tests = tests[:1]
Skip Montanaroab1c7912000-06-30 16:39:27 +0000259 if randomize:
260 random.shuffle(tests)
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000261 if trace:
262 import trace
263 tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix],
264 trace=False, count=True)
265 coverdir = os.path.join(os.getcwd(), 'coverage')
Guido van Rossum41360a41998-03-26 19:42:58 +0000266 test_support.verbose = verbose # Tell tests to be moderately quiet
Barry Warsaw08fca522001-08-20 22:33:46 +0000267 test_support.use_resources = use_resources
Guido van Rossum5796d262000-04-21 21:35:06 +0000268 save_modules = sys.modules.keys()
Guido van Rossum152494a1996-12-20 03:12:20 +0000269 for test in tests:
Guido van Rossum41360a41998-03-26 19:42:58 +0000270 if not quiet:
271 print test
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000272 sys.stdout.flush()
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000273 if trace:
274 # If we're tracing code coverage, then we don't exit with status
275 # if on a false return value from main.
276 tracer.runctx('runtest(test, generate, verbose, quiet, testdir)',
277 globals=globals(), locals=vars())
Guido van Rossum41360a41998-03-26 19:42:58 +0000278 else:
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000279 ok = runtest(test, generate, verbose, quiet, testdir)
280 if ok > 0:
281 good.append(test)
282 elif ok == 0:
283 bad.append(test)
284 else:
285 skipped.append(test)
286 if ok == -2:
287 resource_denieds.append(test)
Neil Schemenauerd569f232000-09-22 15:29:28 +0000288 if findleaks:
289 gc.collect()
290 if gc.garbage:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000291 print "Warning: test created", len(gc.garbage),
292 print "uncollectable object(s)."
293 # move the uncollectable objects somewhere so we don't see
294 # them again
Neil Schemenauerd569f232000-09-22 15:29:28 +0000295 found_garbage.extend(gc.garbage)
296 del gc.garbage[:]
Guido van Rossum5796d262000-04-21 21:35:06 +0000297 # Unload the newly imported modules (best effort finalization)
298 for module in sys.modules.keys():
Guido van Rossum51931142000-05-05 14:27:39 +0000299 if module not in save_modules and module.startswith("test."):
Guido van Rossum5796d262000-04-21 21:35:06 +0000300 test_support.unload(module)
Jeremy Hylton7a1ea0e2001-10-17 13:45:28 +0000301
302 # The lists won't be sorted if running with -r
303 good.sort()
304 bad.sort()
305 skipped.sort()
Tim Peterse0c446b2001-10-18 21:57:37 +0000306
Guido van Rossum152494a1996-12-20 03:12:20 +0000307 if good and not quiet:
Guido van Rossum41360a41998-03-26 19:42:58 +0000308 if not bad and not skipped and len(good) > 1:
309 print "All",
310 print count(len(good), "test"), "OK."
Tim Peters1a4d77b2000-12-30 22:21:22 +0000311 if verbose:
Barry Warsaw408b6d32002-07-30 23:27:12 +0000312 print "CAUTION: stdout isn't compared in verbose mode:"
313 print "a test that passes in verbose mode may fail without it."
Guido van Rossum152494a1996-12-20 03:12:20 +0000314 if bad:
Tim Petersa45da922001-08-12 03:45:50 +0000315 print count(len(bad), "test"), "failed:"
316 printlist(bad)
Guido van Rossum152494a1996-12-20 03:12:20 +0000317 if skipped and not quiet:
Tim Petersa45da922001-08-12 03:45:50 +0000318 print count(len(skipped), "test"), "skipped:"
319 printlist(skipped)
Barry Warsawe11e3de1999-01-28 19:51:51 +0000320
Tim Petersb5b7b782001-08-12 01:20:39 +0000321 e = _ExpectedSkips()
Tim Petersa2be2d62001-08-12 02:01:09 +0000322 plat = sys.platform
Tim Petersb5b7b782001-08-12 01:20:39 +0000323 if e.isvalid():
Raymond Hettingera690a992003-11-16 16:17:49 +0000324 surprise = set(skipped) - e.getexpected() - set(resource_denieds)
Tim Petersb5b7b782001-08-12 01:20:39 +0000325 if surprise:
326 print count(len(surprise), "skip"), \
Tim Petersa45da922001-08-12 03:45:50 +0000327 "unexpected on", plat + ":"
328 printlist(surprise)
Tim Petersb5b7b782001-08-12 01:20:39 +0000329 else:
330 print "Those skips are all expected on", plat + "."
331 else:
332 print "Ask someone to teach regrtest.py about which tests are"
333 print "expected to get skipped on", plat + "."
334
Barry Warsawe11e3de1999-01-28 19:51:51 +0000335 if single:
336 alltests = findtests(testdir, stdtests, nottests)
337 for i in range(len(alltests)):
338 if tests[0] == alltests[i]:
339 if i == len(alltests) - 1:
340 os.unlink(filename)
341 else:
342 fp = open(filename, 'w')
343 fp.write(alltests[i+1] + '\n')
344 fp.close()
345 break
346 else:
347 os.unlink(filename)
348
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000349 if trace:
350 r = tracer.results()
351 r.write_results(show_missing=True, summary=True, coverdir=coverdir)
352
Tim Peters5943b4a2003-07-23 00:30:39 +0000353 sys.exit(len(bad) > 0)
Barry Warsaw08fca522001-08-20 22:33:46 +0000354
Guido van Rossum152494a1996-12-20 03:12:20 +0000355
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000356STDTESTS = [
Guido van Rossum152494a1996-12-20 03:12:20 +0000357 'test_grammar',
358 'test_opcodes',
359 'test_operations',
360 'test_builtin',
361 'test_exceptions',
362 'test_types',
363 ]
364
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000365NOTTESTS = [
Guido van Rossum152494a1996-12-20 03:12:20 +0000366 'test_support',
Jeremy Hylton62e2c7e2001-02-28 17:48:06 +0000367 'test_future1',
368 'test_future2',
Jeremy Hylton8471a352001-08-20 20:33:42 +0000369 'test_future3',
Guido van Rossum152494a1996-12-20 03:12:20 +0000370 ]
371
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000372def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
Guido van Rossum152494a1996-12-20 03:12:20 +0000373 """Return a list of all applicable test modules."""
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000374 if not testdir: testdir = findtestdir()
Guido van Rossum152494a1996-12-20 03:12:20 +0000375 names = os.listdir(testdir)
376 tests = []
377 for name in names:
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000378 if name[:5] == "test_" and name[-3:] == os.extsep+"py":
Guido van Rossum41360a41998-03-26 19:42:58 +0000379 modname = name[:-3]
380 if modname not in stdtests and modname not in nottests:
381 tests.append(modname)
Guido van Rossum152494a1996-12-20 03:12:20 +0000382 tests.sort()
383 return stdtests + tests
384
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000385def runtest(test, generate, verbose, quiet, testdir=None):
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000386 """Run a single test.
387 test -- the name of the test
388 generate -- if true, generate output, instead of running the test
389 and comparing it to a previously created output file
390 verbose -- if true, print more messages
Trent Mickf29f47b2000-08-11 19:02:59 +0000391 quiet -- if true, don't print 'skipped' messages (probably redundant)
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000392 testdir -- test directory
393 """
Guido van Rossum152494a1996-12-20 03:12:20 +0000394 test_support.unload(test)
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000395 if not testdir:
396 testdir = findtestdir()
Guido van Rossum152494a1996-12-20 03:12:20 +0000397 outputdir = os.path.join(testdir, "output")
398 outputfile = os.path.join(outputdir, test)
Tim Peters9390cc12001-09-28 20:14:46 +0000399 if verbose:
Guido van Rossum41360a41998-03-26 19:42:58 +0000400 cfp = None
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000401 else:
Raymond Hettinger74e67662003-05-17 20:44:12 +0000402 cfp = cStringIO.StringIO()
Guido van Rossum152494a1996-12-20 03:12:20 +0000403 try:
Tim Peters342ca752001-09-25 19:13:20 +0000404 save_stdout = sys.stdout
Guido van Rossum41360a41998-03-26 19:42:58 +0000405 try:
406 if cfp:
407 sys.stdout = cfp
408 print test # Output file starts with test name
Barry Warsaw408b6d32002-07-30 23:27:12 +0000409 if test.startswith('test.'):
410 abstest = test
411 else:
412 # Always import it from the test package
413 abstest = 'test.' + test
414 the_package = __import__(abstest, globals(), locals(), [])
415 the_module = getattr(the_package, test)
Tim Petersd9742212001-05-22 18:28:25 +0000416 # Most tests run to completion simply as a side-effect of
417 # being imported. For the benefit of tests that can't run
418 # that way (like test_threaded_import), explicitly invoke
419 # their test_main() function (if it exists).
420 indirect_test = getattr(the_module, "test_main", None)
421 if indirect_test is not None:
422 indirect_test()
Guido van Rossum41360a41998-03-26 19:42:58 +0000423 finally:
Tim Peters342ca752001-09-25 19:13:20 +0000424 sys.stdout = save_stdout
Fred Drake9a0db072003-02-03 15:19:30 +0000425 except test_support.ResourceDenied, msg:
426 if not quiet:
427 print test, "skipped --", msg
428 sys.stdout.flush()
429 return -2
Thomas Wouters3af826e2000-08-04 13:17:51 +0000430 except (ImportError, test_support.TestSkipped), msg:
Trent Mickf29f47b2000-08-11 19:02:59 +0000431 if not quiet:
Fred Drakede4742b2002-10-17 20:36:08 +0000432 print test, "skipped --", msg
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000433 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000434 return -1
Fred Drakefe5c22a2000-08-18 16:04:05 +0000435 except KeyboardInterrupt:
436 raise
Guido van Rossum152494a1996-12-20 03:12:20 +0000437 except test_support.TestFailed, msg:
Guido van Rossum41360a41998-03-26 19:42:58 +0000438 print "test", test, "failed --", msg
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000439 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000440 return 0
Guido van Rossum9e48b271997-07-16 01:56:13 +0000441 except:
Guido van Rossum41360a41998-03-26 19:42:58 +0000442 type, value = sys.exc_info()[:2]
Fred Drake27c4b392000-08-23 20:34:40 +0000443 print "test", test, "crashed --", str(type) + ":", value
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000444 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000445 if verbose:
446 traceback.print_exc(file=sys.stdout)
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000447 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000448 return 0
Guido van Rossum152494a1996-12-20 03:12:20 +0000449 else:
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000450 if not cfp:
451 return 1
452 output = cfp.getvalue()
Fred Drakee51fe8d2001-05-29 17:10:51 +0000453 if generate:
Fred Drakee51fe8d2001-05-29 17:10:51 +0000454 if output == test + "\n":
455 if os.path.exists(outputfile):
456 # Write it since it already exists (and the contents
457 # may have changed), but let the user know it isn't
458 # needed:
Fred Drakee51fe8d2001-05-29 17:10:51 +0000459 print "output file", outputfile, \
460 "is no longer needed; consider removing it"
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000461 else:
462 # We don't need it, so don't create it.
463 return 1
464 fp = open(outputfile, "w")
465 fp.write(output)
466 fp.close()
467 return 1
468 if os.path.exists(outputfile):
469 fp = open(outputfile, "r")
470 expected = fp.read()
471 fp.close()
472 else:
473 expected = test + "\n"
474 if output == expected:
475 return 1
476 print "test", test, "produced unexpected output:"
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000477 sys.stdout.flush()
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000478 reportdiff(expected, output)
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000479 sys.stdout.flush()
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000480 return 0
481
482def reportdiff(expected, output):
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000483 import difflib
Tim Petersc377b162001-09-22 05:31:03 +0000484 print "*" * 70
485 a = expected.splitlines(1)
486 b = output.splitlines(1)
Guido van Rossumcf691932001-09-21 21:06:22 +0000487 sm = difflib.SequenceMatcher(a=a, b=b)
488 tuples = sm.get_opcodes()
Tim Petersc377b162001-09-22 05:31:03 +0000489
Guido van Rossumcf691932001-09-21 21:06:22 +0000490 def pair(x0, x1):
Tim Petersc377b162001-09-22 05:31:03 +0000491 # x0:x1 are 0-based slice indices; convert to 1-based line indices.
Guido van Rossumcf691932001-09-21 21:06:22 +0000492 x0 += 1
493 if x0 >= x1:
Tim Petersc377b162001-09-22 05:31:03 +0000494 return "line " + str(x0)
Guido van Rossumcf691932001-09-21 21:06:22 +0000495 else:
Tim Petersc377b162001-09-22 05:31:03 +0000496 return "lines %d-%d" % (x0, x1)
497
Guido van Rossumcf691932001-09-21 21:06:22 +0000498 for op, a0, a1, b0, b1 in tuples:
499 if op == 'equal':
500 pass
Tim Petersc377b162001-09-22 05:31:03 +0000501
Guido van Rossumcf691932001-09-21 21:06:22 +0000502 elif op == 'delete':
Tim Petersc377b162001-09-22 05:31:03 +0000503 print "***", pair(a0, a1), "of expected output missing:"
Guido van Rossumcf691932001-09-21 21:06:22 +0000504 for line in a[a0:a1]:
Tim Petersc377b162001-09-22 05:31:03 +0000505 print "-", line,
506
Guido van Rossumcf691932001-09-21 21:06:22 +0000507 elif op == 'replace':
Tim Petersc377b162001-09-22 05:31:03 +0000508 print "*** mismatch between", pair(a0, a1), "of expected", \
509 "output and", pair(b0, b1), "of actual output:"
510 for line in difflib.ndiff(a[a0:a1], b[b0:b1]):
511 print line,
512
Guido van Rossumcf691932001-09-21 21:06:22 +0000513 elif op == 'insert':
Tim Petersc377b162001-09-22 05:31:03 +0000514 print "***", pair(b0, b1), "of actual output doesn't appear", \
515 "in expected output after line", str(a1)+":"
Guido van Rossumcf691932001-09-21 21:06:22 +0000516 for line in b[b0:b1]:
Tim Petersc377b162001-09-22 05:31:03 +0000517 print "+", line,
518
Guido van Rossumcf691932001-09-21 21:06:22 +0000519 else:
520 print "get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1)
Tim Petersc377b162001-09-22 05:31:03 +0000521
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000522 print "*" * 70
Guido van Rossum152494a1996-12-20 03:12:20 +0000523
524def findtestdir():
525 if __name__ == '__main__':
Guido van Rossum41360a41998-03-26 19:42:58 +0000526 file = sys.argv[0]
Guido van Rossum152494a1996-12-20 03:12:20 +0000527 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000528 file = __file__
Guido van Rossum152494a1996-12-20 03:12:20 +0000529 testdir = os.path.dirname(file) or os.curdir
530 return testdir
531
Tim Petersc5000df2002-06-02 21:42:01 +0000532def removepy(name):
533 if name.endswith(os.extsep + "py"):
534 name = name[:-3]
535 return name
536
Guido van Rossum152494a1996-12-20 03:12:20 +0000537def count(n, word):
538 if n == 1:
Guido van Rossum41360a41998-03-26 19:42:58 +0000539 return "%d %s" % (n, word)
Guido van Rossum152494a1996-12-20 03:12:20 +0000540 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000541 return "%d %ss" % (n, word)
Guido van Rossum152494a1996-12-20 03:12:20 +0000542
Tim Petersa45da922001-08-12 03:45:50 +0000543def printlist(x, width=70, indent=4):
Tim Peters7c7efe92002-08-23 17:55:54 +0000544 """Print the elements of iterable x to stdout.
Tim Petersa45da922001-08-12 03:45:50 +0000545
546 Optional arg width (default 70) is the maximum line length.
547 Optional arg indent (default 4) is the number of blanks with which to
548 begin each line.
549 """
550
Tim Petersba78bc42002-07-04 19:45:06 +0000551 from textwrap import fill
552 blanks = ' ' * indent
553 print fill(' '.join(map(str, x)), width,
554 initial_indent=blanks, subsequent_indent=blanks)
Tim Petersa45da922001-08-12 03:45:50 +0000555
Tim Petersde14a302002-04-01 05:04:46 +0000556# Map sys.platform to a string containing the basenames of tests
557# expected to be skipped on that platform.
Tim Peters2a182db2002-10-09 01:07:11 +0000558#
559# Special cases:
560# test_pep277
561# The _ExpectedSkips constructor adds this to the set of expected
562# skips if not os.path.supports_unicode_filenames.
Tim Peters1b445d32002-11-24 18:53:11 +0000563# test_normalization
564# Whether a skip is expected here depends on whether a large test
565# input file has been downloaded. test_normalization.skip_expected
Tim Peters1babdfc2002-11-24 19:19:09 +0000566# controls that.
Tim Petersb4ee4eb2002-12-04 03:26:57 +0000567# test_socket_ssl
568# Controlled by test_socket_ssl.skip_expected. Requires the network
569# resource, and a socket module with ssl support.
Neal Norwitz55b61d22003-02-28 19:57:03 +0000570# test_timeout
571# Controlled by test_timeout.skip_expected. Requires the network
572# resource and a socket module.
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +0000573# test_codecmaps_*
574# Whether a skip is expected here depends on whether a large test
575# input file has been downloaded. test_codecmaps_*.skip_expected
576# controls that.
Tim Petersde14a302002-04-01 05:04:46 +0000577
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000578_expectations = {
579 'win32':
580 """
Tim Petersc7c516a2003-09-20 22:06:13 +0000581 test__locale
Raymond Hettinger901dc982003-11-20 19:02:02 +0000582 test_applesingle
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000583 test_al
Skip Montanaro823ba282003-05-06 20:36:24 +0000584 test_bsddb185
Tim Peters78e35f92002-11-22 20:00:34 +0000585 test_bsddb3
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000586 test_cd
587 test_cl
588 test_commands
589 test_crypt
Tim Petersd7030572001-10-22 22:06:08 +0000590 test_curses
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000591 test_dbm
592 test_dl
593 test_fcntl
594 test_fork1
595 test_gdbm
596 test_gl
597 test_grp
598 test_imgfile
Tim Petersfd8e6e52003-03-04 00:26:38 +0000599 test_ioctl
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000600 test_largefile
601 test_linuxaudiodev
602 test_mhlib
Tim Petersde14a302002-04-01 05:04:46 +0000603 test_mpz
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000604 test_nis
605 test_openpty
Tim Petersefc4b122002-12-10 18:47:56 +0000606 test_ossaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000607 test_poll
Tim Peters003eb302003-02-17 21:48:48 +0000608 test_posix
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000609 test_pty
610 test_pwd
Tim Peters1e33ffa2002-04-23 23:09:02 +0000611 test_resource
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000612 test_signal
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000613 test_sunaudiodev
614 test_timing
615 """,
616 'linux2':
617 """
618 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000619 test_applesingle
Skip Montanaro823ba282003-05-06 20:36:24 +0000620 test_bsddb185
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000621 test_cd
622 test_cl
Guido van Rossumf66dacd2001-10-23 15:10:55 +0000623 test_curses
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000624 test_dl
625 test_gl
626 test_imgfile
627 test_largefile
Guido van Rossum4507ec72003-02-14 19:29:22 +0000628 test_linuxaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000629 test_nis
630 test_ntpath
Guido van Rossum4507ec72003-02-14 19:29:22 +0000631 test_ossaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000632 test_sunaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000633 """,
Jack Jansen49a806e2001-08-28 14:49:00 +0000634 'mac':
Guido van Rossumaa782362001-09-02 03:58:41 +0000635 """
636 test_al
Jack Jansen67975142003-01-08 16:31:11 +0000637 test_atexit
Guido van Rossumaa782362001-09-02 03:58:41 +0000638 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000639 test_bsddb185
Jack Jansen67975142003-01-08 16:31:11 +0000640 test_bsddb3
641 test_bz2
Guido van Rossumaa782362001-09-02 03:58:41 +0000642 test_cd
643 test_cl
644 test_commands
645 test_crypt
Jack Jansenb3be2162001-11-30 14:16:36 +0000646 test_curses
Guido van Rossumaa782362001-09-02 03:58:41 +0000647 test_dbm
648 test_dl
649 test_fcntl
650 test_fork1
651 test_gl
652 test_grp
Jack Jansenc4d6bdd2003-03-07 15:38:11 +0000653 test_ioctl
Guido van Rossumaa782362001-09-02 03:58:41 +0000654 test_imgfile
655 test_largefile
656 test_linuxaudiodev
657 test_locale
658 test_mmap
Jack Jansen67975142003-01-08 16:31:11 +0000659 test_mpz
Guido van Rossumaa782362001-09-02 03:58:41 +0000660 test_nis
661 test_ntpath
662 test_openpty
Jack Jansen67975142003-01-08 16:31:11 +0000663 test_ossaudiodev
Guido van Rossumaa782362001-09-02 03:58:41 +0000664 test_poll
Jack Jansen67975142003-01-08 16:31:11 +0000665 test_popen
Guido van Rossumaa782362001-09-02 03:58:41 +0000666 test_popen2
Jack Jansen5bb97e62003-02-21 22:33:55 +0000667 test_posix
Guido van Rossumaa782362001-09-02 03:58:41 +0000668 test_pty
669 test_pwd
Jack Jansen67975142003-01-08 16:31:11 +0000670 test_resource
Guido van Rossumaa782362001-09-02 03:58:41 +0000671 test_signal
Guido van Rossumaa782362001-09-02 03:58:41 +0000672 test_sunaudiodev
673 test_sundry
Jack Jansenc4d6bdd2003-03-07 15:38:11 +0000674 test_tarfile
Guido van Rossumaa782362001-09-02 03:58:41 +0000675 test_timing
Guido van Rossumaa782362001-09-02 03:58:41 +0000676 """,
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000677 'unixware7':
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000678 """
679 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000680 test_applesingle
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000681 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000682 test_bsddb185
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000683 test_cd
684 test_cl
685 test_dl
686 test_gl
687 test_imgfile
688 test_largefile
689 test_linuxaudiodev
690 test_minidom
691 test_nis
692 test_ntpath
693 test_openpty
694 test_pyexpat
695 test_sax
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000696 test_sunaudiodev
697 test_sundry
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000698 """,
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000699 'openunix8':
700 """
701 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000702 test_applesingle
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000703 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000704 test_bsddb185
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000705 test_cd
706 test_cl
707 test_dl
708 test_gl
709 test_imgfile
710 test_largefile
711 test_linuxaudiodev
712 test_minidom
713 test_nis
714 test_ntpath
715 test_openpty
716 test_pyexpat
717 test_sax
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000718 test_sunaudiodev
719 test_sundry
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000720 """,
721 'sco_sv3':
722 """
723 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000724 test_applesingle
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000725 test_asynchat
726 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000727 test_bsddb185
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000728 test_cd
729 test_cl
730 test_dl
731 test_fork1
732 test_gettext
733 test_gl
734 test_imgfile
735 test_largefile
736 test_linuxaudiodev
737 test_locale
738 test_minidom
739 test_nis
740 test_ntpath
741 test_openpty
742 test_pyexpat
743 test_queue
744 test_sax
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000745 test_sunaudiodev
746 test_sundry
747 test_thread
748 test_threaded_import
749 test_threadedtempfile
750 test_threading
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000751 """,
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000752 'riscos':
753 """
754 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000755 test_applesingle
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000756 test_asynchat
Martin v. Löwisa94568a2003-05-10 07:36:56 +0000757 test_atexit
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000758 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000759 test_bsddb185
Martin v. Löwisa94568a2003-05-10 07:36:56 +0000760 test_bsddb3
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000761 test_cd
762 test_cl
763 test_commands
764 test_crypt
765 test_dbm
766 test_dl
767 test_fcntl
768 test_fork1
769 test_gdbm
770 test_gl
771 test_grp
772 test_imgfile
773 test_largefile
774 test_linuxaudiodev
775 test_locale
776 test_mmap
777 test_nis
778 test_ntpath
779 test_openpty
780 test_poll
781 test_popen2
782 test_pty
783 test_pwd
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000784 test_strop
785 test_sunaudiodev
786 test_sundry
787 test_thread
788 test_threaded_import
789 test_threadedtempfile
790 test_threading
791 test_timing
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000792 """,
Jack Jansen8a97f4a2001-12-05 23:27:32 +0000793 'darwin':
Jack Jansen398c2362001-12-02 21:41:36 +0000794 """
Brett Cannon2bfb94c2003-10-13 04:27:47 +0000795 test__locale
Jack Jansen398c2362001-12-02 21:41:36 +0000796 test_al
Jack Jansenacda3392002-12-30 23:03:13 +0000797 test_bsddb
Guido van Rossum9d427002002-12-03 10:24:56 +0000798 test_bsddb3
Jack Jansen398c2362001-12-02 21:41:36 +0000799 test_cd
800 test_cl
801 test_curses
802 test_dl
803 test_gdbm
804 test_gl
805 test_imgfile
806 test_largefile
807 test_linuxaudiodev
Jack Jansenacda3392002-12-30 23:03:13 +0000808 test_locale
Jack Jansen398c2362001-12-02 21:41:36 +0000809 test_minidom
Guido van Rossum9d427002002-12-03 10:24:56 +0000810 test_mpz
Jack Jansen398c2362001-12-02 21:41:36 +0000811 test_nis
812 test_ntpath
Jack Jansenacda3392002-12-30 23:03:13 +0000813 test_ossaudiodev
Jack Jansen398c2362001-12-02 21:41:36 +0000814 test_poll
Jack Jansen398c2362001-12-02 21:41:36 +0000815 test_sunaudiodev
Jack Jansen398c2362001-12-02 21:41:36 +0000816 """,
Guido van Rossum11c3f092002-07-17 15:08:24 +0000817 'sunos5':
818 """
819 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000820 test_applesingle
Guido van Rossum11c3f092002-07-17 15:08:24 +0000821 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000822 test_bsddb185
Guido van Rossum11c3f092002-07-17 15:08:24 +0000823 test_cd
824 test_cl
825 test_curses
826 test_dbm
Guido van Rossum11c3f092002-07-17 15:08:24 +0000827 test_gdbm
828 test_gl
829 test_gzip
830 test_imgfile
831 test_linuxaudiodev
832 test_mpz
833 test_openpty
Guido van Rossum11c3f092002-07-17 15:08:24 +0000834 test_zipfile
835 test_zlib
Jeremy Hyltoned375e12002-07-17 15:56:55 +0000836 """,
Skip Montanarob3230212002-03-15 02:54:03 +0000837 'hp-ux11':
838 """
839 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000840 test_applesingle
Skip Montanarob3230212002-03-15 02:54:03 +0000841 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000842 test_bsddb185
Skip Montanarob3230212002-03-15 02:54:03 +0000843 test_cd
844 test_cl
845 test_curses
846 test_dl
847 test_gdbm
848 test_gl
849 test_gzip
850 test_imgfile
851 test_largefile
852 test_linuxaudiodev
853 test_locale
854 test_minidom
855 test_nis
856 test_ntpath
857 test_openpty
858 test_pyexpat
859 test_sax
Skip Montanarob3230212002-03-15 02:54:03 +0000860 test_sunaudiodev
Skip Montanarob3230212002-03-15 02:54:03 +0000861 test_zipfile
862 test_zlib
863 """,
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000864 'atheos':
Tim Petersc411dba2002-07-16 21:35:23 +0000865 """
866 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000867 test_applesingle
Skip Montanaro823ba282003-05-06 20:36:24 +0000868 test_bsddb185
Tim Petersc411dba2002-07-16 21:35:23 +0000869 test_cd
870 test_cl
871 test_curses
872 test_dl
Tim Petersc411dba2002-07-16 21:35:23 +0000873 test_gdbm
874 test_gl
875 test_imgfile
876 test_largefile
877 test_linuxaudiodev
878 test_locale
879 test_mhlib
880 test_mmap
881 test_mpz
882 test_nis
883 test_poll
884 test_popen2
885 test_resource
Tim Petersc411dba2002-07-16 21:35:23 +0000886 test_sunaudiodev
Tim Petersc411dba2002-07-16 21:35:23 +0000887 """,
Jason Tishler25115942002-12-05 15:18:15 +0000888 'cygwin':
889 """
890 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000891 test_applesingle
Skip Montanaro823ba282003-05-06 20:36:24 +0000892 test_bsddb185
Tim Petersb0f89e02002-12-05 17:20:25 +0000893 test_bsddb3
Jason Tishler25115942002-12-05 15:18:15 +0000894 test_cd
895 test_cl
896 test_curses
897 test_dbm
Jason Tishler25115942002-12-05 15:18:15 +0000898 test_gl
899 test_imgfile
Jason Tishlerc23f39c2003-07-22 18:35:58 +0000900 test_ioctl
Jason Tishler25115942002-12-05 15:18:15 +0000901 test_largefile
902 test_linuxaudiodev
903 test_locale
904 test_mpz
905 test_nis
Jason Tishler5c4ded22003-02-05 16:46:01 +0000906 test_ossaudiodev
Jason Tishler25115942002-12-05 15:18:15 +0000907 test_socketserver
908 test_sunaudiodev
Jason Tishler25115942002-12-05 15:18:15 +0000909 """,
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000910 'os2emx':
911 """
912 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000913 test_applesingle
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000914 test_audioop
Skip Montanaro823ba282003-05-06 20:36:24 +0000915 test_bsddb185
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000916 test_bsddb3
917 test_cd
918 test_cl
919 test_commands
920 test_curses
921 test_dl
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000922 test_gl
923 test_imgfile
924 test_largefile
925 test_linuxaudiodev
926 test_mhlib
927 test_mmap
928 test_nis
929 test_openpty
930 test_ossaudiodev
931 test_pty
932 test_resource
933 test_signal
934 test_sunaudiodev
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000935 """,
Guido van Rossum944a6c32003-11-20 22:11:29 +0000936 'freebsd4':
937 """
938 test_aepack
939 test_al
940 test_applesingle
941 test_bsddb
942 test_bsddb3
943 test_cd
944 test_cl
Guido van Rossum944a6c32003-11-20 22:11:29 +0000945 test_gl
946 test_imgfile
947 test_linuxaudiodev
948 test_locale
949 test_macfs
950 test_macostools
951 test_nis
952 test_normalization
953 test_ossaudiodev
954 test_pep277
955 test_plistlib
956 test_scriptpackages
957 test_socket_ssl
958 test_socketserver
959 test_sunaudiodev
960 test_timeout
961 test_unicode_file
962 test_urllibnet
963 test_winreg
964 test_winsound
Martin v. Löwis56f88112003-06-07 20:01:37 +0000965 """,
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000966}
967
Tim Petersb5b7b782001-08-12 01:20:39 +0000968class _ExpectedSkips:
969 def __init__(self):
Tim Peters2a182db2002-10-09 01:07:11 +0000970 import os.path
Tim Peters1b445d32002-11-24 18:53:11 +0000971 from test import test_normalization
Tim Petersb4ee4eb2002-12-04 03:26:57 +0000972 from test import test_socket_ssl
Neal Norwitz55b61d22003-02-28 19:57:03 +0000973 from test import test_timeout
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +0000974 from test import test_codecmaps_cn, test_codecmaps_jp
975 from test import test_codecmaps_kr, test_codecmaps_tw
Tim Peters1b445d32002-11-24 18:53:11 +0000976
Tim Peters7c7efe92002-08-23 17:55:54 +0000977 self.valid = False
Tim Petersde14a302002-04-01 05:04:46 +0000978 if sys.platform in _expectations:
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000979 s = _expectations[sys.platform]
Raymond Hettingera690a992003-11-16 16:17:49 +0000980 self.expected = set(s.split())
Tim Peters1b445d32002-11-24 18:53:11 +0000981
Tim Peters2a182db2002-10-09 01:07:11 +0000982 if not os.path.supports_unicode_filenames:
983 self.expected.add('test_pep277')
Tim Peters1b445d32002-11-24 18:53:11 +0000984
985 if test_normalization.skip_expected:
986 self.expected.add('test_normalization')
987
Tim Petersb4ee4eb2002-12-04 03:26:57 +0000988 if test_socket_ssl.skip_expected:
989 self.expected.add('test_socket_ssl')
990
Neal Norwitz55b61d22003-02-28 19:57:03 +0000991 if test_timeout.skip_expected:
992 self.expected.add('test_timeout')
993
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +0000994 for cc in ('cn', 'jp', 'kr', 'tw'):
995 if eval('test_codecmaps_' + cc).skip_expected:
996 self.expected.add('test_codecmaps_' + cc)
997
Jack Jansen6afc5e02003-01-29 16:24:16 +0000998 if not sys.platform in ("mac", "darwin"):
Neal Norwitz7035c982003-03-29 22:01:17 +0000999 MAC_ONLY = ["test_macostools", "test_macfs", "test_aepack",
1000 "test_plistlib", "test_scriptpackages"]
1001 for skip in MAC_ONLY:
1002 self.expected.add(skip)
Tim Petersecd79eb2003-01-29 00:35:32 +00001003
1004 if sys.platform != "win32":
Neal Norwitz7035c982003-03-29 22:01:17 +00001005 WIN_ONLY = ["test_unicode_file", "test_winreg",
1006 "test_winsound"]
1007 for skip in WIN_ONLY:
1008 self.expected.add(skip)
Tim Petersf2715e02003-02-19 02:35:07 +00001009
Tim Peters7c7efe92002-08-23 17:55:54 +00001010 self.valid = True
Tim Petersb5b7b782001-08-12 01:20:39 +00001011
1012 def isvalid(self):
1013 "Return true iff _ExpectedSkips knows about the current platform."
1014 return self.valid
1015
1016 def getexpected(self):
1017 """Return set of test names we expect to skip on current platform.
1018
1019 self.isvalid() must be true.
1020 """
1021
1022 assert self.isvalid()
1023 return self.expected
1024
Guido van Rossum152494a1996-12-20 03:12:20 +00001025if __name__ == '__main__':
Barry Warsaw408b6d32002-07-30 23:27:12 +00001026 # Remove regrtest.py's own directory from the module search path. This
1027 # prevents relative imports from working, and relative imports will screw
1028 # up the testing framework. E.g. if both test.test_support and
1029 # test_support are imported, they will not contain the same globals, and
1030 # much of the testing framework relies on the globals in the
1031 # test.test_support module.
1032 mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
1033 i = pathlen = len(sys.path)
1034 while i >= 0:
1035 i -= 1
1036 if os.path.abspath(os.path.normpath(sys.path[i])) == mydir:
1037 del sys.path[i]
1038 if len(sys.path) == pathlen:
1039 print 'Could not find %r in sys.path to remove it' % mydir
Barry Warsaw08fca522001-08-20 22:33:46 +00001040 main()