blob: d16de6bca66df5bd9eb5b314e8840c1450ddd8c2 [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
74To enable all resources except one, use '-uall,-<resource>'. For
75example, to run all the tests except for the bsddb tests, give the
76option '-uall,-bsddb'.
Guido van Rossum152494a1996-12-20 03:12:20 +000077"""
78
Guido van Rossum152494a1996-12-20 03:12:20 +000079import os
Barry Warsaw3b6d0252004-02-07 22:43:03 +000080import sys
Guido van Rossum152494a1996-12-20 03:12:20 +000081import getopt
Skip Montanaroab1c7912000-06-30 16:39:27 +000082import random
Guido van Rossumdc15c272002-08-12 21:55:51 +000083import warnings
Barry Warsaw3b6d0252004-02-07 22:43:03 +000084import cStringIO
85import traceback
Guido van Rossumdc15c272002-08-12 21:55:51 +000086
87# I see no other way to suppress these warnings;
88# putting them in test_grammar.py has no effect:
Guido van Rossum88b1def2002-08-14 17:54:48 +000089warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
Guido van Rossumdc15c272002-08-12 21:55:51 +000090 ".*test.test_grammar$")
Guido van Rossumc34c4fc2002-09-19 00:42:16 +000091if sys.maxint > 0x7fffffff:
92 # Also suppress them in <string>, because for 64-bit platforms,
93 # that's where test_grammar.py hides them.
94 warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
95 "<string>")
Guido van Rossum152494a1996-12-20 03:12:20 +000096
Guido van Rossumbb484652002-12-02 09:56:21 +000097# MacOSX (a.k.a. Darwin) has a default stack size that is too small
98# for deeply recursive regular expressions. We see this as crashes in
99# the Python test suite when running test_re.py and test_sre.py. The
100# fix is to set the stack limit to 2048.
101# This approach may also be useful for other Unixy platforms that
102# suffer from small default stack limits.
103if sys.platform == 'darwin':
104 try:
105 import resource
106 except ImportError:
107 pass
108 else:
109 soft, hard = resource.getrlimit(resource.RLIMIT_STACK)
110 newsoft = min(hard, max(soft, 1024*2048))
111 resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard))
112
Barry Warsaw04f357c2002-07-23 19:04:11 +0000113from test import test_support
Fred Drake3a15dac2002-04-11 16:39:16 +0000114
Guido van Rossum315aa362003-03-11 14:46:48 +0000115RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', 'bsddb')
Fred Drake3a15dac2002-04-11 16:39:16 +0000116
117
Barry Warsaw08fca522001-08-20 22:33:46 +0000118def usage(code, msg=''):
119 print __doc__
120 if msg: print msg
121 sys.exit(code)
122
123
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000124def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
125 exclude=False, single=False, randomize=False, fromfile=None,
Skip Montanaro0179a182004-06-06 15:53:18 +0000126 findleaks=False, use_resources=None, trace=False, runleaks=False):
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000127 """Execute a test suite.
128
Thomas Wouters7e474022000-07-16 12:04:32 +0000129 This also parses command-line options and modifies its behavior
Fred Drake004d5e62000-10-23 17:22:08 +0000130 accordingly.
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000131
132 tests -- a list of strings containing test names (optional)
133 testdir -- the directory in which to look for tests (optional)
134
135 Users other than the Python test suite will certainly want to
136 specify testdir; if it's omitted, the directory containing the
Fred Drake004d5e62000-10-23 17:22:08 +0000137 Python test suite is searched for.
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000138
139 If the tests argument is omitted, the tests listed on the
140 command-line will be used. If that's empty, too, then all *.py
141 files beginning with test_ will be used.
Skip Montanaroab1c7912000-06-30 16:39:27 +0000142
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000143 The other default arguments (verbose, quiet, generate, exclude, single,
144 randomize, findleaks, use_resources, and trace) allow programmers calling
145 main() directly to set the values that would normally be set by flags on
146 the command line.
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000147 """
Fred Drake004d5e62000-10-23 17:22:08 +0000148
Tim Peters8dee8092001-09-25 20:05:11 +0000149 test_support.record_original_stdout(sys.stdout)
Guido van Rossum152494a1996-12-20 03:12:20 +0000150 try:
Skip Montanaro0179a182004-06-06 15:53:18 +0000151 opts, args = getopt.getopt(sys.argv[1:], 'hvgqxsrf:lu:t:TL',
Barry Warsaw08fca522001-08-20 22:33:46 +0000152 ['help', 'verbose', 'quiet', 'generate',
Tim Petersc5000df2002-06-02 21:42:01 +0000153 'exclude', 'single', 'random', 'fromfile',
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000154 'findleaks', 'use=', 'threshold=', 'trace',
Skip Montanaro0179a182004-06-06 15:53:18 +0000155 'runleaks'
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000156 ])
Guido van Rossum152494a1996-12-20 03:12:20 +0000157 except getopt.error, msg:
Barry Warsaw08fca522001-08-20 22:33:46 +0000158 usage(2, msg)
159
160 # Defaults
161 if use_resources is None:
162 use_resources = []
Guido van Rossum152494a1996-12-20 03:12:20 +0000163 for o, a in opts:
Barry Warsaw08fca522001-08-20 22:33:46 +0000164 if o in ('-h', '--help'):
165 usage(0)
166 elif o in ('-v', '--verbose'):
167 verbose += 1
168 elif o in ('-q', '--quiet'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000169 quiet = True;
Barry Warsaw08fca522001-08-20 22:33:46 +0000170 verbose = 0
171 elif o in ('-g', '--generate'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000172 generate = True
Barry Warsaw08fca522001-08-20 22:33:46 +0000173 elif o in ('-x', '--exclude'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000174 exclude = True
Barry Warsaw08fca522001-08-20 22:33:46 +0000175 elif o in ('-s', '--single'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000176 single = True
Barry Warsaw08fca522001-08-20 22:33:46 +0000177 elif o in ('-r', '--randomize'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000178 randomize = True
Tim Petersc5000df2002-06-02 21:42:01 +0000179 elif o in ('-f', '--fromfile'):
180 fromfile = a
Barry Warsaw08fca522001-08-20 22:33:46 +0000181 elif o in ('-l', '--findleaks'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000182 findleaks = True
Skip Montanaro0179a182004-06-06 15:53:18 +0000183 elif o in ('-L', '--runleaks'):
184 runleaks = True
Guido van Rossum9e9d4f82002-06-07 15:17:03 +0000185 elif o in ('-t', '--threshold'):
186 import gc
187 gc.set_threshold(int(a))
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000188 elif o in ('-T', '--coverage'):
189 trace = True
Barry Warsaw08fca522001-08-20 22:33:46 +0000190 elif o in ('-u', '--use'):
Guido van Rossumfe3f6962001-09-06 16:09:41 +0000191 u = [x.lower() for x in a.split(',')]
192 for r in u:
Fred Drake3a15dac2002-04-11 16:39:16 +0000193 if r == 'all':
Fred Drake4dd0f7e2002-11-26 21:44:56 +0000194 use_resources[:] = RESOURCE_NAMES
195 continue
196 remove = False
197 if r[0] == '-':
198 remove = True
199 r = r[1:]
Fred Drake3a15dac2002-04-11 16:39:16 +0000200 if r not in RESOURCE_NAMES:
201 usage(1, 'Invalid -u/--use option: ' + a)
Fred Drake4dd0f7e2002-11-26 21:44:56 +0000202 if remove:
203 if r in use_resources:
204 use_resources.remove(r)
205 elif r not in use_resources:
Andrew MacIntyree41abab2002-04-30 12:11:04 +0000206 use_resources.append(r)
Guido van Rossuma4122201997-08-18 20:08:24 +0000207 if generate and verbose:
Barry Warsaw08fca522001-08-20 22:33:46 +0000208 usage(2, "-g and -v don't go together!")
Tim Petersc5000df2002-06-02 21:42:01 +0000209 if single and fromfile:
210 usage(2, "-s and -f don't go together!")
Barry Warsaw08fca522001-08-20 22:33:46 +0000211
Guido van Rossum152494a1996-12-20 03:12:20 +0000212 good = []
213 bad = []
214 skipped = []
Fred Drake9a0db072003-02-03 15:19:30 +0000215 resource_denieds = []
Barry Warsawe11e3de1999-01-28 19:51:51 +0000216
Neil Schemenauerd569f232000-09-22 15:29:28 +0000217 if findleaks:
Barry Warsawa873b032000-08-03 15:50:37 +0000218 try:
219 import gc
220 except ImportError:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000221 print 'No GC available, disabling findleaks.'
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000222 findleaks = False
Barry Warsawa873b032000-08-03 15:50:37 +0000223 else:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000224 # Uncomment the line below to report garbage that is not
225 # freeable by reference counting alone. By default only
226 # garbage that is not collectable by the GC is reported.
227 #gc.set_debug(gc.DEBUG_SAVEALL)
Neil Schemenauerd569f232000-09-22 15:29:28 +0000228 found_garbage = []
Barry Warsawa873b032000-08-03 15:50:37 +0000229
Barry Warsawe11e3de1999-01-28 19:51:51 +0000230 if single:
231 from tempfile import gettempdir
232 filename = os.path.join(gettempdir(), 'pynexttest')
233 try:
234 fp = open(filename, 'r')
Eric S. Raymondfc170b12001-02-09 11:51:27 +0000235 next = fp.read().strip()
Barry Warsawe11e3de1999-01-28 19:51:51 +0000236 tests = [next]
237 fp.close()
238 except IOError:
239 pass
Tim Petersc5000df2002-06-02 21:42:01 +0000240
241 if fromfile:
242 tests = []
243 fp = open(fromfile)
244 for line in fp:
245 guts = line.split() # assuming no test has whitespace in its name
246 if guts and not guts[0].startswith('#'):
247 tests.extend(guts)
248 fp.close()
249
250 # Strip .py extensions.
251 if args:
252 args = map(removepy, args)
253 if tests:
254 tests = map(removepy, tests)
255
Guido van Rossum6c74fea1998-08-25 12:29:08 +0000256 stdtests = STDTESTS[:]
257 nottests = NOTTESTS[:]
Guido van Rossum152494a1996-12-20 03:12:20 +0000258 if exclude:
Guido van Rossum6c74fea1998-08-25 12:29:08 +0000259 for arg in args:
260 if arg in stdtests:
261 stdtests.remove(arg)
262 nottests[:0] = args
Guido van Rossum41360a41998-03-26 19:42:58 +0000263 args = []
Guido van Rossum747e1ca1998-08-24 13:48:36 +0000264 tests = tests or args or findtests(testdir, stdtests, nottests)
Barry Warsawe11e3de1999-01-28 19:51:51 +0000265 if single:
266 tests = tests[:1]
Skip Montanaroab1c7912000-06-30 16:39:27 +0000267 if randomize:
268 random.shuffle(tests)
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000269 if trace:
270 import trace
271 tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix],
272 trace=False, count=True)
273 coverdir = os.path.join(os.getcwd(), 'coverage')
Guido van Rossum41360a41998-03-26 19:42:58 +0000274 test_support.verbose = verbose # Tell tests to be moderately quiet
Barry Warsaw08fca522001-08-20 22:33:46 +0000275 test_support.use_resources = use_resources
Guido van Rossum5796d262000-04-21 21:35:06 +0000276 save_modules = sys.modules.keys()
Guido van Rossum152494a1996-12-20 03:12:20 +0000277 for test in tests:
Guido van Rossum41360a41998-03-26 19:42:58 +0000278 if not quiet:
279 print test
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000280 sys.stdout.flush()
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000281 if trace:
282 # If we're tracing code coverage, then we don't exit with status
283 # if on a false return value from main.
284 tracer.runctx('runtest(test, generate, verbose, quiet, testdir)',
285 globals=globals(), locals=vars())
Guido van Rossum41360a41998-03-26 19:42:58 +0000286 else:
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000287 ok = runtest(test, generate, verbose, quiet, testdir)
288 if ok > 0:
289 good.append(test)
290 elif ok == 0:
291 bad.append(test)
292 else:
293 skipped.append(test)
294 if ok == -2:
295 resource_denieds.append(test)
Neil Schemenauerd569f232000-09-22 15:29:28 +0000296 if findleaks:
297 gc.collect()
298 if gc.garbage:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000299 print "Warning: test created", len(gc.garbage),
300 print "uncollectable object(s)."
301 # move the uncollectable objects somewhere so we don't see
302 # them again
Neil Schemenauerd569f232000-09-22 15:29:28 +0000303 found_garbage.extend(gc.garbage)
304 del gc.garbage[:]
Guido van Rossum5796d262000-04-21 21:35:06 +0000305 # Unload the newly imported modules (best effort finalization)
306 for module in sys.modules.keys():
Guido van Rossum51931142000-05-05 14:27:39 +0000307 if module not in save_modules and module.startswith("test."):
Guido van Rossum5796d262000-04-21 21:35:06 +0000308 test_support.unload(module)
Jeremy Hylton7a1ea0e2001-10-17 13:45:28 +0000309
310 # The lists won't be sorted if running with -r
311 good.sort()
312 bad.sort()
313 skipped.sort()
Tim Peterse0c446b2001-10-18 21:57:37 +0000314
Guido van Rossum152494a1996-12-20 03:12:20 +0000315 if good and not quiet:
Guido van Rossum41360a41998-03-26 19:42:58 +0000316 if not bad and not skipped and len(good) > 1:
317 print "All",
318 print count(len(good), "test"), "OK."
Tim Peters1a4d77b2000-12-30 22:21:22 +0000319 if verbose:
Barry Warsaw408b6d32002-07-30 23:27:12 +0000320 print "CAUTION: stdout isn't compared in verbose mode:"
321 print "a test that passes in verbose mode may fail without it."
Guido van Rossum152494a1996-12-20 03:12:20 +0000322 if bad:
Tim Petersa45da922001-08-12 03:45:50 +0000323 print count(len(bad), "test"), "failed:"
324 printlist(bad)
Guido van Rossum152494a1996-12-20 03:12:20 +0000325 if skipped and not quiet:
Tim Petersa45da922001-08-12 03:45:50 +0000326 print count(len(skipped), "test"), "skipped:"
327 printlist(skipped)
Barry Warsawe11e3de1999-01-28 19:51:51 +0000328
Tim Petersb5b7b782001-08-12 01:20:39 +0000329 e = _ExpectedSkips()
Tim Petersa2be2d62001-08-12 02:01:09 +0000330 plat = sys.platform
Tim Petersb5b7b782001-08-12 01:20:39 +0000331 if e.isvalid():
Raymond Hettingera690a992003-11-16 16:17:49 +0000332 surprise = set(skipped) - e.getexpected() - set(resource_denieds)
Tim Petersb5b7b782001-08-12 01:20:39 +0000333 if surprise:
334 print count(len(surprise), "skip"), \
Tim Petersa45da922001-08-12 03:45:50 +0000335 "unexpected on", plat + ":"
336 printlist(surprise)
Tim Petersb5b7b782001-08-12 01:20:39 +0000337 else:
338 print "Those skips are all expected on", plat + "."
339 else:
340 print "Ask someone to teach regrtest.py about which tests are"
341 print "expected to get skipped on", plat + "."
342
Barry Warsawe11e3de1999-01-28 19:51:51 +0000343 if single:
344 alltests = findtests(testdir, stdtests, nottests)
345 for i in range(len(alltests)):
346 if tests[0] == alltests[i]:
347 if i == len(alltests) - 1:
348 os.unlink(filename)
349 else:
350 fp = open(filename, 'w')
351 fp.write(alltests[i+1] + '\n')
352 fp.close()
353 break
354 else:
355 os.unlink(filename)
356
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000357 if trace:
358 r = tracer.results()
359 r.write_results(show_missing=True, summary=True, coverdir=coverdir)
360
Skip Montanaro0179a182004-06-06 15:53:18 +0000361 if runleaks:
362 os.system("leaks %d" % os.getpid())
363
Tim Peters5943b4a2003-07-23 00:30:39 +0000364 sys.exit(len(bad) > 0)
Barry Warsaw08fca522001-08-20 22:33:46 +0000365
Guido van Rossum152494a1996-12-20 03:12:20 +0000366
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000367STDTESTS = [
Guido van Rossum152494a1996-12-20 03:12:20 +0000368 'test_grammar',
369 'test_opcodes',
370 'test_operations',
371 'test_builtin',
372 'test_exceptions',
373 'test_types',
374 ]
375
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000376NOTTESTS = [
Guido van Rossum152494a1996-12-20 03:12:20 +0000377 'test_support',
Jeremy Hylton62e2c7e2001-02-28 17:48:06 +0000378 'test_future1',
379 'test_future2',
Jeremy Hylton8471a352001-08-20 20:33:42 +0000380 'test_future3',
Guido van Rossum152494a1996-12-20 03:12:20 +0000381 ]
382
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000383def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
Guido van Rossum152494a1996-12-20 03:12:20 +0000384 """Return a list of all applicable test modules."""
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000385 if not testdir: testdir = findtestdir()
Guido van Rossum152494a1996-12-20 03:12:20 +0000386 names = os.listdir(testdir)
387 tests = []
388 for name in names:
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000389 if name[:5] == "test_" and name[-3:] == os.extsep+"py":
Guido van Rossum41360a41998-03-26 19:42:58 +0000390 modname = name[:-3]
391 if modname not in stdtests and modname not in nottests:
392 tests.append(modname)
Guido van Rossum152494a1996-12-20 03:12:20 +0000393 tests.sort()
394 return stdtests + tests
395
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000396def runtest(test, generate, verbose, quiet, testdir=None):
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000397 """Run a single test.
398 test -- the name of the test
399 generate -- if true, generate output, instead of running the test
400 and comparing it to a previously created output file
401 verbose -- if true, print more messages
Trent Mickf29f47b2000-08-11 19:02:59 +0000402 quiet -- if true, don't print 'skipped' messages (probably redundant)
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000403 testdir -- test directory
404 """
Guido van Rossum152494a1996-12-20 03:12:20 +0000405 test_support.unload(test)
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000406 if not testdir:
407 testdir = findtestdir()
Guido van Rossum152494a1996-12-20 03:12:20 +0000408 outputdir = os.path.join(testdir, "output")
409 outputfile = os.path.join(outputdir, test)
Tim Peters9390cc12001-09-28 20:14:46 +0000410 if verbose:
Guido van Rossum41360a41998-03-26 19:42:58 +0000411 cfp = None
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000412 else:
Raymond Hettinger74e67662003-05-17 20:44:12 +0000413 cfp = cStringIO.StringIO()
Guido van Rossum152494a1996-12-20 03:12:20 +0000414 try:
Tim Peters342ca752001-09-25 19:13:20 +0000415 save_stdout = sys.stdout
Guido van Rossum41360a41998-03-26 19:42:58 +0000416 try:
417 if cfp:
418 sys.stdout = cfp
419 print test # Output file starts with test name
Barry Warsaw408b6d32002-07-30 23:27:12 +0000420 if test.startswith('test.'):
421 abstest = test
422 else:
423 # Always import it from the test package
424 abstest = 'test.' + test
425 the_package = __import__(abstest, globals(), locals(), [])
426 the_module = getattr(the_package, test)
Tim Petersd9742212001-05-22 18:28:25 +0000427 # Most tests run to completion simply as a side-effect of
428 # being imported. For the benefit of tests that can't run
429 # that way (like test_threaded_import), explicitly invoke
430 # their test_main() function (if it exists).
431 indirect_test = getattr(the_module, "test_main", None)
432 if indirect_test is not None:
433 indirect_test()
Guido van Rossum41360a41998-03-26 19:42:58 +0000434 finally:
Tim Peters342ca752001-09-25 19:13:20 +0000435 sys.stdout = save_stdout
Fred Drake9a0db072003-02-03 15:19:30 +0000436 except test_support.ResourceDenied, msg:
437 if not quiet:
438 print test, "skipped --", msg
439 sys.stdout.flush()
440 return -2
Thomas Wouters3af826e2000-08-04 13:17:51 +0000441 except (ImportError, test_support.TestSkipped), msg:
Trent Mickf29f47b2000-08-11 19:02:59 +0000442 if not quiet:
Fred Drakede4742b2002-10-17 20:36:08 +0000443 print test, "skipped --", msg
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000444 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000445 return -1
Fred Drakefe5c22a2000-08-18 16:04:05 +0000446 except KeyboardInterrupt:
447 raise
Guido van Rossum152494a1996-12-20 03:12:20 +0000448 except test_support.TestFailed, msg:
Guido van Rossum41360a41998-03-26 19:42:58 +0000449 print "test", test, "failed --", msg
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000450 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000451 return 0
Guido van Rossum9e48b271997-07-16 01:56:13 +0000452 except:
Guido van Rossum41360a41998-03-26 19:42:58 +0000453 type, value = sys.exc_info()[:2]
Fred Drake27c4b392000-08-23 20:34:40 +0000454 print "test", test, "crashed --", str(type) + ":", value
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000455 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000456 if verbose:
457 traceback.print_exc(file=sys.stdout)
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000458 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000459 return 0
Guido van Rossum152494a1996-12-20 03:12:20 +0000460 else:
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000461 if not cfp:
462 return 1
463 output = cfp.getvalue()
Fred Drakee51fe8d2001-05-29 17:10:51 +0000464 if generate:
Fred Drakee51fe8d2001-05-29 17:10:51 +0000465 if output == test + "\n":
466 if os.path.exists(outputfile):
467 # Write it since it already exists (and the contents
468 # may have changed), but let the user know it isn't
469 # needed:
Fred Drakee51fe8d2001-05-29 17:10:51 +0000470 print "output file", outputfile, \
471 "is no longer needed; consider removing it"
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000472 else:
473 # We don't need it, so don't create it.
474 return 1
475 fp = open(outputfile, "w")
476 fp.write(output)
477 fp.close()
478 return 1
479 if os.path.exists(outputfile):
480 fp = open(outputfile, "r")
481 expected = fp.read()
482 fp.close()
483 else:
484 expected = test + "\n"
485 if output == expected:
486 return 1
487 print "test", test, "produced unexpected output:"
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000488 sys.stdout.flush()
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000489 reportdiff(expected, output)
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000490 sys.stdout.flush()
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000491 return 0
492
493def reportdiff(expected, output):
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000494 import difflib
Tim Petersc377b162001-09-22 05:31:03 +0000495 print "*" * 70
496 a = expected.splitlines(1)
497 b = output.splitlines(1)
Guido van Rossumcf691932001-09-21 21:06:22 +0000498 sm = difflib.SequenceMatcher(a=a, b=b)
499 tuples = sm.get_opcodes()
Tim Petersc377b162001-09-22 05:31:03 +0000500
Guido van Rossumcf691932001-09-21 21:06:22 +0000501 def pair(x0, x1):
Tim Petersc377b162001-09-22 05:31:03 +0000502 # x0:x1 are 0-based slice indices; convert to 1-based line indices.
Guido van Rossumcf691932001-09-21 21:06:22 +0000503 x0 += 1
504 if x0 >= x1:
Tim Petersc377b162001-09-22 05:31:03 +0000505 return "line " + str(x0)
Guido van Rossumcf691932001-09-21 21:06:22 +0000506 else:
Tim Petersc377b162001-09-22 05:31:03 +0000507 return "lines %d-%d" % (x0, x1)
508
Guido van Rossumcf691932001-09-21 21:06:22 +0000509 for op, a0, a1, b0, b1 in tuples:
510 if op == 'equal':
511 pass
Tim Petersc377b162001-09-22 05:31:03 +0000512
Guido van Rossumcf691932001-09-21 21:06:22 +0000513 elif op == 'delete':
Tim Petersc377b162001-09-22 05:31:03 +0000514 print "***", pair(a0, a1), "of expected output missing:"
Guido van Rossumcf691932001-09-21 21:06:22 +0000515 for line in a[a0:a1]:
Tim Petersc377b162001-09-22 05:31:03 +0000516 print "-", line,
517
Guido van Rossumcf691932001-09-21 21:06:22 +0000518 elif op == 'replace':
Tim Petersc377b162001-09-22 05:31:03 +0000519 print "*** mismatch between", pair(a0, a1), "of expected", \
520 "output and", pair(b0, b1), "of actual output:"
521 for line in difflib.ndiff(a[a0:a1], b[b0:b1]):
522 print line,
523
Guido van Rossumcf691932001-09-21 21:06:22 +0000524 elif op == 'insert':
Tim Petersc377b162001-09-22 05:31:03 +0000525 print "***", pair(b0, b1), "of actual output doesn't appear", \
526 "in expected output after line", str(a1)+":"
Guido van Rossumcf691932001-09-21 21:06:22 +0000527 for line in b[b0:b1]:
Tim Petersc377b162001-09-22 05:31:03 +0000528 print "+", line,
529
Guido van Rossumcf691932001-09-21 21:06:22 +0000530 else:
531 print "get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1)
Tim Petersc377b162001-09-22 05:31:03 +0000532
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000533 print "*" * 70
Guido van Rossum152494a1996-12-20 03:12:20 +0000534
535def findtestdir():
536 if __name__ == '__main__':
Guido van Rossum41360a41998-03-26 19:42:58 +0000537 file = sys.argv[0]
Guido van Rossum152494a1996-12-20 03:12:20 +0000538 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000539 file = __file__
Guido van Rossum152494a1996-12-20 03:12:20 +0000540 testdir = os.path.dirname(file) or os.curdir
541 return testdir
542
Tim Petersc5000df2002-06-02 21:42:01 +0000543def removepy(name):
544 if name.endswith(os.extsep + "py"):
545 name = name[:-3]
546 return name
547
Guido van Rossum152494a1996-12-20 03:12:20 +0000548def count(n, word):
549 if n == 1:
Guido van Rossum41360a41998-03-26 19:42:58 +0000550 return "%d %s" % (n, word)
Guido van Rossum152494a1996-12-20 03:12:20 +0000551 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000552 return "%d %ss" % (n, word)
Guido van Rossum152494a1996-12-20 03:12:20 +0000553
Tim Petersa45da922001-08-12 03:45:50 +0000554def printlist(x, width=70, indent=4):
Tim Peters7c7efe92002-08-23 17:55:54 +0000555 """Print the elements of iterable x to stdout.
Tim Petersa45da922001-08-12 03:45:50 +0000556
557 Optional arg width (default 70) is the maximum line length.
558 Optional arg indent (default 4) is the number of blanks with which to
559 begin each line.
560 """
561
Tim Petersba78bc42002-07-04 19:45:06 +0000562 from textwrap import fill
563 blanks = ' ' * indent
564 print fill(' '.join(map(str, x)), width,
565 initial_indent=blanks, subsequent_indent=blanks)
Tim Petersa45da922001-08-12 03:45:50 +0000566
Tim Petersde14a302002-04-01 05:04:46 +0000567# Map sys.platform to a string containing the basenames of tests
568# expected to be skipped on that platform.
Tim Peters2a182db2002-10-09 01:07:11 +0000569#
570# Special cases:
571# test_pep277
572# The _ExpectedSkips constructor adds this to the set of expected
573# skips if not os.path.supports_unicode_filenames.
Tim Peters1b445d32002-11-24 18:53:11 +0000574# test_normalization
575# Whether a skip is expected here depends on whether a large test
576# input file has been downloaded. test_normalization.skip_expected
Tim Peters1babdfc2002-11-24 19:19:09 +0000577# controls that.
Tim Petersb4ee4eb2002-12-04 03:26:57 +0000578# test_socket_ssl
579# Controlled by test_socket_ssl.skip_expected. Requires the network
580# resource, and a socket module with ssl support.
Neal Norwitz55b61d22003-02-28 19:57:03 +0000581# test_timeout
582# Controlled by test_timeout.skip_expected. Requires the network
583# resource and a socket module.
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +0000584# test_codecmaps_*
585# Whether a skip is expected here depends on whether a large test
586# input file has been downloaded. test_codecmaps_*.skip_expected
587# controls that.
Tim Petersde14a302002-04-01 05:04:46 +0000588
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000589_expectations = {
590 'win32':
591 """
Tim Petersc7c516a2003-09-20 22:06:13 +0000592 test__locale
Raymond Hettinger901dc982003-11-20 19:02:02 +0000593 test_applesingle
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000594 test_al
Skip Montanaro823ba282003-05-06 20:36:24 +0000595 test_bsddb185
Tim Peters78e35f92002-11-22 20:00:34 +0000596 test_bsddb3
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000597 test_cd
598 test_cl
599 test_commands
600 test_crypt
Tim Petersd7030572001-10-22 22:06:08 +0000601 test_curses
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000602 test_dbm
603 test_dl
604 test_fcntl
605 test_fork1
606 test_gdbm
607 test_gl
608 test_grp
609 test_imgfile
Tim Petersfd8e6e52003-03-04 00:26:38 +0000610 test_ioctl
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000611 test_largefile
612 test_linuxaudiodev
613 test_mhlib
Tim Petersde14a302002-04-01 05:04:46 +0000614 test_mpz
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000615 test_nis
616 test_openpty
Tim Petersefc4b122002-12-10 18:47:56 +0000617 test_ossaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000618 test_poll
Tim Peters003eb302003-02-17 21:48:48 +0000619 test_posix
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000620 test_pty
621 test_pwd
Tim Peters1e33ffa2002-04-23 23:09:02 +0000622 test_resource
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000623 test_signal
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000624 test_sunaudiodev
625 test_timing
626 """,
627 'linux2':
628 """
629 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000630 test_applesingle
Skip Montanaro823ba282003-05-06 20:36:24 +0000631 test_bsddb185
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000632 test_cd
633 test_cl
Guido van Rossumf66dacd2001-10-23 15:10:55 +0000634 test_curses
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000635 test_dl
636 test_gl
637 test_imgfile
638 test_largefile
Guido van Rossum4507ec72003-02-14 19:29:22 +0000639 test_linuxaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000640 test_nis
641 test_ntpath
Guido van Rossum4507ec72003-02-14 19:29:22 +0000642 test_ossaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000643 test_sunaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000644 """,
Jack Jansen49a806e2001-08-28 14:49:00 +0000645 'mac':
Guido van Rossumaa782362001-09-02 03:58:41 +0000646 """
647 test_al
Jack Jansen67975142003-01-08 16:31:11 +0000648 test_atexit
Guido van Rossumaa782362001-09-02 03:58:41 +0000649 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000650 test_bsddb185
Jack Jansen67975142003-01-08 16:31:11 +0000651 test_bsddb3
652 test_bz2
Guido van Rossumaa782362001-09-02 03:58:41 +0000653 test_cd
654 test_cl
655 test_commands
656 test_crypt
Jack Jansenb3be2162001-11-30 14:16:36 +0000657 test_curses
Guido van Rossumaa782362001-09-02 03:58:41 +0000658 test_dbm
659 test_dl
660 test_fcntl
661 test_fork1
662 test_gl
663 test_grp
Jack Jansenc4d6bdd2003-03-07 15:38:11 +0000664 test_ioctl
Guido van Rossumaa782362001-09-02 03:58:41 +0000665 test_imgfile
666 test_largefile
667 test_linuxaudiodev
668 test_locale
669 test_mmap
Jack Jansen67975142003-01-08 16:31:11 +0000670 test_mpz
Guido van Rossumaa782362001-09-02 03:58:41 +0000671 test_nis
672 test_ntpath
673 test_openpty
Jack Jansen67975142003-01-08 16:31:11 +0000674 test_ossaudiodev
Guido van Rossumaa782362001-09-02 03:58:41 +0000675 test_poll
Jack Jansen67975142003-01-08 16:31:11 +0000676 test_popen
Guido van Rossumaa782362001-09-02 03:58:41 +0000677 test_popen2
Jack Jansen5bb97e62003-02-21 22:33:55 +0000678 test_posix
Guido van Rossumaa782362001-09-02 03:58:41 +0000679 test_pty
680 test_pwd
Jack Jansen67975142003-01-08 16:31:11 +0000681 test_resource
Guido van Rossumaa782362001-09-02 03:58:41 +0000682 test_signal
Guido van Rossumaa782362001-09-02 03:58:41 +0000683 test_sunaudiodev
684 test_sundry
Jack Jansenc4d6bdd2003-03-07 15:38:11 +0000685 test_tarfile
Guido van Rossumaa782362001-09-02 03:58:41 +0000686 test_timing
Guido van Rossumaa782362001-09-02 03:58:41 +0000687 """,
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000688 'unixware7':
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000689 """
690 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000691 test_applesingle
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000692 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000693 test_bsddb185
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000694 test_cd
695 test_cl
696 test_dl
697 test_gl
698 test_imgfile
699 test_largefile
700 test_linuxaudiodev
701 test_minidom
702 test_nis
703 test_ntpath
704 test_openpty
705 test_pyexpat
706 test_sax
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000707 test_sunaudiodev
708 test_sundry
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000709 """,
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000710 'openunix8':
711 """
712 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000713 test_applesingle
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000714 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000715 test_bsddb185
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000716 test_cd
717 test_cl
718 test_dl
719 test_gl
720 test_imgfile
721 test_largefile
722 test_linuxaudiodev
723 test_minidom
724 test_nis
725 test_ntpath
726 test_openpty
727 test_pyexpat
728 test_sax
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000729 test_sunaudiodev
730 test_sundry
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000731 """,
732 'sco_sv3':
733 """
734 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000735 test_applesingle
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000736 test_asynchat
737 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000738 test_bsddb185
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000739 test_cd
740 test_cl
741 test_dl
742 test_fork1
743 test_gettext
744 test_gl
745 test_imgfile
746 test_largefile
747 test_linuxaudiodev
748 test_locale
749 test_minidom
750 test_nis
751 test_ntpath
752 test_openpty
753 test_pyexpat
754 test_queue
755 test_sax
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000756 test_sunaudiodev
757 test_sundry
758 test_thread
759 test_threaded_import
760 test_threadedtempfile
761 test_threading
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000762 """,
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000763 'riscos':
764 """
765 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000766 test_applesingle
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000767 test_asynchat
Martin v. Löwisa94568a2003-05-10 07:36:56 +0000768 test_atexit
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000769 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000770 test_bsddb185
Martin v. Löwisa94568a2003-05-10 07:36:56 +0000771 test_bsddb3
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000772 test_cd
773 test_cl
774 test_commands
775 test_crypt
776 test_dbm
777 test_dl
778 test_fcntl
779 test_fork1
780 test_gdbm
781 test_gl
782 test_grp
783 test_imgfile
784 test_largefile
785 test_linuxaudiodev
786 test_locale
787 test_mmap
788 test_nis
789 test_ntpath
790 test_openpty
791 test_poll
792 test_popen2
793 test_pty
794 test_pwd
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000795 test_strop
796 test_sunaudiodev
797 test_sundry
798 test_thread
799 test_threaded_import
800 test_threadedtempfile
801 test_threading
802 test_timing
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000803 """,
Jack Jansen8a97f4a2001-12-05 23:27:32 +0000804 'darwin':
Jack Jansen398c2362001-12-02 21:41:36 +0000805 """
Brett Cannon2bfb94c2003-10-13 04:27:47 +0000806 test__locale
Jack Jansen398c2362001-12-02 21:41:36 +0000807 test_al
Jack Jansenacda3392002-12-30 23:03:13 +0000808 test_bsddb
Guido van Rossum9d427002002-12-03 10:24:56 +0000809 test_bsddb3
Jack Jansen398c2362001-12-02 21:41:36 +0000810 test_cd
811 test_cl
812 test_curses
813 test_dl
814 test_gdbm
815 test_gl
816 test_imgfile
817 test_largefile
818 test_linuxaudiodev
Jack Jansenacda3392002-12-30 23:03:13 +0000819 test_locale
Jack Jansen398c2362001-12-02 21:41:36 +0000820 test_minidom
Guido van Rossum9d427002002-12-03 10:24:56 +0000821 test_mpz
Jack Jansen398c2362001-12-02 21:41:36 +0000822 test_nis
823 test_ntpath
Jack Jansenacda3392002-12-30 23:03:13 +0000824 test_ossaudiodev
Jack Jansen398c2362001-12-02 21:41:36 +0000825 test_poll
Jack Jansen398c2362001-12-02 21:41:36 +0000826 test_sunaudiodev
Jack Jansen398c2362001-12-02 21:41:36 +0000827 """,
Guido van Rossum11c3f092002-07-17 15:08:24 +0000828 'sunos5':
829 """
830 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000831 test_applesingle
Guido van Rossum11c3f092002-07-17 15:08:24 +0000832 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000833 test_bsddb185
Guido van Rossum11c3f092002-07-17 15:08:24 +0000834 test_cd
835 test_cl
836 test_curses
837 test_dbm
Guido van Rossum11c3f092002-07-17 15:08:24 +0000838 test_gdbm
839 test_gl
840 test_gzip
841 test_imgfile
842 test_linuxaudiodev
843 test_mpz
844 test_openpty
Guido van Rossum11c3f092002-07-17 15:08:24 +0000845 test_zipfile
846 test_zlib
Jeremy Hyltoned375e12002-07-17 15:56:55 +0000847 """,
Skip Montanarob3230212002-03-15 02:54:03 +0000848 'hp-ux11':
849 """
850 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000851 test_applesingle
Skip Montanarob3230212002-03-15 02:54:03 +0000852 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000853 test_bsddb185
Skip Montanarob3230212002-03-15 02:54:03 +0000854 test_cd
855 test_cl
856 test_curses
857 test_dl
858 test_gdbm
859 test_gl
860 test_gzip
861 test_imgfile
862 test_largefile
863 test_linuxaudiodev
864 test_locale
865 test_minidom
866 test_nis
867 test_ntpath
868 test_openpty
869 test_pyexpat
870 test_sax
Skip Montanarob3230212002-03-15 02:54:03 +0000871 test_sunaudiodev
Skip Montanarob3230212002-03-15 02:54:03 +0000872 test_zipfile
873 test_zlib
874 """,
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000875 'atheos':
Tim Petersc411dba2002-07-16 21:35:23 +0000876 """
877 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000878 test_applesingle
Skip Montanaro823ba282003-05-06 20:36:24 +0000879 test_bsddb185
Tim Petersc411dba2002-07-16 21:35:23 +0000880 test_cd
881 test_cl
882 test_curses
883 test_dl
Tim Petersc411dba2002-07-16 21:35:23 +0000884 test_gdbm
885 test_gl
886 test_imgfile
887 test_largefile
888 test_linuxaudiodev
889 test_locale
890 test_mhlib
891 test_mmap
892 test_mpz
893 test_nis
894 test_poll
895 test_popen2
896 test_resource
Tim Petersc411dba2002-07-16 21:35:23 +0000897 test_sunaudiodev
Tim Petersc411dba2002-07-16 21:35:23 +0000898 """,
Jason Tishler25115942002-12-05 15:18:15 +0000899 'cygwin':
900 """
901 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000902 test_applesingle
Skip Montanaro823ba282003-05-06 20:36:24 +0000903 test_bsddb185
Tim Petersb0f89e02002-12-05 17:20:25 +0000904 test_bsddb3
Jason Tishler25115942002-12-05 15:18:15 +0000905 test_cd
906 test_cl
907 test_curses
908 test_dbm
Jason Tishler25115942002-12-05 15:18:15 +0000909 test_gl
910 test_imgfile
Jason Tishlerc23f39c2003-07-22 18:35:58 +0000911 test_ioctl
Jason Tishler25115942002-12-05 15:18:15 +0000912 test_largefile
913 test_linuxaudiodev
914 test_locale
915 test_mpz
916 test_nis
Jason Tishler5c4ded22003-02-05 16:46:01 +0000917 test_ossaudiodev
Jason Tishler25115942002-12-05 15:18:15 +0000918 test_socketserver
919 test_sunaudiodev
Jason Tishler25115942002-12-05 15:18:15 +0000920 """,
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000921 'os2emx':
922 """
923 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000924 test_applesingle
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000925 test_audioop
Skip Montanaro823ba282003-05-06 20:36:24 +0000926 test_bsddb185
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000927 test_bsddb3
928 test_cd
929 test_cl
930 test_commands
931 test_curses
932 test_dl
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000933 test_gl
934 test_imgfile
935 test_largefile
936 test_linuxaudiodev
937 test_mhlib
938 test_mmap
939 test_nis
940 test_openpty
941 test_ossaudiodev
942 test_pty
943 test_resource
944 test_signal
945 test_sunaudiodev
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000946 """,
Guido van Rossum944a6c32003-11-20 22:11:29 +0000947 'freebsd4':
948 """
949 test_aepack
950 test_al
951 test_applesingle
952 test_bsddb
953 test_bsddb3
954 test_cd
955 test_cl
Guido van Rossum944a6c32003-11-20 22:11:29 +0000956 test_gl
957 test_imgfile
958 test_linuxaudiodev
959 test_locale
960 test_macfs
961 test_macostools
962 test_nis
963 test_normalization
964 test_ossaudiodev
965 test_pep277
966 test_plistlib
967 test_scriptpackages
968 test_socket_ssl
969 test_socketserver
970 test_sunaudiodev
971 test_timeout
972 test_unicode_file
973 test_urllibnet
974 test_winreg
975 test_winsound
Martin v. Löwis56f88112003-06-07 20:01:37 +0000976 """,
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000977}
978
Tim Petersb5b7b782001-08-12 01:20:39 +0000979class _ExpectedSkips:
980 def __init__(self):
Tim Peters2a182db2002-10-09 01:07:11 +0000981 import os.path
Tim Peters1b445d32002-11-24 18:53:11 +0000982 from test import test_normalization
Tim Petersb4ee4eb2002-12-04 03:26:57 +0000983 from test import test_socket_ssl
Neal Norwitz55b61d22003-02-28 19:57:03 +0000984 from test import test_timeout
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +0000985 from test import test_codecmaps_cn, test_codecmaps_jp
986 from test import test_codecmaps_kr, test_codecmaps_tw
Tim Peters1b445d32002-11-24 18:53:11 +0000987
Tim Peters7c7efe92002-08-23 17:55:54 +0000988 self.valid = False
Tim Petersde14a302002-04-01 05:04:46 +0000989 if sys.platform in _expectations:
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000990 s = _expectations[sys.platform]
Raymond Hettingera690a992003-11-16 16:17:49 +0000991 self.expected = set(s.split())
Tim Peters1b445d32002-11-24 18:53:11 +0000992
Tim Peters2a182db2002-10-09 01:07:11 +0000993 if not os.path.supports_unicode_filenames:
994 self.expected.add('test_pep277')
Tim Peters1b445d32002-11-24 18:53:11 +0000995
996 if test_normalization.skip_expected:
997 self.expected.add('test_normalization')
998
Tim Petersb4ee4eb2002-12-04 03:26:57 +0000999 if test_socket_ssl.skip_expected:
1000 self.expected.add('test_socket_ssl')
1001
Neal Norwitz55b61d22003-02-28 19:57:03 +00001002 if test_timeout.skip_expected:
1003 self.expected.add('test_timeout')
1004
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001005 for cc in ('cn', 'jp', 'kr', 'tw'):
1006 if eval('test_codecmaps_' + cc).skip_expected:
1007 self.expected.add('test_codecmaps_' + cc)
1008
Jack Jansen6afc5e02003-01-29 16:24:16 +00001009 if not sys.platform in ("mac", "darwin"):
Neal Norwitz7035c982003-03-29 22:01:17 +00001010 MAC_ONLY = ["test_macostools", "test_macfs", "test_aepack",
1011 "test_plistlib", "test_scriptpackages"]
1012 for skip in MAC_ONLY:
1013 self.expected.add(skip)
Tim Petersecd79eb2003-01-29 00:35:32 +00001014
1015 if sys.platform != "win32":
Neal Norwitz7035c982003-03-29 22:01:17 +00001016 WIN_ONLY = ["test_unicode_file", "test_winreg",
1017 "test_winsound"]
1018 for skip in WIN_ONLY:
1019 self.expected.add(skip)
Tim Petersf2715e02003-02-19 02:35:07 +00001020
Tim Peters7c7efe92002-08-23 17:55:54 +00001021 self.valid = True
Tim Petersb5b7b782001-08-12 01:20:39 +00001022
1023 def isvalid(self):
1024 "Return true iff _ExpectedSkips knows about the current platform."
1025 return self.valid
1026
1027 def getexpected(self):
1028 """Return set of test names we expect to skip on current platform.
1029
1030 self.isvalid() must be true.
1031 """
1032
1033 assert self.isvalid()
1034 return self.expected
1035
Guido van Rossum152494a1996-12-20 03:12:20 +00001036if __name__ == '__main__':
Barry Warsaw408b6d32002-07-30 23:27:12 +00001037 # Remove regrtest.py's own directory from the module search path. This
1038 # prevents relative imports from working, and relative imports will screw
1039 # up the testing framework. E.g. if both test.test_support and
1040 # test_support are imported, they will not contain the same globals, and
1041 # much of the testing framework relies on the globals in the
1042 # test.test_support module.
1043 mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
1044 i = pathlen = len(sys.path)
1045 while i >= 0:
1046 i -= 1
1047 if os.path.abspath(os.path.normpath(sys.path[i])) == mydir:
1048 del sys.path[i]
1049 if len(sys.path) == pathlen:
1050 print 'Could not find %r in sys.path to remove it' % mydir
Barry Warsaw08fca522001-08-20 22:33:46 +00001051 main()