blob: e1ad55d48a09174569c84e6696d2805827249f7d [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
Michael W. Hudson61147f62004-08-03 11:33:28 +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
17-f: fromfile -- read names of tests to run from a file (see below)
18-l: findleaks -- if GC is available detect tests that leak memory
19-u: use -- specify which special resource intensive tests to run
20-h: help -- print this text and exit
21-t: threshold -- call gc.set_threshold(N)
22-T: coverage -- turn on code coverage using the trace module
23-L: runleaks -- run the leaks(1) command just before exit
24-R: huntrleaks -- search for reference leaks (needs debug build, v. slow)
Guido van Rossum152494a1996-12-20 03:12:20 +000025
26If non-option arguments are present, they are names for tests to run,
27unless -x is given, in which case they are names for tests not to run.
28If no test names are given, all tests are run.
Guido van Rossumf58ed251997-03-07 21:04:33 +000029
Guido van Rossuma4122201997-08-18 20:08:24 +000030-v is incompatible with -g and does not compare test output files.
Barry Warsawe11e3de1999-01-28 19:51:51 +000031
Barry Warsaw3b6d0252004-02-07 22:43:03 +000032-T turns on code coverage tracing with the trace module.
33
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000034-s means to run only a single test and exit. This is useful when
35doing memory analysis on the Python interpreter (which tend to consume
36too many resources to run the full regression test non-stop). The
37file /tmp/pynexttest is read to find the next test to run. If this
38file is missing, the first test_*.py file in testdir or on the command
39line is used. (actually tempfile.gettempdir() is used instead of
40/tmp).
Barry Warsawe11e3de1999-01-28 19:51:51 +000041
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000042-f reads the names of tests from the file given as f's argument, one
43or more test names per line. Whitespace is ignored. Blank lines and
44lines beginning with '#' are ignored. This is especially useful for
45whittling down failures involving interactions among tests.
Tim Petersc5000df2002-06-02 21:42:01 +000046
Skip Montanaro0179a182004-06-06 15:53:18 +000047-L causes the leaks(1) command to be run just before exit if it exists.
48leaks(1) is available on Mac OS X and presumably on some other
49FreeBSD-derived systems.
50
Michael W. Hudson61147f62004-08-03 11:33:28 +000051-R runs each test several times and examines sys.gettotalrefcount() to
52see if the test appears to be leaking references. The argument should
53be of the form stab:run:fname where 'stab' is the number of times the
54test is run to let gettotalrefcount settle down, 'run' is the number
55of times further it is run and 'fname' is the name of the file the
56reports are written to. These parameters all have defaults (5, 4 and
57"reflog.txt" respectively), so the minimal invocation is '-R ::'.
58
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000059-u is used to specify which special resource intensive tests to run,
60such as those requiring large file support or network connectivity.
61The argument is a comma-separated list of words indicating the
62resources to test. Currently only the following are defined:
Barry Warsaw08fca522001-08-20 22:33:46 +000063
Fred Drake3a15dac2002-04-11 16:39:16 +000064 all - Enable all special resources.
65
Guido van Rossum315aa362003-03-11 14:46:48 +000066 audio - Tests that use the audio device. (There are known
67 cases of broken audio drivers that can crash Python or
68 even the Linux kernel.)
69
Andrew M. Kuchling2158df02001-10-22 15:26:09 +000070 curses - Tests that use curses and will modify the terminal's
71 state and output modes.
Tim Peters1633a2e2001-10-30 05:56:40 +000072
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000073 largefile - It is okay to run some test that may create huge
74 files. These tests can take a long time and may
75 consume >2GB of disk space temporarily.
Barry Warsaw08fca522001-08-20 22:33:46 +000076
Guido van Rossum9e9d4f82002-06-07 15:17:03 +000077 network - It is okay to run tests that use external network
78 resource, e.g. testing SSL support for sockets.
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000079
80 bsddb - It is okay to run the bsddb testsuite, which takes
81 a long time to complete.
Fred Drake4dd0f7e2002-11-26 21:44:56 +000082
Raymond Hettinger7c85fa42004-07-01 11:01:35 +000083 decimal - Test the decimal module against a large suite that
84 verifies compliance with standards.
85
Fred Drake4dd0f7e2002-11-26 21:44:56 +000086To enable all resources except one, use '-uall,-<resource>'. For
87example, to run all the tests except for the bsddb tests, give the
88option '-uall,-bsddb'.
Guido van Rossum152494a1996-12-20 03:12:20 +000089"""
90
Guido van Rossum152494a1996-12-20 03:12:20 +000091import os
Barry Warsaw3b6d0252004-02-07 22:43:03 +000092import sys
Guido van Rossum152494a1996-12-20 03:12:20 +000093import getopt
Skip Montanaroab1c7912000-06-30 16:39:27 +000094import random
Guido van Rossumdc15c272002-08-12 21:55:51 +000095import warnings
Michael W. Hudson61147f62004-08-03 11:33:28 +000096import sre
Barry Warsaw3b6d0252004-02-07 22:43:03 +000097import cStringIO
98import traceback
Guido van Rossumdc15c272002-08-12 21:55:51 +000099
100# I see no other way to suppress these warnings;
101# putting them in test_grammar.py has no effect:
Guido van Rossum88b1def2002-08-14 17:54:48 +0000102warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
Guido van Rossumdc15c272002-08-12 21:55:51 +0000103 ".*test.test_grammar$")
Guido van Rossumc34c4fc2002-09-19 00:42:16 +0000104if sys.maxint > 0x7fffffff:
105 # Also suppress them in <string>, because for 64-bit platforms,
106 # that's where test_grammar.py hides them.
107 warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
108 "<string>")
Guido van Rossum152494a1996-12-20 03:12:20 +0000109
Guido van Rossumbb484652002-12-02 09:56:21 +0000110# MacOSX (a.k.a. Darwin) has a default stack size that is too small
111# for deeply recursive regular expressions. We see this as crashes in
112# the Python test suite when running test_re.py and test_sre.py. The
113# fix is to set the stack limit to 2048.
114# This approach may also be useful for other Unixy platforms that
115# suffer from small default stack limits.
116if sys.platform == 'darwin':
117 try:
118 import resource
119 except ImportError:
120 pass
121 else:
122 soft, hard = resource.getrlimit(resource.RLIMIT_STACK)
123 newsoft = min(hard, max(soft, 1024*2048))
124 resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard))
125
Barry Warsaw04f357c2002-07-23 19:04:11 +0000126from test import test_support
Fred Drake3a15dac2002-04-11 16:39:16 +0000127
Raymond Hettinger7c85fa42004-07-01 11:01:35 +0000128RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', 'bsddb',
129 'decimal')
Fred Drake3a15dac2002-04-11 16:39:16 +0000130
131
Barry Warsaw08fca522001-08-20 22:33:46 +0000132def usage(code, msg=''):
133 print __doc__
134 if msg: print msg
135 sys.exit(code)
136
137
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000138def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
139 exclude=False, single=False, randomize=False, fromfile=None,
Michael W. Hudson61147f62004-08-03 11:33:28 +0000140 findleaks=False, use_resources=None, trace=False, runleaks=False,
141 huntrleaks=False):
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000142 """Execute a test suite.
143
Thomas Wouters7e474022000-07-16 12:04:32 +0000144 This also parses command-line options and modifies its behavior
Fred Drake004d5e62000-10-23 17:22:08 +0000145 accordingly.
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000146
147 tests -- a list of strings containing test names (optional)
148 testdir -- the directory in which to look for tests (optional)
149
150 Users other than the Python test suite will certainly want to
151 specify testdir; if it's omitted, the directory containing the
Fred Drake004d5e62000-10-23 17:22:08 +0000152 Python test suite is searched for.
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000153
154 If the tests argument is omitted, the tests listed on the
155 command-line will be used. If that's empty, too, then all *.py
156 files beginning with test_ will be used.
Skip Montanaroab1c7912000-06-30 16:39:27 +0000157
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000158 The other default arguments (verbose, quiet, generate, exclude, single,
159 randomize, findleaks, use_resources, and trace) allow programmers calling
160 main() directly to set the values that would normally be set by flags on
161 the command line.
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000162 """
Fred Drake004d5e62000-10-23 17:22:08 +0000163
Tim Peters8dee8092001-09-25 20:05:11 +0000164 test_support.record_original_stdout(sys.stdout)
Guido van Rossum152494a1996-12-20 03:12:20 +0000165 try:
Michael W. Hudson61147f62004-08-03 11:33:28 +0000166 opts, args = getopt.getopt(sys.argv[1:], 'hvgqxsrf:lu:t:TLR:',
Barry Warsaw08fca522001-08-20 22:33:46 +0000167 ['help', 'verbose', 'quiet', 'generate',
Tim Petersc5000df2002-06-02 21:42:01 +0000168 'exclude', 'single', 'random', 'fromfile',
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000169 'findleaks', 'use=', 'threshold=', 'trace',
Michael W. Hudson61147f62004-08-03 11:33:28 +0000170 'runleaks', 'huntrleaks='
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000171 ])
Guido van Rossum152494a1996-12-20 03:12:20 +0000172 except getopt.error, msg:
Barry Warsaw08fca522001-08-20 22:33:46 +0000173 usage(2, msg)
174
175 # Defaults
176 if use_resources is None:
177 use_resources = []
Guido van Rossum152494a1996-12-20 03:12:20 +0000178 for o, a in opts:
Barry Warsaw08fca522001-08-20 22:33:46 +0000179 if o in ('-h', '--help'):
180 usage(0)
181 elif o in ('-v', '--verbose'):
182 verbose += 1
183 elif o in ('-q', '--quiet'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000184 quiet = True;
Barry Warsaw08fca522001-08-20 22:33:46 +0000185 verbose = 0
186 elif o in ('-g', '--generate'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000187 generate = True
Barry Warsaw08fca522001-08-20 22:33:46 +0000188 elif o in ('-x', '--exclude'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000189 exclude = True
Barry Warsaw08fca522001-08-20 22:33:46 +0000190 elif o in ('-s', '--single'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000191 single = True
Barry Warsaw08fca522001-08-20 22:33:46 +0000192 elif o in ('-r', '--randomize'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000193 randomize = True
Tim Petersc5000df2002-06-02 21:42:01 +0000194 elif o in ('-f', '--fromfile'):
195 fromfile = a
Barry Warsaw08fca522001-08-20 22:33:46 +0000196 elif o in ('-l', '--findleaks'):
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000197 findleaks = True
Skip Montanaro0179a182004-06-06 15:53:18 +0000198 elif o in ('-L', '--runleaks'):
199 runleaks = True
Guido van Rossum9e9d4f82002-06-07 15:17:03 +0000200 elif o in ('-t', '--threshold'):
201 import gc
202 gc.set_threshold(int(a))
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000203 elif o in ('-T', '--coverage'):
204 trace = True
Michael W. Hudson61147f62004-08-03 11:33:28 +0000205 elif o in ('-R', '--huntrleaks'):
206 huntrleaks = a.split(':')
207 if len(huntrleaks) != 3:
208 print a, huntrleaks
209 usage(2, '-R takes three colon-separated arguments')
210 if len(huntrleaks[0]) == 0:
211 huntrleaks[0] = 5
212 else:
213 huntrleaks[0] = int(huntrleaks[0])
214 if len(huntrleaks[1]) == 0:
215 huntrleaks[1] = 4
216 else:
217 huntrleaks[1] = int(huntrleaks[1])
218 if len(huntrleaks[2]) == 0:
219 huntrleaks[2] = "reflog.txt"
Barry Warsaw08fca522001-08-20 22:33:46 +0000220 elif o in ('-u', '--use'):
Guido van Rossumfe3f6962001-09-06 16:09:41 +0000221 u = [x.lower() for x in a.split(',')]
222 for r in u:
Fred Drake3a15dac2002-04-11 16:39:16 +0000223 if r == 'all':
Fred Drake4dd0f7e2002-11-26 21:44:56 +0000224 use_resources[:] = RESOURCE_NAMES
225 continue
226 remove = False
227 if r[0] == '-':
228 remove = True
229 r = r[1:]
Fred Drake3a15dac2002-04-11 16:39:16 +0000230 if r not in RESOURCE_NAMES:
231 usage(1, 'Invalid -u/--use option: ' + a)
Fred Drake4dd0f7e2002-11-26 21:44:56 +0000232 if remove:
233 if r in use_resources:
234 use_resources.remove(r)
235 elif r not in use_resources:
Andrew MacIntyree41abab2002-04-30 12:11:04 +0000236 use_resources.append(r)
Guido van Rossuma4122201997-08-18 20:08:24 +0000237 if generate and verbose:
Barry Warsaw08fca522001-08-20 22:33:46 +0000238 usage(2, "-g and -v don't go together!")
Tim Petersc5000df2002-06-02 21:42:01 +0000239 if single and fromfile:
240 usage(2, "-s and -f don't go together!")
Barry Warsaw08fca522001-08-20 22:33:46 +0000241
Guido van Rossum152494a1996-12-20 03:12:20 +0000242 good = []
243 bad = []
244 skipped = []
Fred Drake9a0db072003-02-03 15:19:30 +0000245 resource_denieds = []
Barry Warsawe11e3de1999-01-28 19:51:51 +0000246
Neil Schemenauerd569f232000-09-22 15:29:28 +0000247 if findleaks:
Barry Warsawa873b032000-08-03 15:50:37 +0000248 try:
249 import gc
250 except ImportError:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000251 print 'No GC available, disabling findleaks.'
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000252 findleaks = False
Barry Warsawa873b032000-08-03 15:50:37 +0000253 else:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000254 # Uncomment the line below to report garbage that is not
255 # freeable by reference counting alone. By default only
256 # garbage that is not collectable by the GC is reported.
257 #gc.set_debug(gc.DEBUG_SAVEALL)
Neil Schemenauerd569f232000-09-22 15:29:28 +0000258 found_garbage = []
Barry Warsawa873b032000-08-03 15:50:37 +0000259
Barry Warsawe11e3de1999-01-28 19:51:51 +0000260 if single:
261 from tempfile import gettempdir
262 filename = os.path.join(gettempdir(), 'pynexttest')
263 try:
264 fp = open(filename, 'r')
Eric S. Raymondfc170b12001-02-09 11:51:27 +0000265 next = fp.read().strip()
Barry Warsawe11e3de1999-01-28 19:51:51 +0000266 tests = [next]
267 fp.close()
268 except IOError:
269 pass
Tim Petersc5000df2002-06-02 21:42:01 +0000270
271 if fromfile:
272 tests = []
273 fp = open(fromfile)
274 for line in fp:
275 guts = line.split() # assuming no test has whitespace in its name
276 if guts and not guts[0].startswith('#'):
277 tests.extend(guts)
278 fp.close()
279
280 # Strip .py extensions.
281 if args:
282 args = map(removepy, args)
283 if tests:
284 tests = map(removepy, tests)
285
Guido van Rossum6c74fea1998-08-25 12:29:08 +0000286 stdtests = STDTESTS[:]
287 nottests = NOTTESTS[:]
Guido van Rossum152494a1996-12-20 03:12:20 +0000288 if exclude:
Guido van Rossum6c74fea1998-08-25 12:29:08 +0000289 for arg in args:
290 if arg in stdtests:
291 stdtests.remove(arg)
292 nottests[:0] = args
Guido van Rossum41360a41998-03-26 19:42:58 +0000293 args = []
Guido van Rossum747e1ca1998-08-24 13:48:36 +0000294 tests = tests or args or findtests(testdir, stdtests, nottests)
Barry Warsawe11e3de1999-01-28 19:51:51 +0000295 if single:
296 tests = tests[:1]
Skip Montanaroab1c7912000-06-30 16:39:27 +0000297 if randomize:
298 random.shuffle(tests)
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000299 if trace:
300 import trace
301 tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix],
302 trace=False, count=True)
303 coverdir = os.path.join(os.getcwd(), 'coverage')
Guido van Rossum41360a41998-03-26 19:42:58 +0000304 test_support.verbose = verbose # Tell tests to be moderately quiet
Barry Warsaw08fca522001-08-20 22:33:46 +0000305 test_support.use_resources = use_resources
Guido van Rossum5796d262000-04-21 21:35:06 +0000306 save_modules = sys.modules.keys()
Guido van Rossum152494a1996-12-20 03:12:20 +0000307 for test in tests:
Guido van Rossum41360a41998-03-26 19:42:58 +0000308 if not quiet:
309 print test
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000310 sys.stdout.flush()
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000311 if trace:
312 # If we're tracing code coverage, then we don't exit with status
313 # if on a false return value from main.
314 tracer.runctx('runtest(test, generate, verbose, quiet, testdir)',
315 globals=globals(), locals=vars())
Guido van Rossum41360a41998-03-26 19:42:58 +0000316 else:
Michael W. Hudson61147f62004-08-03 11:33:28 +0000317 ok = runtest(test, generate, verbose, quiet, testdir, huntrleaks)
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000318 if ok > 0:
319 good.append(test)
320 elif ok == 0:
321 bad.append(test)
322 else:
323 skipped.append(test)
324 if ok == -2:
325 resource_denieds.append(test)
Neil Schemenauerd569f232000-09-22 15:29:28 +0000326 if findleaks:
327 gc.collect()
328 if gc.garbage:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000329 print "Warning: test created", len(gc.garbage),
330 print "uncollectable object(s)."
331 # move the uncollectable objects somewhere so we don't see
332 # them again
Neil Schemenauerd569f232000-09-22 15:29:28 +0000333 found_garbage.extend(gc.garbage)
334 del gc.garbage[:]
Guido van Rossum5796d262000-04-21 21:35:06 +0000335 # Unload the newly imported modules (best effort finalization)
336 for module in sys.modules.keys():
Guido van Rossum51931142000-05-05 14:27:39 +0000337 if module not in save_modules and module.startswith("test."):
Guido van Rossum5796d262000-04-21 21:35:06 +0000338 test_support.unload(module)
Jeremy Hylton7a1ea0e2001-10-17 13:45:28 +0000339
340 # The lists won't be sorted if running with -r
341 good.sort()
342 bad.sort()
343 skipped.sort()
Tim Peterse0c446b2001-10-18 21:57:37 +0000344
Guido van Rossum152494a1996-12-20 03:12:20 +0000345 if good and not quiet:
Guido van Rossum41360a41998-03-26 19:42:58 +0000346 if not bad and not skipped and len(good) > 1:
347 print "All",
348 print count(len(good), "test"), "OK."
Tim Peters1a4d77b2000-12-30 22:21:22 +0000349 if verbose:
Barry Warsaw408b6d32002-07-30 23:27:12 +0000350 print "CAUTION: stdout isn't compared in verbose mode:"
351 print "a test that passes in verbose mode may fail without it."
Guido van Rossum152494a1996-12-20 03:12:20 +0000352 if bad:
Tim Petersa45da922001-08-12 03:45:50 +0000353 print count(len(bad), "test"), "failed:"
354 printlist(bad)
Guido van Rossum152494a1996-12-20 03:12:20 +0000355 if skipped and not quiet:
Tim Petersa45da922001-08-12 03:45:50 +0000356 print count(len(skipped), "test"), "skipped:"
357 printlist(skipped)
Barry Warsawe11e3de1999-01-28 19:51:51 +0000358
Tim Petersb5b7b782001-08-12 01:20:39 +0000359 e = _ExpectedSkips()
Tim Petersa2be2d62001-08-12 02:01:09 +0000360 plat = sys.platform
Tim Petersb5b7b782001-08-12 01:20:39 +0000361 if e.isvalid():
Raymond Hettingera690a992003-11-16 16:17:49 +0000362 surprise = set(skipped) - e.getexpected() - set(resource_denieds)
Tim Petersb5b7b782001-08-12 01:20:39 +0000363 if surprise:
364 print count(len(surprise), "skip"), \
Tim Petersa45da922001-08-12 03:45:50 +0000365 "unexpected on", plat + ":"
366 printlist(surprise)
Tim Petersb5b7b782001-08-12 01:20:39 +0000367 else:
368 print "Those skips are all expected on", plat + "."
369 else:
370 print "Ask someone to teach regrtest.py about which tests are"
371 print "expected to get skipped on", plat + "."
372
Barry Warsawe11e3de1999-01-28 19:51:51 +0000373 if single:
374 alltests = findtests(testdir, stdtests, nottests)
375 for i in range(len(alltests)):
376 if tests[0] == alltests[i]:
377 if i == len(alltests) - 1:
378 os.unlink(filename)
379 else:
380 fp = open(filename, 'w')
381 fp.write(alltests[i+1] + '\n')
382 fp.close()
383 break
384 else:
385 os.unlink(filename)
386
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000387 if trace:
388 r = tracer.results()
389 r.write_results(show_missing=True, summary=True, coverdir=coverdir)
390
Skip Montanaro0179a182004-06-06 15:53:18 +0000391 if runleaks:
392 os.system("leaks %d" % os.getpid())
393
Tim Peters5943b4a2003-07-23 00:30:39 +0000394 sys.exit(len(bad) > 0)
Barry Warsaw08fca522001-08-20 22:33:46 +0000395
Guido van Rossum152494a1996-12-20 03:12:20 +0000396
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000397STDTESTS = [
Guido van Rossum152494a1996-12-20 03:12:20 +0000398 'test_grammar',
399 'test_opcodes',
400 'test_operations',
401 'test_builtin',
402 'test_exceptions',
403 'test_types',
404 ]
405
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000406NOTTESTS = [
Guido van Rossum152494a1996-12-20 03:12:20 +0000407 'test_support',
Jeremy Hylton62e2c7e2001-02-28 17:48:06 +0000408 'test_future1',
409 'test_future2',
Jeremy Hylton8471a352001-08-20 20:33:42 +0000410 'test_future3',
Guido van Rossum152494a1996-12-20 03:12:20 +0000411 ]
412
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000413def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
Guido van Rossum152494a1996-12-20 03:12:20 +0000414 """Return a list of all applicable test modules."""
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000415 if not testdir: testdir = findtestdir()
Guido van Rossum152494a1996-12-20 03:12:20 +0000416 names = os.listdir(testdir)
417 tests = []
418 for name in names:
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000419 if name[:5] == "test_" and name[-3:] == os.extsep+"py":
Guido van Rossum41360a41998-03-26 19:42:58 +0000420 modname = name[:-3]
421 if modname not in stdtests and modname not in nottests:
422 tests.append(modname)
Guido van Rossum152494a1996-12-20 03:12:20 +0000423 tests.sort()
424 return stdtests + tests
425
Michael W. Hudson61147f62004-08-03 11:33:28 +0000426def runtest(test, generate, verbose, quiet, testdir=None, huntrleaks=False):
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000427 """Run a single test.
428 test -- the name of the test
429 generate -- if true, generate output, instead of running the test
430 and comparing it to a previously created output file
431 verbose -- if true, print more messages
Trent Mickf29f47b2000-08-11 19:02:59 +0000432 quiet -- if true, don't print 'skipped' messages (probably redundant)
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000433 testdir -- test directory
434 """
Guido van Rossum152494a1996-12-20 03:12:20 +0000435 test_support.unload(test)
Barry Warsaw3b6d0252004-02-07 22:43:03 +0000436 if not testdir:
437 testdir = findtestdir()
Guido van Rossum152494a1996-12-20 03:12:20 +0000438 outputdir = os.path.join(testdir, "output")
439 outputfile = os.path.join(outputdir, test)
Tim Peters9390cc12001-09-28 20:14:46 +0000440 if verbose:
Guido van Rossum41360a41998-03-26 19:42:58 +0000441 cfp = None
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000442 else:
Raymond Hettinger74e67662003-05-17 20:44:12 +0000443 cfp = cStringIO.StringIO()
Michael W. Hudson61147f62004-08-03 11:33:28 +0000444 if huntrleaks:
445 refrep = open(huntrleaks[2], "a")
Guido van Rossum152494a1996-12-20 03:12:20 +0000446 try:
Tim Peters342ca752001-09-25 19:13:20 +0000447 save_stdout = sys.stdout
Guido van Rossum41360a41998-03-26 19:42:58 +0000448 try:
449 if cfp:
450 sys.stdout = cfp
451 print test # Output file starts with test name
Barry Warsaw408b6d32002-07-30 23:27:12 +0000452 if test.startswith('test.'):
453 abstest = test
454 else:
455 # Always import it from the test package
456 abstest = 'test.' + test
457 the_package = __import__(abstest, globals(), locals(), [])
458 the_module = getattr(the_package, test)
Tim Petersd9742212001-05-22 18:28:25 +0000459 # Most tests run to completion simply as a side-effect of
460 # being imported. For the benefit of tests that can't run
461 # that way (like test_threaded_import), explicitly invoke
462 # their test_main() function (if it exists).
463 indirect_test = getattr(the_module, "test_main", None)
464 if indirect_test is not None:
465 indirect_test()
Michael W. Hudson61147f62004-08-03 11:33:28 +0000466 if huntrleaks:
467 # This code *is* hackish and inelegant, yes.
468 # But it seems to do the job.
469 import copy_reg
470 fs = warnings.filters[:]
471 ps = copy_reg.dispatch_table.copy()
472 pic = sys.path_importer_cache.copy()
473 import gc
474 def cleanup():
475 import _strptime, urlparse, warnings, dircache
476 from distutils.dir_util import _path_created
477 _path_created.clear()
478 warnings.filters[:] = fs
479 gc.collect()
480 sre.purge()
481 _strptime._regex_cache.clear()
482 urlparse.clear_cache()
483 copy_reg.dispatch_table.clear()
484 copy_reg.dispatch_table.update(ps)
485 sys.path_importer_cache.clear()
486 sys.path_importer_cache.update(pic)
487 dircache.reset()
488 if indirect_test:
489 def run_the_test():
490 indirect_test()
491 else:
492 def run_the_test():
493 reload(the_module)
494 deltas = []
495 repcount = huntrleaks[0] + huntrleaks[1]
496 print >> sys.stderr, "beginning", repcount, "repetitions"
497 print >> sys.stderr, \
498 ("1234567890"*(repcount//10 + 1))[:repcount]
499 for i in range(repcount):
500 rc = sys.gettotalrefcount()
501 run_the_test()
502 sys.stderr.write('.')
503 cleanup()
504 deltas.append(sys.gettotalrefcount() - rc - 2)
505 print >>sys.stderr
506 if max(map(abs, deltas[-huntrleaks[1]:])) > 0:
507 print >>refrep, test, 'leaked', \
508 deltas[-huntrleaks[1]:], 'references'
509 # The end of the huntrleaks hackishness.
Guido van Rossum41360a41998-03-26 19:42:58 +0000510 finally:
Tim Peters342ca752001-09-25 19:13:20 +0000511 sys.stdout = save_stdout
Fred Drake9a0db072003-02-03 15:19:30 +0000512 except test_support.ResourceDenied, msg:
513 if not quiet:
514 print test, "skipped --", msg
515 sys.stdout.flush()
516 return -2
Thomas Wouters3af826e2000-08-04 13:17:51 +0000517 except (ImportError, test_support.TestSkipped), msg:
Trent Mickf29f47b2000-08-11 19:02:59 +0000518 if not quiet:
Fred Drakede4742b2002-10-17 20:36:08 +0000519 print test, "skipped --", msg
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000520 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000521 return -1
Fred Drakefe5c22a2000-08-18 16:04:05 +0000522 except KeyboardInterrupt:
523 raise
Guido van Rossum152494a1996-12-20 03:12:20 +0000524 except test_support.TestFailed, msg:
Guido van Rossum41360a41998-03-26 19:42:58 +0000525 print "test", test, "failed --", msg
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000526 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000527 return 0
Guido van Rossum9e48b271997-07-16 01:56:13 +0000528 except:
Guido van Rossum41360a41998-03-26 19:42:58 +0000529 type, value = sys.exc_info()[:2]
Fred Drake27c4b392000-08-23 20:34:40 +0000530 print "test", test, "crashed --", str(type) + ":", value
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000531 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000532 if verbose:
533 traceback.print_exc(file=sys.stdout)
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000534 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000535 return 0
Guido van Rossum152494a1996-12-20 03:12:20 +0000536 else:
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000537 if not cfp:
538 return 1
539 output = cfp.getvalue()
Fred Drakee51fe8d2001-05-29 17:10:51 +0000540 if generate:
Fred Drakee51fe8d2001-05-29 17:10:51 +0000541 if output == test + "\n":
542 if os.path.exists(outputfile):
543 # Write it since it already exists (and the contents
544 # may have changed), but let the user know it isn't
545 # needed:
Fred Drakee51fe8d2001-05-29 17:10:51 +0000546 print "output file", outputfile, \
547 "is no longer needed; consider removing it"
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000548 else:
549 # We don't need it, so don't create it.
550 return 1
551 fp = open(outputfile, "w")
552 fp.write(output)
553 fp.close()
554 return 1
555 if os.path.exists(outputfile):
556 fp = open(outputfile, "r")
557 expected = fp.read()
558 fp.close()
559 else:
560 expected = test + "\n"
Michael W. Hudson61147f62004-08-03 11:33:28 +0000561 if output == expected or huntrleaks:
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000562 return 1
563 print "test", test, "produced unexpected output:"
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000564 sys.stdout.flush()
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000565 reportdiff(expected, output)
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000566 sys.stdout.flush()
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000567 return 0
568
569def reportdiff(expected, output):
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000570 import difflib
Tim Petersc377b162001-09-22 05:31:03 +0000571 print "*" * 70
572 a = expected.splitlines(1)
573 b = output.splitlines(1)
Guido van Rossumcf691932001-09-21 21:06:22 +0000574 sm = difflib.SequenceMatcher(a=a, b=b)
575 tuples = sm.get_opcodes()
Tim Petersc377b162001-09-22 05:31:03 +0000576
Guido van Rossumcf691932001-09-21 21:06:22 +0000577 def pair(x0, x1):
Tim Petersc377b162001-09-22 05:31:03 +0000578 # x0:x1 are 0-based slice indices; convert to 1-based line indices.
Guido van Rossumcf691932001-09-21 21:06:22 +0000579 x0 += 1
580 if x0 >= x1:
Tim Petersc377b162001-09-22 05:31:03 +0000581 return "line " + str(x0)
Guido van Rossumcf691932001-09-21 21:06:22 +0000582 else:
Tim Petersc377b162001-09-22 05:31:03 +0000583 return "lines %d-%d" % (x0, x1)
584
Guido van Rossumcf691932001-09-21 21:06:22 +0000585 for op, a0, a1, b0, b1 in tuples:
586 if op == 'equal':
587 pass
Tim Petersc377b162001-09-22 05:31:03 +0000588
Guido van Rossumcf691932001-09-21 21:06:22 +0000589 elif op == 'delete':
Tim Petersc377b162001-09-22 05:31:03 +0000590 print "***", pair(a0, a1), "of expected output missing:"
Guido van Rossumcf691932001-09-21 21:06:22 +0000591 for line in a[a0:a1]:
Tim Petersc377b162001-09-22 05:31:03 +0000592 print "-", line,
593
Guido van Rossumcf691932001-09-21 21:06:22 +0000594 elif op == 'replace':
Tim Petersc377b162001-09-22 05:31:03 +0000595 print "*** mismatch between", pair(a0, a1), "of expected", \
596 "output and", pair(b0, b1), "of actual output:"
597 for line in difflib.ndiff(a[a0:a1], b[b0:b1]):
598 print line,
599
Guido van Rossumcf691932001-09-21 21:06:22 +0000600 elif op == 'insert':
Tim Petersc377b162001-09-22 05:31:03 +0000601 print "***", pair(b0, b1), "of actual output doesn't appear", \
602 "in expected output after line", str(a1)+":"
Guido van Rossumcf691932001-09-21 21:06:22 +0000603 for line in b[b0:b1]:
Tim Petersc377b162001-09-22 05:31:03 +0000604 print "+", line,
605
Guido van Rossumcf691932001-09-21 21:06:22 +0000606 else:
607 print "get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1)
Tim Petersc377b162001-09-22 05:31:03 +0000608
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000609 print "*" * 70
Guido van Rossum152494a1996-12-20 03:12:20 +0000610
611def findtestdir():
612 if __name__ == '__main__':
Guido van Rossum41360a41998-03-26 19:42:58 +0000613 file = sys.argv[0]
Guido van Rossum152494a1996-12-20 03:12:20 +0000614 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000615 file = __file__
Guido van Rossum152494a1996-12-20 03:12:20 +0000616 testdir = os.path.dirname(file) or os.curdir
617 return testdir
618
Tim Petersc5000df2002-06-02 21:42:01 +0000619def removepy(name):
620 if name.endswith(os.extsep + "py"):
621 name = name[:-3]
622 return name
623
Guido van Rossum152494a1996-12-20 03:12:20 +0000624def count(n, word):
625 if n == 1:
Guido van Rossum41360a41998-03-26 19:42:58 +0000626 return "%d %s" % (n, word)
Guido van Rossum152494a1996-12-20 03:12:20 +0000627 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000628 return "%d %ss" % (n, word)
Guido van Rossum152494a1996-12-20 03:12:20 +0000629
Tim Petersa45da922001-08-12 03:45:50 +0000630def printlist(x, width=70, indent=4):
Tim Peters7c7efe92002-08-23 17:55:54 +0000631 """Print the elements of iterable x to stdout.
Tim Petersa45da922001-08-12 03:45:50 +0000632
633 Optional arg width (default 70) is the maximum line length.
634 Optional arg indent (default 4) is the number of blanks with which to
635 begin each line.
636 """
637
Tim Petersba78bc42002-07-04 19:45:06 +0000638 from textwrap import fill
639 blanks = ' ' * indent
640 print fill(' '.join(map(str, x)), width,
641 initial_indent=blanks, subsequent_indent=blanks)
Tim Petersa45da922001-08-12 03:45:50 +0000642
Tim Petersde14a302002-04-01 05:04:46 +0000643# Map sys.platform to a string containing the basenames of tests
644# expected to be skipped on that platform.
Tim Peters2a182db2002-10-09 01:07:11 +0000645#
646# Special cases:
647# test_pep277
648# The _ExpectedSkips constructor adds this to the set of expected
649# skips if not os.path.supports_unicode_filenames.
Tim Peters1b445d32002-11-24 18:53:11 +0000650# test_normalization
651# Whether a skip is expected here depends on whether a large test
652# input file has been downloaded. test_normalization.skip_expected
Tim Peters1babdfc2002-11-24 19:19:09 +0000653# controls that.
Tim Petersb4ee4eb2002-12-04 03:26:57 +0000654# test_socket_ssl
655# Controlled by test_socket_ssl.skip_expected. Requires the network
656# resource, and a socket module with ssl support.
Neal Norwitz55b61d22003-02-28 19:57:03 +0000657# test_timeout
658# Controlled by test_timeout.skip_expected. Requires the network
659# resource and a socket module.
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +0000660# test_codecmaps_*
661# Whether a skip is expected here depends on whether a large test
662# input file has been downloaded. test_codecmaps_*.skip_expected
663# controls that.
Tim Petersde14a302002-04-01 05:04:46 +0000664
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000665_expectations = {
666 'win32':
667 """
Tim Petersc7c516a2003-09-20 22:06:13 +0000668 test__locale
Raymond Hettinger901dc982003-11-20 19:02:02 +0000669 test_applesingle
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000670 test_al
Skip Montanaro823ba282003-05-06 20:36:24 +0000671 test_bsddb185
Tim Peters78e35f92002-11-22 20:00:34 +0000672 test_bsddb3
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000673 test_cd
674 test_cl
675 test_commands
676 test_crypt
Tim Petersd7030572001-10-22 22:06:08 +0000677 test_curses
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000678 test_dbm
679 test_dl
680 test_fcntl
681 test_fork1
682 test_gdbm
683 test_gl
684 test_grp
685 test_imgfile
Tim Petersfd8e6e52003-03-04 00:26:38 +0000686 test_ioctl
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000687 test_largefile
688 test_linuxaudiodev
689 test_mhlib
Tim Petersde14a302002-04-01 05:04:46 +0000690 test_mpz
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000691 test_nis
692 test_openpty
Tim Petersefc4b122002-12-10 18:47:56 +0000693 test_ossaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000694 test_poll
Tim Peters003eb302003-02-17 21:48:48 +0000695 test_posix
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000696 test_pty
697 test_pwd
Tim Peters1e33ffa2002-04-23 23:09:02 +0000698 test_resource
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000699 test_signal
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000700 test_sunaudiodev
Tim Peterscea2cc42004-08-04 02:32:03 +0000701 test_threadsignals
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000702 test_timing
703 """,
704 'linux2':
705 """
706 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000707 test_applesingle
Skip Montanaro823ba282003-05-06 20:36:24 +0000708 test_bsddb185
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000709 test_cd
710 test_cl
Guido van Rossumf66dacd2001-10-23 15:10:55 +0000711 test_curses
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000712 test_dl
713 test_gl
714 test_imgfile
715 test_largefile
Guido van Rossum4507ec72003-02-14 19:29:22 +0000716 test_linuxaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000717 test_nis
718 test_ntpath
Guido van Rossum4507ec72003-02-14 19:29:22 +0000719 test_ossaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000720 test_sunaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000721 """,
Jack Jansen49a806e2001-08-28 14:49:00 +0000722 'mac':
Guido van Rossumaa782362001-09-02 03:58:41 +0000723 """
724 test_al
Jack Jansen67975142003-01-08 16:31:11 +0000725 test_atexit
Guido van Rossumaa782362001-09-02 03:58:41 +0000726 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000727 test_bsddb185
Jack Jansen67975142003-01-08 16:31:11 +0000728 test_bsddb3
729 test_bz2
Guido van Rossumaa782362001-09-02 03:58:41 +0000730 test_cd
731 test_cl
732 test_commands
733 test_crypt
Jack Jansenb3be2162001-11-30 14:16:36 +0000734 test_curses
Guido van Rossumaa782362001-09-02 03:58:41 +0000735 test_dbm
736 test_dl
737 test_fcntl
738 test_fork1
739 test_gl
740 test_grp
Jack Jansenc4d6bdd2003-03-07 15:38:11 +0000741 test_ioctl
Guido van Rossumaa782362001-09-02 03:58:41 +0000742 test_imgfile
743 test_largefile
744 test_linuxaudiodev
745 test_locale
746 test_mmap
Jack Jansen67975142003-01-08 16:31:11 +0000747 test_mpz
Guido van Rossumaa782362001-09-02 03:58:41 +0000748 test_nis
749 test_ntpath
750 test_openpty
Jack Jansen67975142003-01-08 16:31:11 +0000751 test_ossaudiodev
Guido van Rossumaa782362001-09-02 03:58:41 +0000752 test_poll
Jack Jansen67975142003-01-08 16:31:11 +0000753 test_popen
Guido van Rossumaa782362001-09-02 03:58:41 +0000754 test_popen2
Jack Jansen5bb97e62003-02-21 22:33:55 +0000755 test_posix
Guido van Rossumaa782362001-09-02 03:58:41 +0000756 test_pty
757 test_pwd
Jack Jansen67975142003-01-08 16:31:11 +0000758 test_resource
Guido van Rossumaa782362001-09-02 03:58:41 +0000759 test_signal
Guido van Rossumaa782362001-09-02 03:58:41 +0000760 test_sunaudiodev
761 test_sundry
Jack Jansenc4d6bdd2003-03-07 15:38:11 +0000762 test_tarfile
Guido van Rossumaa782362001-09-02 03:58:41 +0000763 test_timing
Guido van Rossumaa782362001-09-02 03:58:41 +0000764 """,
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000765 'unixware7':
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000766 """
767 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000768 test_applesingle
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000769 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000770 test_bsddb185
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000771 test_cd
772 test_cl
773 test_dl
774 test_gl
775 test_imgfile
776 test_largefile
777 test_linuxaudiodev
778 test_minidom
779 test_nis
780 test_ntpath
781 test_openpty
782 test_pyexpat
783 test_sax
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000784 test_sunaudiodev
785 test_sundry
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000786 """,
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000787 'openunix8':
788 """
789 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000790 test_applesingle
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000791 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000792 test_bsddb185
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000793 test_cd
794 test_cl
795 test_dl
796 test_gl
797 test_imgfile
798 test_largefile
799 test_linuxaudiodev
800 test_minidom
801 test_nis
802 test_ntpath
803 test_openpty
804 test_pyexpat
805 test_sax
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000806 test_sunaudiodev
807 test_sundry
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000808 """,
809 'sco_sv3':
810 """
811 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000812 test_applesingle
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000813 test_asynchat
814 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000815 test_bsddb185
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000816 test_cd
817 test_cl
818 test_dl
819 test_fork1
820 test_gettext
821 test_gl
822 test_imgfile
823 test_largefile
824 test_linuxaudiodev
825 test_locale
826 test_minidom
827 test_nis
828 test_ntpath
829 test_openpty
830 test_pyexpat
831 test_queue
832 test_sax
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000833 test_sunaudiodev
834 test_sundry
835 test_thread
836 test_threaded_import
837 test_threadedtempfile
838 test_threading
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000839 """,
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000840 'riscos':
841 """
842 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000843 test_applesingle
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000844 test_asynchat
Martin v. Löwisa94568a2003-05-10 07:36:56 +0000845 test_atexit
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000846 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000847 test_bsddb185
Martin v. Löwisa94568a2003-05-10 07:36:56 +0000848 test_bsddb3
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000849 test_cd
850 test_cl
851 test_commands
852 test_crypt
853 test_dbm
854 test_dl
855 test_fcntl
856 test_fork1
857 test_gdbm
858 test_gl
859 test_grp
860 test_imgfile
861 test_largefile
862 test_linuxaudiodev
863 test_locale
864 test_mmap
865 test_nis
866 test_ntpath
867 test_openpty
868 test_poll
869 test_popen2
870 test_pty
871 test_pwd
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000872 test_strop
873 test_sunaudiodev
874 test_sundry
875 test_thread
876 test_threaded_import
877 test_threadedtempfile
878 test_threading
879 test_timing
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000880 """,
Jack Jansen8a97f4a2001-12-05 23:27:32 +0000881 'darwin':
Jack Jansen398c2362001-12-02 21:41:36 +0000882 """
Brett Cannon2bfb94c2003-10-13 04:27:47 +0000883 test__locale
Jack Jansen398c2362001-12-02 21:41:36 +0000884 test_al
Jack Jansenacda3392002-12-30 23:03:13 +0000885 test_bsddb
Guido van Rossum9d427002002-12-03 10:24:56 +0000886 test_bsddb3
Jack Jansen398c2362001-12-02 21:41:36 +0000887 test_cd
888 test_cl
889 test_curses
890 test_dl
891 test_gdbm
892 test_gl
893 test_imgfile
894 test_largefile
895 test_linuxaudiodev
Jack Jansenacda3392002-12-30 23:03:13 +0000896 test_locale
Jack Jansen398c2362001-12-02 21:41:36 +0000897 test_minidom
Guido van Rossum9d427002002-12-03 10:24:56 +0000898 test_mpz
Jack Jansen398c2362001-12-02 21:41:36 +0000899 test_nis
900 test_ntpath
Jack Jansenacda3392002-12-30 23:03:13 +0000901 test_ossaudiodev
Jack Jansen398c2362001-12-02 21:41:36 +0000902 test_poll
Jack Jansen398c2362001-12-02 21:41:36 +0000903 test_sunaudiodev
Jack Jansen398c2362001-12-02 21:41:36 +0000904 """,
Guido van Rossum11c3f092002-07-17 15:08:24 +0000905 'sunos5':
906 """
907 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000908 test_applesingle
Guido van Rossum11c3f092002-07-17 15:08:24 +0000909 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000910 test_bsddb185
Guido van Rossum11c3f092002-07-17 15:08:24 +0000911 test_cd
912 test_cl
913 test_curses
914 test_dbm
Guido van Rossum11c3f092002-07-17 15:08:24 +0000915 test_gdbm
916 test_gl
917 test_gzip
918 test_imgfile
919 test_linuxaudiodev
920 test_mpz
921 test_openpty
Guido van Rossum11c3f092002-07-17 15:08:24 +0000922 test_zipfile
923 test_zlib
Jeremy Hyltoned375e12002-07-17 15:56:55 +0000924 """,
Skip Montanarob3230212002-03-15 02:54:03 +0000925 'hp-ux11':
926 """
927 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000928 test_applesingle
Skip Montanarob3230212002-03-15 02:54:03 +0000929 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000930 test_bsddb185
Skip Montanarob3230212002-03-15 02:54:03 +0000931 test_cd
932 test_cl
933 test_curses
934 test_dl
935 test_gdbm
936 test_gl
937 test_gzip
938 test_imgfile
939 test_largefile
940 test_linuxaudiodev
941 test_locale
942 test_minidom
943 test_nis
944 test_ntpath
945 test_openpty
946 test_pyexpat
947 test_sax
Skip Montanarob3230212002-03-15 02:54:03 +0000948 test_sunaudiodev
Skip Montanarob3230212002-03-15 02:54:03 +0000949 test_zipfile
950 test_zlib
951 """,
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000952 'atheos':
Tim Petersc411dba2002-07-16 21:35:23 +0000953 """
954 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000955 test_applesingle
Skip Montanaro823ba282003-05-06 20:36:24 +0000956 test_bsddb185
Tim Petersc411dba2002-07-16 21:35:23 +0000957 test_cd
958 test_cl
959 test_curses
960 test_dl
Tim Petersc411dba2002-07-16 21:35:23 +0000961 test_gdbm
962 test_gl
963 test_imgfile
964 test_largefile
965 test_linuxaudiodev
966 test_locale
967 test_mhlib
968 test_mmap
969 test_mpz
970 test_nis
971 test_poll
972 test_popen2
973 test_resource
Tim Petersc411dba2002-07-16 21:35:23 +0000974 test_sunaudiodev
Tim Petersc411dba2002-07-16 21:35:23 +0000975 """,
Jason Tishler25115942002-12-05 15:18:15 +0000976 'cygwin':
977 """
978 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +0000979 test_applesingle
Skip Montanaro823ba282003-05-06 20:36:24 +0000980 test_bsddb185
Tim Petersb0f89e02002-12-05 17:20:25 +0000981 test_bsddb3
Jason Tishler25115942002-12-05 15:18:15 +0000982 test_cd
983 test_cl
984 test_curses
985 test_dbm
Jason Tishler25115942002-12-05 15:18:15 +0000986 test_gl
987 test_imgfile
Jason Tishlerc23f39c2003-07-22 18:35:58 +0000988 test_ioctl
Jason Tishler25115942002-12-05 15:18:15 +0000989 test_largefile
990 test_linuxaudiodev
991 test_locale
992 test_mpz
993 test_nis
Jason Tishler5c4ded22003-02-05 16:46:01 +0000994 test_ossaudiodev
Jason Tishler25115942002-12-05 15:18:15 +0000995 test_socketserver
996 test_sunaudiodev
Jason Tishler25115942002-12-05 15:18:15 +0000997 """,
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000998 'os2emx':
999 """
1000 test_al
Guido van Rossum944a6c32003-11-20 22:11:29 +00001001 test_applesingle
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +00001002 test_audioop
Skip Montanaro823ba282003-05-06 20:36:24 +00001003 test_bsddb185
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +00001004 test_bsddb3
1005 test_cd
1006 test_cl
1007 test_commands
1008 test_curses
1009 test_dl
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +00001010 test_gl
1011 test_imgfile
1012 test_largefile
1013 test_linuxaudiodev
1014 test_mhlib
1015 test_mmap
1016 test_nis
1017 test_openpty
1018 test_ossaudiodev
1019 test_pty
1020 test_resource
1021 test_signal
1022 test_sunaudiodev
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +00001023 """,
Guido van Rossum944a6c32003-11-20 22:11:29 +00001024 'freebsd4':
1025 """
1026 test_aepack
1027 test_al
1028 test_applesingle
1029 test_bsddb
1030 test_bsddb3
1031 test_cd
1032 test_cl
Guido van Rossum944a6c32003-11-20 22:11:29 +00001033 test_gl
1034 test_imgfile
1035 test_linuxaudiodev
1036 test_locale
1037 test_macfs
1038 test_macostools
1039 test_nis
1040 test_normalization
1041 test_ossaudiodev
1042 test_pep277
1043 test_plistlib
1044 test_scriptpackages
1045 test_socket_ssl
1046 test_socketserver
1047 test_sunaudiodev
1048 test_timeout
1049 test_unicode_file
1050 test_urllibnet
1051 test_winreg
1052 test_winsound
Martin v. Löwis56f88112003-06-07 20:01:37 +00001053 """,
Guido van Rossumf73e30c2001-08-12 02:22:19 +00001054}
Martin v. Löwis32d0c1b2004-07-26 12:09:13 +00001055_expectations['freebsd5'] = _expectations['freebsd4']
Guido van Rossumf73e30c2001-08-12 02:22:19 +00001056
Tim Petersb5b7b782001-08-12 01:20:39 +00001057class _ExpectedSkips:
1058 def __init__(self):
Tim Peters2a182db2002-10-09 01:07:11 +00001059 import os.path
Tim Peters1b445d32002-11-24 18:53:11 +00001060 from test import test_normalization
Tim Petersb4ee4eb2002-12-04 03:26:57 +00001061 from test import test_socket_ssl
Neal Norwitz55b61d22003-02-28 19:57:03 +00001062 from test import test_timeout
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001063 from test import test_codecmaps_cn, test_codecmaps_jp
1064 from test import test_codecmaps_kr, test_codecmaps_tw
Hye-Shik Chang5ef60182004-07-19 06:39:37 +00001065 from test import test_codecmaps_hk
Tim Peters1b445d32002-11-24 18:53:11 +00001066
Tim Peters7c7efe92002-08-23 17:55:54 +00001067 self.valid = False
Tim Petersde14a302002-04-01 05:04:46 +00001068 if sys.platform in _expectations:
Guido van Rossumf73e30c2001-08-12 02:22:19 +00001069 s = _expectations[sys.platform]
Raymond Hettingera690a992003-11-16 16:17:49 +00001070 self.expected = set(s.split())
Tim Peters1b445d32002-11-24 18:53:11 +00001071
Tim Peters2a182db2002-10-09 01:07:11 +00001072 if not os.path.supports_unicode_filenames:
1073 self.expected.add('test_pep277')
Tim Peters1b445d32002-11-24 18:53:11 +00001074
1075 if test_normalization.skip_expected:
1076 self.expected.add('test_normalization')
1077
Tim Petersb4ee4eb2002-12-04 03:26:57 +00001078 if test_socket_ssl.skip_expected:
1079 self.expected.add('test_socket_ssl')
1080
Neal Norwitz55b61d22003-02-28 19:57:03 +00001081 if test_timeout.skip_expected:
1082 self.expected.add('test_timeout')
1083
Hye-Shik Chang5ef60182004-07-19 06:39:37 +00001084 for cc in ('cn', 'jp', 'kr', 'tw', 'hk'):
Hye-Shik Chang3e2a3062004-01-17 14:29:29 +00001085 if eval('test_codecmaps_' + cc).skip_expected:
1086 self.expected.add('test_codecmaps_' + cc)
1087
Jack Jansen6afc5e02003-01-29 16:24:16 +00001088 if not sys.platform in ("mac", "darwin"):
Neal Norwitz7035c982003-03-29 22:01:17 +00001089 MAC_ONLY = ["test_macostools", "test_macfs", "test_aepack",
1090 "test_plistlib", "test_scriptpackages"]
1091 for skip in MAC_ONLY:
1092 self.expected.add(skip)
Tim Petersecd79eb2003-01-29 00:35:32 +00001093
1094 if sys.platform != "win32":
Neal Norwitz7035c982003-03-29 22:01:17 +00001095 WIN_ONLY = ["test_unicode_file", "test_winreg",
1096 "test_winsound"]
1097 for skip in WIN_ONLY:
1098 self.expected.add(skip)
Tim Petersf2715e02003-02-19 02:35:07 +00001099
Tim Peters7c7efe92002-08-23 17:55:54 +00001100 self.valid = True
Tim Petersb5b7b782001-08-12 01:20:39 +00001101
1102 def isvalid(self):
1103 "Return true iff _ExpectedSkips knows about the current platform."
1104 return self.valid
1105
1106 def getexpected(self):
1107 """Return set of test names we expect to skip on current platform.
1108
1109 self.isvalid() must be true.
1110 """
1111
1112 assert self.isvalid()
1113 return self.expected
1114
Guido van Rossum152494a1996-12-20 03:12:20 +00001115if __name__ == '__main__':
Barry Warsaw408b6d32002-07-30 23:27:12 +00001116 # Remove regrtest.py's own directory from the module search path. This
1117 # prevents relative imports from working, and relative imports will screw
1118 # up the testing framework. E.g. if both test.test_support and
1119 # test_support are imported, they will not contain the same globals, and
1120 # much of the testing framework relies on the globals in the
1121 # test.test_support module.
1122 mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
1123 i = pathlen = len(sys.path)
1124 while i >= 0:
1125 i -= 1
1126 if os.path.abspath(os.path.normpath(sys.path[i])) == mydir:
1127 del sys.path[i]
1128 if len(sys.path) == pathlen:
1129 print 'Could not find %r in sys.path to remove it' % mydir
Barry Warsaw08fca522001-08-20 22:33:46 +00001130 main()