blob: 34213ecb127171d03b639edc3bbb3dbc62516732 [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)
Guido van Rossum152494a1996-12-20 03:12:20 +000022
23If non-option arguments are present, they are names for tests to run,
24unless -x is given, in which case they are names for tests not to run.
25If no test names are given, all tests are run.
Guido van Rossumf58ed251997-03-07 21:04:33 +000026
Guido van Rossuma4122201997-08-18 20:08:24 +000027-v is incompatible with -g and does not compare test output files.
Barry Warsawe11e3de1999-01-28 19:51:51 +000028
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000029-s means to run only a single test and exit. This is useful when
30doing memory analysis on the Python interpreter (which tend to consume
31too many resources to run the full regression test non-stop). The
32file /tmp/pynexttest is read to find the next test to run. If this
33file is missing, the first test_*.py file in testdir or on the command
34line is used. (actually tempfile.gettempdir() is used instead of
35/tmp).
Barry Warsawe11e3de1999-01-28 19:51:51 +000036
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000037-f reads the names of tests from the file given as f's argument, one
38or more test names per line. Whitespace is ignored. Blank lines and
39lines beginning with '#' are ignored. This is especially useful for
40whittling down failures involving interactions among tests.
Tim Petersc5000df2002-06-02 21:42:01 +000041
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000042-u is used to specify which special resource intensive tests to run,
43such as those requiring large file support or network connectivity.
44The argument is a comma-separated list of words indicating the
45resources to test. Currently only the following are defined:
Barry Warsaw08fca522001-08-20 22:33:46 +000046
Fred Drake3a15dac2002-04-11 16:39:16 +000047 all - Enable all special resources.
48
Guido van Rossum315aa362003-03-11 14:46:48 +000049 audio - Tests that use the audio device. (There are known
50 cases of broken audio drivers that can crash Python or
51 even the Linux kernel.)
52
Andrew M. Kuchling2158df02001-10-22 15:26:09 +000053 curses - Tests that use curses and will modify the terminal's
54 state and output modes.
Tim Peters1633a2e2001-10-30 05:56:40 +000055
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000056 largefile - It is okay to run some test that may create huge
57 files. These tests can take a long time and may
58 consume >2GB of disk space temporarily.
Barry Warsaw08fca522001-08-20 22:33:46 +000059
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000060 network - It is okay to run tests that use external network
61 resource, e.g. testing SSL support for sockets.
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000062
63 bsddb - It is okay to run the bsddb testsuite, which takes
64 a long time to complete.
Fred Drake4dd0f7e2002-11-26 21:44:56 +000065
66To enable all resources except one, use '-uall,-<resource>'. For
67example, to run all the tests except for the bsddb tests, give the
68option '-uall,-bsddb'.
Guido van Rossum152494a1996-12-20 03:12:20 +000069"""
70
71import sys
Guido van Rossum152494a1996-12-20 03:12:20 +000072import os
73import getopt
Guido van Rossum9e48b271997-07-16 01:56:13 +000074import traceback
Skip Montanaroab1c7912000-06-30 16:39:27 +000075import random
Raymond Hettinger74e67662003-05-17 20:44:12 +000076import cStringIO
Guido van Rossumdc15c272002-08-12 21:55:51 +000077import warnings
78
79# I see no other way to suppress these warnings;
80# putting them in test_grammar.py has no effect:
Guido van Rossum88b1def2002-08-14 17:54:48 +000081warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
Guido van Rossumdc15c272002-08-12 21:55:51 +000082 ".*test.test_grammar$")
Guido van Rossumc34c4fc2002-09-19 00:42:16 +000083if sys.maxint > 0x7fffffff:
84 # Also suppress them in <string>, because for 64-bit platforms,
85 # that's where test_grammar.py hides them.
86 warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
87 "<string>")
Guido van Rossum152494a1996-12-20 03:12:20 +000088
Guido van Rossumbb484652002-12-02 09:56:21 +000089# MacOSX (a.k.a. Darwin) has a default stack size that is too small
90# for deeply recursive regular expressions. We see this as crashes in
91# the Python test suite when running test_re.py and test_sre.py. The
92# fix is to set the stack limit to 2048.
93# This approach may also be useful for other Unixy platforms that
94# suffer from small default stack limits.
95if sys.platform == 'darwin':
96 try:
97 import resource
98 except ImportError:
99 pass
100 else:
101 soft, hard = resource.getrlimit(resource.RLIMIT_STACK)
102 newsoft = min(hard, max(soft, 1024*2048))
103 resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard))
104
Barry Warsaw04f357c2002-07-23 19:04:11 +0000105from test import test_support
Fred Drake3a15dac2002-04-11 16:39:16 +0000106
Guido van Rossum315aa362003-03-11 14:46:48 +0000107RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', 'bsddb')
Fred Drake3a15dac2002-04-11 16:39:16 +0000108
109
Barry Warsaw08fca522001-08-20 22:33:46 +0000110def usage(code, msg=''):
111 print __doc__
112 if msg: print msg
113 sys.exit(code)
114
115
Skip Montanaroab1c7912000-06-30 16:39:27 +0000116def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
Tim Petersc5000df2002-06-02 21:42:01 +0000117 exclude=0, single=0, randomize=0, fromfile=None, findleaks=0,
Barry Warsaw08fca522001-08-20 22:33:46 +0000118 use_resources=None):
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000119 """Execute a test suite.
120
Thomas Wouters7e474022000-07-16 12:04:32 +0000121 This also parses command-line options and modifies its behavior
Fred Drake004d5e62000-10-23 17:22:08 +0000122 accordingly.
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000123
124 tests -- a list of strings containing test names (optional)
125 testdir -- the directory in which to look for tests (optional)
126
127 Users other than the Python test suite will certainly want to
128 specify testdir; if it's omitted, the directory containing the
Fred Drake004d5e62000-10-23 17:22:08 +0000129 Python test suite is searched for.
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000130
131 If the tests argument is omitted, the tests listed on the
132 command-line will be used. If that's empty, too, then all *.py
133 files beginning with test_ will be used.
Skip Montanaroab1c7912000-06-30 16:39:27 +0000134
Guido van Rossum9e9d4f82002-06-07 15:17:03 +0000135 The other default arguments (verbose, quiet, generate, exclude,
136 single, randomize, findleaks, and use_resources) allow programmers
137 calling main() directly to set the values that would normally be
138 set by flags on the command line.
Barry Warsawa873b032000-08-03 15:50:37 +0000139
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000140 """
Fred Drake004d5e62000-10-23 17:22:08 +0000141
Tim Peters8dee8092001-09-25 20:05:11 +0000142 test_support.record_original_stdout(sys.stdout)
Guido van Rossum152494a1996-12-20 03:12:20 +0000143 try:
Guido van Rossum9e9d4f82002-06-07 15:17:03 +0000144 opts, args = getopt.getopt(sys.argv[1:], 'hvgqxsrf:lu:t:',
Barry Warsaw08fca522001-08-20 22:33:46 +0000145 ['help', 'verbose', 'quiet', 'generate',
Tim Petersc5000df2002-06-02 21:42:01 +0000146 'exclude', 'single', 'random', 'fromfile',
Guido van Rossum9e9d4f82002-06-07 15:17:03 +0000147 'findleaks', 'use=', 'threshold='])
Guido van Rossum152494a1996-12-20 03:12:20 +0000148 except getopt.error, msg:
Barry Warsaw08fca522001-08-20 22:33:46 +0000149 usage(2, msg)
150
151 # Defaults
152 if use_resources is None:
153 use_resources = []
Guido van Rossum152494a1996-12-20 03:12:20 +0000154 for o, a in opts:
Barry Warsaw08fca522001-08-20 22:33:46 +0000155 if o in ('-h', '--help'):
156 usage(0)
157 elif o in ('-v', '--verbose'):
158 verbose += 1
159 elif o in ('-q', '--quiet'):
160 quiet = 1;
161 verbose = 0
162 elif o in ('-g', '--generate'):
163 generate = 1
164 elif o in ('-x', '--exclude'):
165 exclude = 1
166 elif o in ('-s', '--single'):
167 single = 1
168 elif o in ('-r', '--randomize'):
169 randomize = 1
Tim Petersc5000df2002-06-02 21:42:01 +0000170 elif o in ('-f', '--fromfile'):
171 fromfile = a
Barry Warsaw08fca522001-08-20 22:33:46 +0000172 elif o in ('-l', '--findleaks'):
173 findleaks = 1
Guido van Rossum9e9d4f82002-06-07 15:17:03 +0000174 elif o in ('-t', '--threshold'):
175 import gc
176 gc.set_threshold(int(a))
Barry Warsaw08fca522001-08-20 22:33:46 +0000177 elif o in ('-u', '--use'):
Guido van Rossumfe3f6962001-09-06 16:09:41 +0000178 u = [x.lower() for x in a.split(',')]
179 for r in u:
Fred Drake3a15dac2002-04-11 16:39:16 +0000180 if r == 'all':
Fred Drake4dd0f7e2002-11-26 21:44:56 +0000181 use_resources[:] = RESOURCE_NAMES
182 continue
183 remove = False
184 if r[0] == '-':
185 remove = True
186 r = r[1:]
Fred Drake3a15dac2002-04-11 16:39:16 +0000187 if r not in RESOURCE_NAMES:
188 usage(1, 'Invalid -u/--use option: ' + a)
Fred Drake4dd0f7e2002-11-26 21:44:56 +0000189 if remove:
190 if r in use_resources:
191 use_resources.remove(r)
192 elif r not in use_resources:
Andrew MacIntyree41abab2002-04-30 12:11:04 +0000193 use_resources.append(r)
Guido van Rossuma4122201997-08-18 20:08:24 +0000194 if generate and verbose:
Barry Warsaw08fca522001-08-20 22:33:46 +0000195 usage(2, "-g and -v don't go together!")
Tim Petersc5000df2002-06-02 21:42:01 +0000196 if single and fromfile:
197 usage(2, "-s and -f don't go together!")
Barry Warsaw08fca522001-08-20 22:33:46 +0000198
Guido van Rossum152494a1996-12-20 03:12:20 +0000199 good = []
200 bad = []
201 skipped = []
Fred Drake9a0db072003-02-03 15:19:30 +0000202 resource_denieds = []
Barry Warsawe11e3de1999-01-28 19:51:51 +0000203
Neil Schemenauerd569f232000-09-22 15:29:28 +0000204 if findleaks:
Barry Warsawa873b032000-08-03 15:50:37 +0000205 try:
206 import gc
207 except ImportError:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000208 print 'No GC available, disabling findleaks.'
Neil Schemenauerd569f232000-09-22 15:29:28 +0000209 findleaks = 0
Barry Warsawa873b032000-08-03 15:50:37 +0000210 else:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000211 # Uncomment the line below to report garbage that is not
212 # freeable by reference counting alone. By default only
213 # garbage that is not collectable by the GC is reported.
214 #gc.set_debug(gc.DEBUG_SAVEALL)
Neil Schemenauerd569f232000-09-22 15:29:28 +0000215 found_garbage = []
Barry Warsawa873b032000-08-03 15:50:37 +0000216
Barry Warsawe11e3de1999-01-28 19:51:51 +0000217 if single:
218 from tempfile import gettempdir
219 filename = os.path.join(gettempdir(), 'pynexttest')
220 try:
221 fp = open(filename, 'r')
Eric S. Raymondfc170b12001-02-09 11:51:27 +0000222 next = fp.read().strip()
Barry Warsawe11e3de1999-01-28 19:51:51 +0000223 tests = [next]
224 fp.close()
225 except IOError:
226 pass
Tim Petersc5000df2002-06-02 21:42:01 +0000227
228 if fromfile:
229 tests = []
230 fp = open(fromfile)
231 for line in fp:
232 guts = line.split() # assuming no test has whitespace in its name
233 if guts and not guts[0].startswith('#'):
234 tests.extend(guts)
235 fp.close()
236
237 # Strip .py extensions.
238 if args:
239 args = map(removepy, args)
240 if tests:
241 tests = map(removepy, tests)
242
Guido van Rossum6c74fea1998-08-25 12:29:08 +0000243 stdtests = STDTESTS[:]
244 nottests = NOTTESTS[:]
Guido van Rossum152494a1996-12-20 03:12:20 +0000245 if exclude:
Guido van Rossum6c74fea1998-08-25 12:29:08 +0000246 for arg in args:
247 if arg in stdtests:
248 stdtests.remove(arg)
249 nottests[:0] = args
Guido van Rossum41360a41998-03-26 19:42:58 +0000250 args = []
Guido van Rossum747e1ca1998-08-24 13:48:36 +0000251 tests = tests or args or findtests(testdir, stdtests, nottests)
Barry Warsawe11e3de1999-01-28 19:51:51 +0000252 if single:
253 tests = tests[:1]
Skip Montanaroab1c7912000-06-30 16:39:27 +0000254 if randomize:
255 random.shuffle(tests)
Guido van Rossum41360a41998-03-26 19:42:58 +0000256 test_support.verbose = verbose # Tell tests to be moderately quiet
Barry Warsaw08fca522001-08-20 22:33:46 +0000257 test_support.use_resources = use_resources
Guido van Rossum5796d262000-04-21 21:35:06 +0000258 save_modules = sys.modules.keys()
Guido van Rossum152494a1996-12-20 03:12:20 +0000259 for test in tests:
Guido van Rossum41360a41998-03-26 19:42:58 +0000260 if not quiet:
261 print test
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000262 sys.stdout.flush()
Trent Mickf29f47b2000-08-11 19:02:59 +0000263 ok = runtest(test, generate, verbose, quiet, testdir)
Guido van Rossum41360a41998-03-26 19:42:58 +0000264 if ok > 0:
265 good.append(test)
266 elif ok == 0:
267 bad.append(test)
268 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000269 skipped.append(test)
Fred Drake9a0db072003-02-03 15:19:30 +0000270 if ok == -2:
271 resource_denieds.append(test)
Neil Schemenauerd569f232000-09-22 15:29:28 +0000272 if findleaks:
273 gc.collect()
274 if gc.garbage:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000275 print "Warning: test created", len(gc.garbage),
276 print "uncollectable object(s)."
277 # move the uncollectable objects somewhere so we don't see
278 # them again
Neil Schemenauerd569f232000-09-22 15:29:28 +0000279 found_garbage.extend(gc.garbage)
280 del gc.garbage[:]
Guido van Rossum5796d262000-04-21 21:35:06 +0000281 # Unload the newly imported modules (best effort finalization)
282 for module in sys.modules.keys():
Guido van Rossum51931142000-05-05 14:27:39 +0000283 if module not in save_modules and module.startswith("test."):
Guido van Rossum5796d262000-04-21 21:35:06 +0000284 test_support.unload(module)
Jeremy Hylton7a1ea0e2001-10-17 13:45:28 +0000285
286 # The lists won't be sorted if running with -r
287 good.sort()
288 bad.sort()
289 skipped.sort()
Tim Peterse0c446b2001-10-18 21:57:37 +0000290
Guido van Rossum152494a1996-12-20 03:12:20 +0000291 if good and not quiet:
Guido van Rossum41360a41998-03-26 19:42:58 +0000292 if not bad and not skipped and len(good) > 1:
293 print "All",
294 print count(len(good), "test"), "OK."
Tim Peters1a4d77b2000-12-30 22:21:22 +0000295 if verbose:
Barry Warsaw408b6d32002-07-30 23:27:12 +0000296 print "CAUTION: stdout isn't compared in verbose mode:"
297 print "a test that passes in verbose mode may fail without it."
Guido van Rossum152494a1996-12-20 03:12:20 +0000298 if bad:
Tim Petersa45da922001-08-12 03:45:50 +0000299 print count(len(bad), "test"), "failed:"
300 printlist(bad)
Guido van Rossum152494a1996-12-20 03:12:20 +0000301 if skipped and not quiet:
Tim Petersa45da922001-08-12 03:45:50 +0000302 print count(len(skipped), "test"), "skipped:"
303 printlist(skipped)
Barry Warsawe11e3de1999-01-28 19:51:51 +0000304
Tim Petersb5b7b782001-08-12 01:20:39 +0000305 e = _ExpectedSkips()
Tim Petersa2be2d62001-08-12 02:01:09 +0000306 plat = sys.platform
Tim Petersb5b7b782001-08-12 01:20:39 +0000307 if e.isvalid():
Raymond Hettingera690a992003-11-16 16:17:49 +0000308 surprise = set(skipped) - e.getexpected() - set(resource_denieds)
Tim Petersb5b7b782001-08-12 01:20:39 +0000309 if surprise:
310 print count(len(surprise), "skip"), \
Tim Petersa45da922001-08-12 03:45:50 +0000311 "unexpected on", plat + ":"
312 printlist(surprise)
Tim Petersb5b7b782001-08-12 01:20:39 +0000313 else:
314 print "Those skips are all expected on", plat + "."
315 else:
316 print "Ask someone to teach regrtest.py about which tests are"
317 print "expected to get skipped on", plat + "."
318
Barry Warsawe11e3de1999-01-28 19:51:51 +0000319 if single:
320 alltests = findtests(testdir, stdtests, nottests)
321 for i in range(len(alltests)):
322 if tests[0] == alltests[i]:
323 if i == len(alltests) - 1:
324 os.unlink(filename)
325 else:
326 fp = open(filename, 'w')
327 fp.write(alltests[i+1] + '\n')
328 fp.close()
329 break
330 else:
331 os.unlink(filename)
332
Tim Peters5943b4a2003-07-23 00:30:39 +0000333 sys.exit(len(bad) > 0)
Barry Warsaw08fca522001-08-20 22:33:46 +0000334
Guido van Rossum152494a1996-12-20 03:12:20 +0000335
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000336STDTESTS = [
Guido van Rossum152494a1996-12-20 03:12:20 +0000337 'test_grammar',
338 'test_opcodes',
339 'test_operations',
340 'test_builtin',
341 'test_exceptions',
342 'test_types',
343 ]
344
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000345NOTTESTS = [
Guido van Rossum152494a1996-12-20 03:12:20 +0000346 'test_support',
Jeremy Hylton62e2c7e2001-02-28 17:48:06 +0000347 'test_future1',
348 'test_future2',
Jeremy Hylton8471a352001-08-20 20:33:42 +0000349 'test_future3',
Guido van Rossum152494a1996-12-20 03:12:20 +0000350 ]
351
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000352def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
Guido van Rossum152494a1996-12-20 03:12:20 +0000353 """Return a list of all applicable test modules."""
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000354 if not testdir: testdir = findtestdir()
Guido van Rossum152494a1996-12-20 03:12:20 +0000355 names = os.listdir(testdir)
356 tests = []
357 for name in names:
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000358 if name[:5] == "test_" and name[-3:] == os.extsep+"py":
Guido van Rossum41360a41998-03-26 19:42:58 +0000359 modname = name[:-3]
360 if modname not in stdtests and modname not in nottests:
361 tests.append(modname)
Guido van Rossum152494a1996-12-20 03:12:20 +0000362 tests.sort()
363 return stdtests + tests
364
Trent Mickf29f47b2000-08-11 19:02:59 +0000365def runtest(test, generate, verbose, quiet, testdir = None):
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000366 """Run a single test.
367 test -- the name of the test
368 generate -- if true, generate output, instead of running the test
369 and comparing it to a previously created output file
370 verbose -- if true, print more messages
Trent Mickf29f47b2000-08-11 19:02:59 +0000371 quiet -- if true, don't print 'skipped' messages (probably redundant)
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000372 testdir -- test directory
373 """
Guido van Rossum152494a1996-12-20 03:12:20 +0000374 test_support.unload(test)
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000375 if not testdir: testdir = findtestdir()
Guido van Rossum152494a1996-12-20 03:12:20 +0000376 outputdir = os.path.join(testdir, "output")
377 outputfile = os.path.join(outputdir, test)
Tim Peters9390cc12001-09-28 20:14:46 +0000378 if verbose:
Guido van Rossum41360a41998-03-26 19:42:58 +0000379 cfp = None
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000380 else:
Raymond Hettinger74e67662003-05-17 20:44:12 +0000381 cfp = cStringIO.StringIO()
Guido van Rossum152494a1996-12-20 03:12:20 +0000382 try:
Tim Peters342ca752001-09-25 19:13:20 +0000383 save_stdout = sys.stdout
Guido van Rossum41360a41998-03-26 19:42:58 +0000384 try:
385 if cfp:
386 sys.stdout = cfp
387 print test # Output file starts with test name
Barry Warsaw408b6d32002-07-30 23:27:12 +0000388 if test.startswith('test.'):
389 abstest = test
390 else:
391 # Always import it from the test package
392 abstest = 'test.' + test
393 the_package = __import__(abstest, globals(), locals(), [])
394 the_module = getattr(the_package, test)
Tim Petersd9742212001-05-22 18:28:25 +0000395 # Most tests run to completion simply as a side-effect of
396 # being imported. For the benefit of tests that can't run
397 # that way (like test_threaded_import), explicitly invoke
398 # their test_main() function (if it exists).
399 indirect_test = getattr(the_module, "test_main", None)
400 if indirect_test is not None:
401 indirect_test()
Guido van Rossum41360a41998-03-26 19:42:58 +0000402 finally:
Tim Peters342ca752001-09-25 19:13:20 +0000403 sys.stdout = save_stdout
Fred Drake9a0db072003-02-03 15:19:30 +0000404 except test_support.ResourceDenied, msg:
405 if not quiet:
406 print test, "skipped --", msg
407 sys.stdout.flush()
408 return -2
Thomas Wouters3af826e2000-08-04 13:17:51 +0000409 except (ImportError, test_support.TestSkipped), msg:
Trent Mickf29f47b2000-08-11 19:02:59 +0000410 if not quiet:
Fred Drakede4742b2002-10-17 20:36:08 +0000411 print test, "skipped --", msg
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000412 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000413 return -1
Fred Drakefe5c22a2000-08-18 16:04:05 +0000414 except KeyboardInterrupt:
415 raise
Guido van Rossum152494a1996-12-20 03:12:20 +0000416 except test_support.TestFailed, msg:
Guido van Rossum41360a41998-03-26 19:42:58 +0000417 print "test", test, "failed --", msg
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000418 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000419 return 0
Guido van Rossum9e48b271997-07-16 01:56:13 +0000420 except:
Guido van Rossum41360a41998-03-26 19:42:58 +0000421 type, value = sys.exc_info()[:2]
Fred Drake27c4b392000-08-23 20:34:40 +0000422 print "test", test, "crashed --", str(type) + ":", value
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000423 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000424 if verbose:
425 traceback.print_exc(file=sys.stdout)
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000426 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000427 return 0
Guido van Rossum152494a1996-12-20 03:12:20 +0000428 else:
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000429 if not cfp:
430 return 1
431 output = cfp.getvalue()
Fred Drakee51fe8d2001-05-29 17:10:51 +0000432 if generate:
Fred Drakee51fe8d2001-05-29 17:10:51 +0000433 if output == test + "\n":
434 if os.path.exists(outputfile):
435 # Write it since it already exists (and the contents
436 # may have changed), but let the user know it isn't
437 # needed:
Fred Drakee51fe8d2001-05-29 17:10:51 +0000438 print "output file", outputfile, \
439 "is no longer needed; consider removing it"
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000440 else:
441 # We don't need it, so don't create it.
442 return 1
443 fp = open(outputfile, "w")
444 fp.write(output)
445 fp.close()
446 return 1
447 if os.path.exists(outputfile):
448 fp = open(outputfile, "r")
449 expected = fp.read()
450 fp.close()
451 else:
452 expected = test + "\n"
453 if output == expected:
454 return 1
455 print "test", test, "produced unexpected output:"
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000456 sys.stdout.flush()
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000457 reportdiff(expected, output)
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000458 sys.stdout.flush()
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000459 return 0
460
461def reportdiff(expected, output):
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000462 import difflib
Tim Petersc377b162001-09-22 05:31:03 +0000463 print "*" * 70
464 a = expected.splitlines(1)
465 b = output.splitlines(1)
Guido van Rossumcf691932001-09-21 21:06:22 +0000466 sm = difflib.SequenceMatcher(a=a, b=b)
467 tuples = sm.get_opcodes()
Tim Petersc377b162001-09-22 05:31:03 +0000468
Guido van Rossumcf691932001-09-21 21:06:22 +0000469 def pair(x0, x1):
Tim Petersc377b162001-09-22 05:31:03 +0000470 # x0:x1 are 0-based slice indices; convert to 1-based line indices.
Guido van Rossumcf691932001-09-21 21:06:22 +0000471 x0 += 1
472 if x0 >= x1:
Tim Petersc377b162001-09-22 05:31:03 +0000473 return "line " + str(x0)
Guido van Rossumcf691932001-09-21 21:06:22 +0000474 else:
Tim Petersc377b162001-09-22 05:31:03 +0000475 return "lines %d-%d" % (x0, x1)
476
Guido van Rossumcf691932001-09-21 21:06:22 +0000477 for op, a0, a1, b0, b1 in tuples:
478 if op == 'equal':
479 pass
Tim Petersc377b162001-09-22 05:31:03 +0000480
Guido van Rossumcf691932001-09-21 21:06:22 +0000481 elif op == 'delete':
Tim Petersc377b162001-09-22 05:31:03 +0000482 print "***", pair(a0, a1), "of expected output missing:"
Guido van Rossumcf691932001-09-21 21:06:22 +0000483 for line in a[a0:a1]:
Tim Petersc377b162001-09-22 05:31:03 +0000484 print "-", line,
485
Guido van Rossumcf691932001-09-21 21:06:22 +0000486 elif op == 'replace':
Tim Petersc377b162001-09-22 05:31:03 +0000487 print "*** mismatch between", pair(a0, a1), "of expected", \
488 "output and", pair(b0, b1), "of actual output:"
489 for line in difflib.ndiff(a[a0:a1], b[b0:b1]):
490 print line,
491
Guido van Rossumcf691932001-09-21 21:06:22 +0000492 elif op == 'insert':
Tim Petersc377b162001-09-22 05:31:03 +0000493 print "***", pair(b0, b1), "of actual output doesn't appear", \
494 "in expected output after line", str(a1)+":"
Guido van Rossumcf691932001-09-21 21:06:22 +0000495 for line in b[b0:b1]:
Tim Petersc377b162001-09-22 05:31:03 +0000496 print "+", line,
497
Guido van Rossumcf691932001-09-21 21:06:22 +0000498 else:
499 print "get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1)
Tim Petersc377b162001-09-22 05:31:03 +0000500
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000501 print "*" * 70
Guido van Rossum152494a1996-12-20 03:12:20 +0000502
503def findtestdir():
504 if __name__ == '__main__':
Guido van Rossum41360a41998-03-26 19:42:58 +0000505 file = sys.argv[0]
Guido van Rossum152494a1996-12-20 03:12:20 +0000506 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000507 file = __file__
Guido van Rossum152494a1996-12-20 03:12:20 +0000508 testdir = os.path.dirname(file) or os.curdir
509 return testdir
510
Tim Petersc5000df2002-06-02 21:42:01 +0000511def removepy(name):
512 if name.endswith(os.extsep + "py"):
513 name = name[:-3]
514 return name
515
Guido van Rossum152494a1996-12-20 03:12:20 +0000516def count(n, word):
517 if n == 1:
Guido van Rossum41360a41998-03-26 19:42:58 +0000518 return "%d %s" % (n, word)
Guido van Rossum152494a1996-12-20 03:12:20 +0000519 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000520 return "%d %ss" % (n, word)
Guido van Rossum152494a1996-12-20 03:12:20 +0000521
Tim Petersa45da922001-08-12 03:45:50 +0000522def printlist(x, width=70, indent=4):
Tim Peters7c7efe92002-08-23 17:55:54 +0000523 """Print the elements of iterable x to stdout.
Tim Petersa45da922001-08-12 03:45:50 +0000524
525 Optional arg width (default 70) is the maximum line length.
526 Optional arg indent (default 4) is the number of blanks with which to
527 begin each line.
528 """
529
Tim Petersba78bc42002-07-04 19:45:06 +0000530 from textwrap import fill
531 blanks = ' ' * indent
532 print fill(' '.join(map(str, x)), width,
533 initial_indent=blanks, subsequent_indent=blanks)
Tim Petersa45da922001-08-12 03:45:50 +0000534
Tim Petersde14a302002-04-01 05:04:46 +0000535# Map sys.platform to a string containing the basenames of tests
536# expected to be skipped on that platform.
Tim Peters2a182db2002-10-09 01:07:11 +0000537#
538# Special cases:
539# test_pep277
540# The _ExpectedSkips constructor adds this to the set of expected
541# skips if not os.path.supports_unicode_filenames.
Tim Peters1b445d32002-11-24 18:53:11 +0000542# test_normalization
543# Whether a skip is expected here depends on whether a large test
544# input file has been downloaded. test_normalization.skip_expected
Tim Peters1babdfc2002-11-24 19:19:09 +0000545# controls that.
Tim Petersb4ee4eb2002-12-04 03:26:57 +0000546# test_socket_ssl
547# Controlled by test_socket_ssl.skip_expected. Requires the network
548# resource, and a socket module with ssl support.
Neal Norwitz55b61d22003-02-28 19:57:03 +0000549# test_timeout
550# Controlled by test_timeout.skip_expected. Requires the network
551# resource and a socket module.
Tim Petersde14a302002-04-01 05:04:46 +0000552
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000553_expectations = {
554 'win32':
555 """
Tim Petersc7c516a2003-09-20 22:06:13 +0000556 test__locale
Raymond Hettinger901dc982003-11-20 19:02:02 +0000557 test_applesingle
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000558 test_al
Skip Montanaro823ba282003-05-06 20:36:24 +0000559 test_bsddb185
Tim Peters78e35f92002-11-22 20:00:34 +0000560 test_bsddb3
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000561 test_cd
562 test_cl
563 test_commands
564 test_crypt
Tim Petersd7030572001-10-22 22:06:08 +0000565 test_curses
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000566 test_dbm
567 test_dl
Tim Petersdeb121a2002-04-11 19:52:58 +0000568 test_email_codecs
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000569 test_fcntl
570 test_fork1
571 test_gdbm
572 test_gl
573 test_grp
574 test_imgfile
Tim Petersfd8e6e52003-03-04 00:26:38 +0000575 test_ioctl
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000576 test_largefile
577 test_linuxaudiodev
578 test_mhlib
Tim Petersde14a302002-04-01 05:04:46 +0000579 test_mpz
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000580 test_nis
581 test_openpty
Tim Petersefc4b122002-12-10 18:47:56 +0000582 test_ossaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000583 test_poll
Tim Peters003eb302003-02-17 21:48:48 +0000584 test_posix
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000585 test_pty
586 test_pwd
Tim Peters1e33ffa2002-04-23 23:09:02 +0000587 test_resource
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000588 test_signal
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000589 test_sunaudiodev
590 test_timing
591 """,
592 'linux2':
593 """
594 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000595 test_applesingle
Skip Montanaro823ba282003-05-06 20:36:24 +0000596 test_bsddb185
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000597 test_cd
598 test_cl
Guido van Rossumf66dacd2001-10-23 15:10:55 +0000599 test_curses
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000600 test_dl
Guido van Rossum6184c112002-04-16 02:14:04 +0000601 test_email_codecs
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000602 test_gl
603 test_imgfile
604 test_largefile
Guido van Rossum4507ec72003-02-14 19:29:22 +0000605 test_linuxaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000606 test_nis
607 test_ntpath
Guido van Rossum4507ec72003-02-14 19:29:22 +0000608 test_ossaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000609 test_sunaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000610 """,
Jack Jansen49a806e2001-08-28 14:49:00 +0000611 'mac':
Guido van Rossumaa782362001-09-02 03:58:41 +0000612 """
613 test_al
Jack Jansen67975142003-01-08 16:31:11 +0000614 test_atexit
Guido van Rossumaa782362001-09-02 03:58:41 +0000615 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000616 test_bsddb185
Jack Jansen67975142003-01-08 16:31:11 +0000617 test_bsddb3
618 test_bz2
Guido van Rossumaa782362001-09-02 03:58:41 +0000619 test_cd
620 test_cl
621 test_commands
622 test_crypt
Jack Jansenb3be2162001-11-30 14:16:36 +0000623 test_curses
Guido van Rossumaa782362001-09-02 03:58:41 +0000624 test_dbm
625 test_dl
Jack Jansen67975142003-01-08 16:31:11 +0000626 test_email_codecs
Guido van Rossumaa782362001-09-02 03:58:41 +0000627 test_fcntl
628 test_fork1
629 test_gl
630 test_grp
Jack Jansenc4d6bdd2003-03-07 15:38:11 +0000631 test_ioctl
Guido van Rossumaa782362001-09-02 03:58:41 +0000632 test_imgfile
633 test_largefile
634 test_linuxaudiodev
635 test_locale
636 test_mmap
Jack Jansen67975142003-01-08 16:31:11 +0000637 test_mpz
Guido van Rossumaa782362001-09-02 03:58:41 +0000638 test_nis
639 test_ntpath
640 test_openpty
Jack Jansen67975142003-01-08 16:31:11 +0000641 test_ossaudiodev
Guido van Rossumaa782362001-09-02 03:58:41 +0000642 test_poll
Jack Jansen67975142003-01-08 16:31:11 +0000643 test_popen
Guido van Rossumaa782362001-09-02 03:58:41 +0000644 test_popen2
Jack Jansen5bb97e62003-02-21 22:33:55 +0000645 test_posix
Guido van Rossumaa782362001-09-02 03:58:41 +0000646 test_pty
647 test_pwd
Jack Jansen67975142003-01-08 16:31:11 +0000648 test_resource
Guido van Rossumaa782362001-09-02 03:58:41 +0000649 test_signal
Guido van Rossumaa782362001-09-02 03:58:41 +0000650 test_sunaudiodev
651 test_sundry
Jack Jansenc4d6bdd2003-03-07 15:38:11 +0000652 test_tarfile
Guido van Rossumaa782362001-09-02 03:58:41 +0000653 test_timing
Guido van Rossumaa782362001-09-02 03:58:41 +0000654 """,
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000655 'unixware7':
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000656 """
657 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000658 test_applesingle
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000659 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000660 test_bsddb185
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000661 test_cd
662 test_cl
663 test_dl
664 test_gl
665 test_imgfile
666 test_largefile
667 test_linuxaudiodev
668 test_minidom
669 test_nis
670 test_ntpath
671 test_openpty
672 test_pyexpat
673 test_sax
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000674 test_sunaudiodev
675 test_sundry
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000676 """,
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000677 'openunix8':
678 """
679 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000680 test_applesingle
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000681 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000682 test_bsddb185
Martin v. Löwis21ee4092002-09-30 16:19: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öwis21ee4092002-09-30 16:19:48 +0000696 test_sunaudiodev
697 test_sundry
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000698 """,
699 'sco_sv3':
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_asynchat
704 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000705 test_bsddb185
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000706 test_cd
707 test_cl
708 test_dl
709 test_fork1
710 test_gettext
711 test_gl
712 test_imgfile
713 test_largefile
714 test_linuxaudiodev
715 test_locale
716 test_minidom
717 test_nis
718 test_ntpath
719 test_openpty
720 test_pyexpat
721 test_queue
722 test_sax
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000723 test_sunaudiodev
724 test_sundry
725 test_thread
726 test_threaded_import
727 test_threadedtempfile
728 test_threading
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000729 """,
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000730 'riscos':
731 """
732 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000733 test_applesingle
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000734 test_asynchat
Martin v. Löwisa94568a2003-05-10 07:36:56 +0000735 test_atexit
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000736 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000737 test_bsddb185
Martin v. Löwisa94568a2003-05-10 07:36:56 +0000738 test_bsddb3
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000739 test_cd
740 test_cl
741 test_commands
742 test_crypt
743 test_dbm
744 test_dl
745 test_fcntl
746 test_fork1
747 test_gdbm
748 test_gl
749 test_grp
750 test_imgfile
751 test_largefile
752 test_linuxaudiodev
753 test_locale
754 test_mmap
755 test_nis
756 test_ntpath
757 test_openpty
758 test_poll
759 test_popen2
760 test_pty
761 test_pwd
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000762 test_strop
763 test_sunaudiodev
764 test_sundry
765 test_thread
766 test_threaded_import
767 test_threadedtempfile
768 test_threading
769 test_timing
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000770 """,
Jack Jansen8a97f4a2001-12-05 23:27:32 +0000771 'darwin':
Jack Jansen398c2362001-12-02 21:41:36 +0000772 """
Brett Cannon2bfb94c2003-10-13 04:27:47 +0000773 test__locale
Jack Jansen398c2362001-12-02 21:41:36 +0000774 test_al
Jack Jansenacda3392002-12-30 23:03:13 +0000775 test_bsddb
Guido van Rossum9d427002002-12-03 10:24:56 +0000776 test_bsddb3
Jack Jansen398c2362001-12-02 21:41:36 +0000777 test_cd
778 test_cl
779 test_curses
780 test_dl
Guido van Rossum9d427002002-12-03 10:24:56 +0000781 test_email_codecs
Jack Jansen398c2362001-12-02 21:41:36 +0000782 test_gdbm
783 test_gl
784 test_imgfile
785 test_largefile
786 test_linuxaudiodev
Jack Jansenacda3392002-12-30 23:03:13 +0000787 test_locale
Jack Jansen398c2362001-12-02 21:41:36 +0000788 test_minidom
Guido van Rossum9d427002002-12-03 10:24:56 +0000789 test_mpz
Jack Jansen398c2362001-12-02 21:41:36 +0000790 test_nis
791 test_ntpath
Jack Jansenacda3392002-12-30 23:03:13 +0000792 test_ossaudiodev
Jack Jansen398c2362001-12-02 21:41:36 +0000793 test_poll
Jack Jansen398c2362001-12-02 21:41:36 +0000794 test_sunaudiodev
Jack Jansen398c2362001-12-02 21:41:36 +0000795 """,
Guido van Rossum11c3f092002-07-17 15:08:24 +0000796 'sunos5':
797 """
798 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000799 test_applesingle
Guido van Rossum11c3f092002-07-17 15:08:24 +0000800 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000801 test_bsddb185
Guido van Rossum11c3f092002-07-17 15:08:24 +0000802 test_cd
803 test_cl
804 test_curses
805 test_dbm
806 test_email_codecs
807 test_gdbm
808 test_gl
809 test_gzip
810 test_imgfile
811 test_linuxaudiodev
812 test_mpz
813 test_openpty
Guido van Rossum11c3f092002-07-17 15:08:24 +0000814 test_zipfile
815 test_zlib
Jeremy Hyltoned375e12002-07-17 15:56:55 +0000816 """,
Skip Montanarob3230212002-03-15 02:54:03 +0000817 'hp-ux11':
818 """
819 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000820 test_applesingle
Skip Montanarob3230212002-03-15 02:54:03 +0000821 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000822 test_bsddb185
Skip Montanarob3230212002-03-15 02:54:03 +0000823 test_cd
824 test_cl
825 test_curses
826 test_dl
827 test_gdbm
828 test_gl
829 test_gzip
830 test_imgfile
831 test_largefile
832 test_linuxaudiodev
833 test_locale
834 test_minidom
835 test_nis
836 test_ntpath
837 test_openpty
838 test_pyexpat
839 test_sax
Skip Montanarob3230212002-03-15 02:54:03 +0000840 test_sunaudiodev
Skip Montanarob3230212002-03-15 02:54:03 +0000841 test_zipfile
842 test_zlib
843 """,
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000844 'atheos':
Tim Petersc411dba2002-07-16 21:35:23 +0000845 """
846 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000847 test_applesingle
Skip Montanaro823ba282003-05-06 20:36:24 +0000848 test_bsddb185
Tim Petersc411dba2002-07-16 21:35:23 +0000849 test_cd
850 test_cl
851 test_curses
852 test_dl
853 test_email_codecs
854 test_gdbm
855 test_gl
856 test_imgfile
857 test_largefile
858 test_linuxaudiodev
859 test_locale
860 test_mhlib
861 test_mmap
862 test_mpz
863 test_nis
864 test_poll
865 test_popen2
866 test_resource
Tim Petersc411dba2002-07-16 21:35:23 +0000867 test_sunaudiodev
Tim Petersc411dba2002-07-16 21:35:23 +0000868 """,
Jason Tishler25115942002-12-05 15:18:15 +0000869 'cygwin':
870 """
871 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000872 test_applesingle
Skip Montanaro823ba282003-05-06 20:36:24 +0000873 test_bsddb185
Tim Petersb0f89e02002-12-05 17:20:25 +0000874 test_bsddb3
Jason Tishler25115942002-12-05 15:18:15 +0000875 test_cd
876 test_cl
877 test_curses
878 test_dbm
879 test_email_codecs
880 test_gl
881 test_imgfile
Jason Tishlerc23f39c2003-07-22 18:35:58 +0000882 test_ioctl
Jason Tishler25115942002-12-05 15:18:15 +0000883 test_largefile
884 test_linuxaudiodev
885 test_locale
886 test_mpz
887 test_nis
Jason Tishler5c4ded22003-02-05 16:46:01 +0000888 test_ossaudiodev
Jason Tishler25115942002-12-05 15:18:15 +0000889 test_socketserver
890 test_sunaudiodev
Jason Tishler25115942002-12-05 15:18:15 +0000891 """,
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000892 'os2emx':
893 """
894 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000895 test_applesingle
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000896 test_audioop
Skip Montanaro823ba282003-05-06 20:36:24 +0000897 test_bsddb185
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000898 test_bsddb3
899 test_cd
900 test_cl
901 test_commands
902 test_curses
903 test_dl
904 test_email_codecs
905 test_gl
906 test_imgfile
907 test_largefile
908 test_linuxaudiodev
909 test_mhlib
910 test_mmap
911 test_nis
912 test_openpty
913 test_ossaudiodev
914 test_pty
915 test_resource
916 test_signal
917 test_sunaudiodev
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000918 """,
Guido van Rossum944a6c32003-11-20 22:11:29 +0000919 'freebsd4':
920 """
921 test_aepack
922 test_al
923 test_applesingle
924 test_bsddb
925 test_bsddb3
926 test_cd
927 test_cl
928 test_email_codecs
929 test_gl
930 test_imgfile
931 test_linuxaudiodev
932 test_locale
933 test_macfs
934 test_macostools
935 test_nis
936 test_normalization
937 test_ossaudiodev
938 test_pep277
939 test_plistlib
940 test_scriptpackages
941 test_socket_ssl
942 test_socketserver
943 test_sunaudiodev
944 test_timeout
945 test_unicode_file
946 test_urllibnet
947 test_winreg
948 test_winsound
Martin v. Löwis56f88112003-06-07 20:01:37 +0000949 """,
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000950}
951
Tim Petersb5b7b782001-08-12 01:20:39 +0000952class _ExpectedSkips:
953 def __init__(self):
Tim Peters2a182db2002-10-09 01:07:11 +0000954 import os.path
Tim Peters1b445d32002-11-24 18:53:11 +0000955 from test import test_normalization
Tim Petersb4ee4eb2002-12-04 03:26:57 +0000956 from test import test_socket_ssl
Neal Norwitz55b61d22003-02-28 19:57:03 +0000957 from test import test_timeout
Tim Peters1b445d32002-11-24 18:53:11 +0000958
Tim Peters7c7efe92002-08-23 17:55:54 +0000959 self.valid = False
Tim Petersde14a302002-04-01 05:04:46 +0000960 if sys.platform in _expectations:
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000961 s = _expectations[sys.platform]
Raymond Hettingera690a992003-11-16 16:17:49 +0000962 self.expected = set(s.split())
Tim Peters1b445d32002-11-24 18:53:11 +0000963
Tim Peters2a182db2002-10-09 01:07:11 +0000964 if not os.path.supports_unicode_filenames:
965 self.expected.add('test_pep277')
Tim Peters1b445d32002-11-24 18:53:11 +0000966
967 if test_normalization.skip_expected:
968 self.expected.add('test_normalization')
969
Tim Petersb4ee4eb2002-12-04 03:26:57 +0000970 if test_socket_ssl.skip_expected:
971 self.expected.add('test_socket_ssl')
972
Neal Norwitz55b61d22003-02-28 19:57:03 +0000973 if test_timeout.skip_expected:
974 self.expected.add('test_timeout')
975
Jack Jansen6afc5e02003-01-29 16:24:16 +0000976 if not sys.platform in ("mac", "darwin"):
Neal Norwitz7035c982003-03-29 22:01:17 +0000977 MAC_ONLY = ["test_macostools", "test_macfs", "test_aepack",
978 "test_plistlib", "test_scriptpackages"]
979 for skip in MAC_ONLY:
980 self.expected.add(skip)
Tim Petersecd79eb2003-01-29 00:35:32 +0000981
982 if sys.platform != "win32":
Neal Norwitz7035c982003-03-29 22:01:17 +0000983 WIN_ONLY = ["test_unicode_file", "test_winreg",
984 "test_winsound"]
985 for skip in WIN_ONLY:
986 self.expected.add(skip)
Tim Petersf2715e02003-02-19 02:35:07 +0000987
Tim Peters7c7efe92002-08-23 17:55:54 +0000988 self.valid = True
Tim Petersb5b7b782001-08-12 01:20:39 +0000989
990 def isvalid(self):
991 "Return true iff _ExpectedSkips knows about the current platform."
992 return self.valid
993
994 def getexpected(self):
995 """Return set of test names we expect to skip on current platform.
996
997 self.isvalid() must be true.
998 """
999
1000 assert self.isvalid()
1001 return self.expected
1002
Guido van Rossum152494a1996-12-20 03:12:20 +00001003if __name__ == '__main__':
Barry Warsaw408b6d32002-07-30 23:27:12 +00001004 # Remove regrtest.py's own directory from the module search path. This
1005 # prevents relative imports from working, and relative imports will screw
1006 # up the testing framework. E.g. if both test.test_support and
1007 # test_support are imported, they will not contain the same globals, and
1008 # much of the testing framework relies on the globals in the
1009 # test.test_support module.
1010 mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
1011 i = pathlen = len(sys.path)
1012 while i >= 0:
1013 i -= 1
1014 if os.path.abspath(os.path.normpath(sys.path[i])) == mydir:
1015 del sys.path[i]
1016 if len(sys.path) == pathlen:
1017 print 'Could not find %r in sys.path to remove it' % mydir
Barry Warsaw08fca522001-08-20 22:33:46 +00001018 main()