blob: 12e65e5b8fe4f34ffd6b343df980cc17d5e26cac [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
Tim Peters7c7efe92002-08-23 17:55:54 +000078from sets import Set
Guido van Rossumdc15c272002-08-12 21:55:51 +000079
80# I see no other way to suppress these warnings;
81# putting them in test_grammar.py has no effect:
Guido van Rossum88b1def2002-08-14 17:54:48 +000082warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
Guido van Rossumdc15c272002-08-12 21:55:51 +000083 ".*test.test_grammar$")
Guido van Rossumc34c4fc2002-09-19 00:42:16 +000084if sys.maxint > 0x7fffffff:
85 # Also suppress them in <string>, because for 64-bit platforms,
86 # that's where test_grammar.py hides them.
87 warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
88 "<string>")
Guido van Rossum152494a1996-12-20 03:12:20 +000089
Guido van Rossumbb484652002-12-02 09:56:21 +000090# MacOSX (a.k.a. Darwin) has a default stack size that is too small
91# for deeply recursive regular expressions. We see this as crashes in
92# the Python test suite when running test_re.py and test_sre.py. The
93# fix is to set the stack limit to 2048.
94# This approach may also be useful for other Unixy platforms that
95# suffer from small default stack limits.
96if sys.platform == 'darwin':
97 try:
98 import resource
99 except ImportError:
100 pass
101 else:
102 soft, hard = resource.getrlimit(resource.RLIMIT_STACK)
103 newsoft = min(hard, max(soft, 1024*2048))
104 resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard))
105
Barry Warsaw04f357c2002-07-23 19:04:11 +0000106from test import test_support
Fred Drake3a15dac2002-04-11 16:39:16 +0000107
Guido van Rossum315aa362003-03-11 14:46:48 +0000108RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', 'bsddb')
Fred Drake3a15dac2002-04-11 16:39:16 +0000109
110
Barry Warsaw08fca522001-08-20 22:33:46 +0000111def usage(code, msg=''):
112 print __doc__
113 if msg: print msg
114 sys.exit(code)
115
116
Skip Montanaroab1c7912000-06-30 16:39:27 +0000117def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
Tim Petersc5000df2002-06-02 21:42:01 +0000118 exclude=0, single=0, randomize=0, fromfile=None, findleaks=0,
Barry Warsaw08fca522001-08-20 22:33:46 +0000119 use_resources=None):
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000120 """Execute a test suite.
121
Thomas Wouters7e474022000-07-16 12:04:32 +0000122 This also parses command-line options and modifies its behavior
Fred Drake004d5e62000-10-23 17:22:08 +0000123 accordingly.
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000124
125 tests -- a list of strings containing test names (optional)
126 testdir -- the directory in which to look for tests (optional)
127
128 Users other than the Python test suite will certainly want to
129 specify testdir; if it's omitted, the directory containing the
Fred Drake004d5e62000-10-23 17:22:08 +0000130 Python test suite is searched for.
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000131
132 If the tests argument is omitted, the tests listed on the
133 command-line will be used. If that's empty, too, then all *.py
134 files beginning with test_ will be used.
Skip Montanaroab1c7912000-06-30 16:39:27 +0000135
Guido van Rossum9e9d4f82002-06-07 15:17:03 +0000136 The other default arguments (verbose, quiet, generate, exclude,
137 single, randomize, findleaks, and use_resources) allow programmers
138 calling main() directly to set the values that would normally be
139 set by flags on the command line.
Barry Warsawa873b032000-08-03 15:50:37 +0000140
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000141 """
Fred Drake004d5e62000-10-23 17:22:08 +0000142
Tim Peters8dee8092001-09-25 20:05:11 +0000143 test_support.record_original_stdout(sys.stdout)
Guido van Rossum152494a1996-12-20 03:12:20 +0000144 try:
Guido van Rossum9e9d4f82002-06-07 15:17:03 +0000145 opts, args = getopt.getopt(sys.argv[1:], 'hvgqxsrf:lu:t:',
Barry Warsaw08fca522001-08-20 22:33:46 +0000146 ['help', 'verbose', 'quiet', 'generate',
Tim Petersc5000df2002-06-02 21:42:01 +0000147 'exclude', 'single', 'random', 'fromfile',
Guido van Rossum9e9d4f82002-06-07 15:17:03 +0000148 'findleaks', 'use=', 'threshold='])
Guido van Rossum152494a1996-12-20 03:12:20 +0000149 except getopt.error, msg:
Barry Warsaw08fca522001-08-20 22:33:46 +0000150 usage(2, msg)
151
152 # Defaults
153 if use_resources is None:
154 use_resources = []
Guido van Rossum152494a1996-12-20 03:12:20 +0000155 for o, a in opts:
Barry Warsaw08fca522001-08-20 22:33:46 +0000156 if o in ('-h', '--help'):
157 usage(0)
158 elif o in ('-v', '--verbose'):
159 verbose += 1
160 elif o in ('-q', '--quiet'):
161 quiet = 1;
162 verbose = 0
163 elif o in ('-g', '--generate'):
164 generate = 1
165 elif o in ('-x', '--exclude'):
166 exclude = 1
167 elif o in ('-s', '--single'):
168 single = 1
169 elif o in ('-r', '--randomize'):
170 randomize = 1
Tim Petersc5000df2002-06-02 21:42:01 +0000171 elif o in ('-f', '--fromfile'):
172 fromfile = a
Barry Warsaw08fca522001-08-20 22:33:46 +0000173 elif o in ('-l', '--findleaks'):
174 findleaks = 1
Guido van Rossum9e9d4f82002-06-07 15:17:03 +0000175 elif o in ('-t', '--threshold'):
176 import gc
177 gc.set_threshold(int(a))
Barry Warsaw08fca522001-08-20 22:33:46 +0000178 elif o in ('-u', '--use'):
Guido van Rossumfe3f6962001-09-06 16:09:41 +0000179 u = [x.lower() for x in a.split(',')]
180 for r in u:
Fred Drake3a15dac2002-04-11 16:39:16 +0000181 if r == 'all':
Fred Drake4dd0f7e2002-11-26 21:44:56 +0000182 use_resources[:] = RESOURCE_NAMES
183 continue
184 remove = False
185 if r[0] == '-':
186 remove = True
187 r = r[1:]
Fred Drake3a15dac2002-04-11 16:39:16 +0000188 if r not in RESOURCE_NAMES:
189 usage(1, 'Invalid -u/--use option: ' + a)
Fred Drake4dd0f7e2002-11-26 21:44:56 +0000190 if remove:
191 if r in use_resources:
192 use_resources.remove(r)
193 elif r not in use_resources:
Andrew MacIntyree41abab2002-04-30 12:11:04 +0000194 use_resources.append(r)
Guido van Rossuma4122201997-08-18 20:08:24 +0000195 if generate and verbose:
Barry Warsaw08fca522001-08-20 22:33:46 +0000196 usage(2, "-g and -v don't go together!")
Tim Petersc5000df2002-06-02 21:42:01 +0000197 if single and fromfile:
198 usage(2, "-s and -f don't go together!")
Barry Warsaw08fca522001-08-20 22:33:46 +0000199
Guido van Rossum152494a1996-12-20 03:12:20 +0000200 good = []
201 bad = []
202 skipped = []
Fred Drake9a0db072003-02-03 15:19:30 +0000203 resource_denieds = []
Barry Warsawe11e3de1999-01-28 19:51:51 +0000204
Neil Schemenauerd569f232000-09-22 15:29:28 +0000205 if findleaks:
Barry Warsawa873b032000-08-03 15:50:37 +0000206 try:
207 import gc
208 except ImportError:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000209 print 'No GC available, disabling findleaks.'
Neil Schemenauerd569f232000-09-22 15:29:28 +0000210 findleaks = 0
Barry Warsawa873b032000-08-03 15:50:37 +0000211 else:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000212 # Uncomment the line below to report garbage that is not
213 # freeable by reference counting alone. By default only
214 # garbage that is not collectable by the GC is reported.
215 #gc.set_debug(gc.DEBUG_SAVEALL)
Neil Schemenauerd569f232000-09-22 15:29:28 +0000216 found_garbage = []
Barry Warsawa873b032000-08-03 15:50:37 +0000217
Barry Warsawe11e3de1999-01-28 19:51:51 +0000218 if single:
219 from tempfile import gettempdir
220 filename = os.path.join(gettempdir(), 'pynexttest')
221 try:
222 fp = open(filename, 'r')
Eric S. Raymondfc170b12001-02-09 11:51:27 +0000223 next = fp.read().strip()
Barry Warsawe11e3de1999-01-28 19:51:51 +0000224 tests = [next]
225 fp.close()
226 except IOError:
227 pass
Tim Petersc5000df2002-06-02 21:42:01 +0000228
229 if fromfile:
230 tests = []
231 fp = open(fromfile)
232 for line in fp:
233 guts = line.split() # assuming no test has whitespace in its name
234 if guts and not guts[0].startswith('#'):
235 tests.extend(guts)
236 fp.close()
237
238 # Strip .py extensions.
239 if args:
240 args = map(removepy, args)
241 if tests:
242 tests = map(removepy, tests)
243
Guido van Rossum6c74fea1998-08-25 12:29:08 +0000244 stdtests = STDTESTS[:]
245 nottests = NOTTESTS[:]
Guido van Rossum152494a1996-12-20 03:12:20 +0000246 if exclude:
Guido van Rossum6c74fea1998-08-25 12:29:08 +0000247 for arg in args:
248 if arg in stdtests:
249 stdtests.remove(arg)
250 nottests[:0] = args
Guido van Rossum41360a41998-03-26 19:42:58 +0000251 args = []
Guido van Rossum747e1ca1998-08-24 13:48:36 +0000252 tests = tests or args or findtests(testdir, stdtests, nottests)
Barry Warsawe11e3de1999-01-28 19:51:51 +0000253 if single:
254 tests = tests[:1]
Skip Montanaroab1c7912000-06-30 16:39:27 +0000255 if randomize:
256 random.shuffle(tests)
Guido van Rossum41360a41998-03-26 19:42:58 +0000257 test_support.verbose = verbose # Tell tests to be moderately quiet
Barry Warsaw08fca522001-08-20 22:33:46 +0000258 test_support.use_resources = use_resources
Guido van Rossum5796d262000-04-21 21:35:06 +0000259 save_modules = sys.modules.keys()
Guido van Rossum152494a1996-12-20 03:12:20 +0000260 for test in tests:
Guido van Rossum41360a41998-03-26 19:42:58 +0000261 if not quiet:
262 print test
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000263 sys.stdout.flush()
Trent Mickf29f47b2000-08-11 19:02:59 +0000264 ok = runtest(test, generate, verbose, quiet, testdir)
Guido van Rossum41360a41998-03-26 19:42:58 +0000265 if ok > 0:
266 good.append(test)
267 elif ok == 0:
268 bad.append(test)
269 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000270 skipped.append(test)
Fred Drake9a0db072003-02-03 15:19:30 +0000271 if ok == -2:
272 resource_denieds.append(test)
Neil Schemenauerd569f232000-09-22 15:29:28 +0000273 if findleaks:
274 gc.collect()
275 if gc.garbage:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000276 print "Warning: test created", len(gc.garbage),
277 print "uncollectable object(s)."
278 # move the uncollectable objects somewhere so we don't see
279 # them again
Neil Schemenauerd569f232000-09-22 15:29:28 +0000280 found_garbage.extend(gc.garbage)
281 del gc.garbage[:]
Guido van Rossum5796d262000-04-21 21:35:06 +0000282 # Unload the newly imported modules (best effort finalization)
283 for module in sys.modules.keys():
Guido van Rossum51931142000-05-05 14:27:39 +0000284 if module not in save_modules and module.startswith("test."):
Guido van Rossum5796d262000-04-21 21:35:06 +0000285 test_support.unload(module)
Jeremy Hylton7a1ea0e2001-10-17 13:45:28 +0000286
287 # The lists won't be sorted if running with -r
288 good.sort()
289 bad.sort()
290 skipped.sort()
Tim Peterse0c446b2001-10-18 21:57:37 +0000291
Guido van Rossum152494a1996-12-20 03:12:20 +0000292 if good and not quiet:
Guido van Rossum41360a41998-03-26 19:42:58 +0000293 if not bad and not skipped and len(good) > 1:
294 print "All",
295 print count(len(good), "test"), "OK."
Tim Peters1a4d77b2000-12-30 22:21:22 +0000296 if verbose:
Barry Warsaw408b6d32002-07-30 23:27:12 +0000297 print "CAUTION: stdout isn't compared in verbose mode:"
298 print "a test that passes in verbose mode may fail without it."
Guido van Rossum152494a1996-12-20 03:12:20 +0000299 if bad:
Tim Petersa45da922001-08-12 03:45:50 +0000300 print count(len(bad), "test"), "failed:"
301 printlist(bad)
Guido van Rossum152494a1996-12-20 03:12:20 +0000302 if skipped and not quiet:
Tim Petersa45da922001-08-12 03:45:50 +0000303 print count(len(skipped), "test"), "skipped:"
304 printlist(skipped)
Barry Warsawe11e3de1999-01-28 19:51:51 +0000305
Tim Petersb5b7b782001-08-12 01:20:39 +0000306 e = _ExpectedSkips()
Tim Petersa2be2d62001-08-12 02:01:09 +0000307 plat = sys.platform
Tim Petersb5b7b782001-08-12 01:20:39 +0000308 if e.isvalid():
Fred Drake9a0db072003-02-03 15:19:30 +0000309 surprise = Set(skipped) - e.getexpected() - Set(resource_denieds)
Tim Petersb5b7b782001-08-12 01:20:39 +0000310 if surprise:
311 print count(len(surprise), "skip"), \
Tim Petersa45da922001-08-12 03:45:50 +0000312 "unexpected on", plat + ":"
313 printlist(surprise)
Tim Petersb5b7b782001-08-12 01:20:39 +0000314 else:
315 print "Those skips are all expected on", plat + "."
316 else:
317 print "Ask someone to teach regrtest.py about which tests are"
318 print "expected to get skipped on", plat + "."
319
Barry Warsawe11e3de1999-01-28 19:51:51 +0000320 if single:
321 alltests = findtests(testdir, stdtests, nottests)
322 for i in range(len(alltests)):
323 if tests[0] == alltests[i]:
324 if i == len(alltests) - 1:
325 os.unlink(filename)
326 else:
327 fp = open(filename, 'w')
328 fp.write(alltests[i+1] + '\n')
329 fp.close()
330 break
331 else:
332 os.unlink(filename)
333
Tim Peters5943b4a2003-07-23 00:30:39 +0000334 sys.exit(len(bad) > 0)
Barry Warsaw08fca522001-08-20 22:33:46 +0000335
Guido van Rossum152494a1996-12-20 03:12:20 +0000336
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000337STDTESTS = [
Guido van Rossum152494a1996-12-20 03:12:20 +0000338 'test_grammar',
339 'test_opcodes',
340 'test_operations',
341 'test_builtin',
342 'test_exceptions',
343 'test_types',
344 ]
345
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000346NOTTESTS = [
Guido van Rossum152494a1996-12-20 03:12:20 +0000347 'test_support',
Jeremy Hylton62e2c7e2001-02-28 17:48:06 +0000348 'test_future1',
349 'test_future2',
Jeremy Hylton8471a352001-08-20 20:33:42 +0000350 'test_future3',
Guido van Rossum152494a1996-12-20 03:12:20 +0000351 ]
352
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000353def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
Guido van Rossum152494a1996-12-20 03:12:20 +0000354 """Return a list of all applicable test modules."""
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000355 if not testdir: testdir = findtestdir()
Guido van Rossum152494a1996-12-20 03:12:20 +0000356 names = os.listdir(testdir)
357 tests = []
358 for name in names:
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000359 if name[:5] == "test_" and name[-3:] == os.extsep+"py":
Guido van Rossum41360a41998-03-26 19:42:58 +0000360 modname = name[:-3]
361 if modname not in stdtests and modname not in nottests:
362 tests.append(modname)
Guido van Rossum152494a1996-12-20 03:12:20 +0000363 tests.sort()
364 return stdtests + tests
365
Trent Mickf29f47b2000-08-11 19:02:59 +0000366def runtest(test, generate, verbose, quiet, testdir = None):
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000367 """Run a single test.
368 test -- the name of the test
369 generate -- if true, generate output, instead of running the test
370 and comparing it to a previously created output file
371 verbose -- if true, print more messages
Trent Mickf29f47b2000-08-11 19:02:59 +0000372 quiet -- if true, don't print 'skipped' messages (probably redundant)
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000373 testdir -- test directory
374 """
Guido van Rossum152494a1996-12-20 03:12:20 +0000375 test_support.unload(test)
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000376 if not testdir: testdir = findtestdir()
Guido van Rossum152494a1996-12-20 03:12:20 +0000377 outputdir = os.path.join(testdir, "output")
378 outputfile = os.path.join(outputdir, test)
Tim Peters9390cc12001-09-28 20:14:46 +0000379 if verbose:
Guido van Rossum41360a41998-03-26 19:42:58 +0000380 cfp = None
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000381 else:
Raymond Hettinger74e67662003-05-17 20:44:12 +0000382 cfp = cStringIO.StringIO()
Guido van Rossum152494a1996-12-20 03:12:20 +0000383 try:
Tim Peters342ca752001-09-25 19:13:20 +0000384 save_stdout = sys.stdout
Guido van Rossum41360a41998-03-26 19:42:58 +0000385 try:
386 if cfp:
387 sys.stdout = cfp
388 print test # Output file starts with test name
Barry Warsaw408b6d32002-07-30 23:27:12 +0000389 if test.startswith('test.'):
390 abstest = test
391 else:
392 # Always import it from the test package
393 abstest = 'test.' + test
394 the_package = __import__(abstest, globals(), locals(), [])
395 the_module = getattr(the_package, test)
Tim Petersd9742212001-05-22 18:28:25 +0000396 # Most tests run to completion simply as a side-effect of
397 # being imported. For the benefit of tests that can't run
398 # that way (like test_threaded_import), explicitly invoke
399 # their test_main() function (if it exists).
400 indirect_test = getattr(the_module, "test_main", None)
401 if indirect_test is not None:
402 indirect_test()
Guido van Rossum41360a41998-03-26 19:42:58 +0000403 finally:
Tim Peters342ca752001-09-25 19:13:20 +0000404 sys.stdout = save_stdout
Fred Drake9a0db072003-02-03 15:19:30 +0000405 except test_support.ResourceDenied, msg:
406 if not quiet:
407 print test, "skipped --", msg
408 sys.stdout.flush()
409 return -2
Thomas Wouters3af826e2000-08-04 13:17:51 +0000410 except (ImportError, test_support.TestSkipped), msg:
Trent Mickf29f47b2000-08-11 19:02:59 +0000411 if not quiet:
Fred Drakede4742b2002-10-17 20:36:08 +0000412 print test, "skipped --", msg
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000413 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000414 return -1
Fred Drakefe5c22a2000-08-18 16:04:05 +0000415 except KeyboardInterrupt:
416 raise
Guido van Rossum152494a1996-12-20 03:12:20 +0000417 except test_support.TestFailed, msg:
Guido van Rossum41360a41998-03-26 19:42:58 +0000418 print "test", test, "failed --", msg
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000419 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000420 return 0
Guido van Rossum9e48b271997-07-16 01:56:13 +0000421 except:
Guido van Rossum41360a41998-03-26 19:42:58 +0000422 type, value = sys.exc_info()[:2]
Fred Drake27c4b392000-08-23 20:34:40 +0000423 print "test", test, "crashed --", str(type) + ":", value
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000424 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000425 if verbose:
426 traceback.print_exc(file=sys.stdout)
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000427 sys.stdout.flush()
Guido van Rossum41360a41998-03-26 19:42:58 +0000428 return 0
Guido van Rossum152494a1996-12-20 03:12:20 +0000429 else:
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000430 if not cfp:
431 return 1
432 output = cfp.getvalue()
Fred Drakee51fe8d2001-05-29 17:10:51 +0000433 if generate:
Fred Drakee51fe8d2001-05-29 17:10:51 +0000434 if output == test + "\n":
435 if os.path.exists(outputfile):
436 # Write it since it already exists (and the contents
437 # may have changed), but let the user know it isn't
438 # needed:
Fred Drakee51fe8d2001-05-29 17:10:51 +0000439 print "output file", outputfile, \
440 "is no longer needed; consider removing it"
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000441 else:
442 # We don't need it, so don't create it.
443 return 1
444 fp = open(outputfile, "w")
445 fp.write(output)
446 fp.close()
447 return 1
448 if os.path.exists(outputfile):
449 fp = open(outputfile, "r")
450 expected = fp.read()
451 fp.close()
452 else:
453 expected = test + "\n"
454 if output == expected:
455 return 1
456 print "test", test, "produced unexpected output:"
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000457 sys.stdout.flush()
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000458 reportdiff(expected, output)
Guido van Rossum3cda93e2002-09-13 21:28:03 +0000459 sys.stdout.flush()
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000460 return 0
461
462def reportdiff(expected, output):
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000463 import difflib
Tim Petersc377b162001-09-22 05:31:03 +0000464 print "*" * 70
465 a = expected.splitlines(1)
466 b = output.splitlines(1)
Guido van Rossumcf691932001-09-21 21:06:22 +0000467 sm = difflib.SequenceMatcher(a=a, b=b)
468 tuples = sm.get_opcodes()
Tim Petersc377b162001-09-22 05:31:03 +0000469
Guido van Rossumcf691932001-09-21 21:06:22 +0000470 def pair(x0, x1):
Tim Petersc377b162001-09-22 05:31:03 +0000471 # x0:x1 are 0-based slice indices; convert to 1-based line indices.
Guido van Rossumcf691932001-09-21 21:06:22 +0000472 x0 += 1
473 if x0 >= x1:
Tim Petersc377b162001-09-22 05:31:03 +0000474 return "line " + str(x0)
Guido van Rossumcf691932001-09-21 21:06:22 +0000475 else:
Tim Petersc377b162001-09-22 05:31:03 +0000476 return "lines %d-%d" % (x0, x1)
477
Guido van Rossumcf691932001-09-21 21:06:22 +0000478 for op, a0, a1, b0, b1 in tuples:
479 if op == 'equal':
480 pass
Tim Petersc377b162001-09-22 05:31:03 +0000481
Guido van Rossumcf691932001-09-21 21:06:22 +0000482 elif op == 'delete':
Tim Petersc377b162001-09-22 05:31:03 +0000483 print "***", pair(a0, a1), "of expected output missing:"
Guido van Rossumcf691932001-09-21 21:06:22 +0000484 for line in a[a0:a1]:
Tim Petersc377b162001-09-22 05:31:03 +0000485 print "-", line,
486
Guido van Rossumcf691932001-09-21 21:06:22 +0000487 elif op == 'replace':
Tim Petersc377b162001-09-22 05:31:03 +0000488 print "*** mismatch between", pair(a0, a1), "of expected", \
489 "output and", pair(b0, b1), "of actual output:"
490 for line in difflib.ndiff(a[a0:a1], b[b0:b1]):
491 print line,
492
Guido van Rossumcf691932001-09-21 21:06:22 +0000493 elif op == 'insert':
Tim Petersc377b162001-09-22 05:31:03 +0000494 print "***", pair(b0, b1), "of actual output doesn't appear", \
495 "in expected output after line", str(a1)+":"
Guido van Rossumcf691932001-09-21 21:06:22 +0000496 for line in b[b0:b1]:
Tim Petersc377b162001-09-22 05:31:03 +0000497 print "+", line,
498
Guido van Rossumcf691932001-09-21 21:06:22 +0000499 else:
500 print "get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1)
Tim Petersc377b162001-09-22 05:31:03 +0000501
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000502 print "*" * 70
Guido van Rossum152494a1996-12-20 03:12:20 +0000503
504def findtestdir():
505 if __name__ == '__main__':
Guido van Rossum41360a41998-03-26 19:42:58 +0000506 file = sys.argv[0]
Guido van Rossum152494a1996-12-20 03:12:20 +0000507 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000508 file = __file__
Guido van Rossum152494a1996-12-20 03:12:20 +0000509 testdir = os.path.dirname(file) or os.curdir
510 return testdir
511
Tim Petersc5000df2002-06-02 21:42:01 +0000512def removepy(name):
513 if name.endswith(os.extsep + "py"):
514 name = name[:-3]
515 return name
516
Guido van Rossum152494a1996-12-20 03:12:20 +0000517def count(n, word):
518 if n == 1:
Guido van Rossum41360a41998-03-26 19:42:58 +0000519 return "%d %s" % (n, word)
Guido van Rossum152494a1996-12-20 03:12:20 +0000520 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000521 return "%d %ss" % (n, word)
Guido van Rossum152494a1996-12-20 03:12:20 +0000522
Tim Petersa45da922001-08-12 03:45:50 +0000523def printlist(x, width=70, indent=4):
Tim Peters7c7efe92002-08-23 17:55:54 +0000524 """Print the elements of iterable x to stdout.
Tim Petersa45da922001-08-12 03:45:50 +0000525
526 Optional arg width (default 70) is the maximum line length.
527 Optional arg indent (default 4) is the number of blanks with which to
528 begin each line.
529 """
530
Tim Petersba78bc42002-07-04 19:45:06 +0000531 from textwrap import fill
532 blanks = ' ' * indent
533 print fill(' '.join(map(str, x)), width,
534 initial_indent=blanks, subsequent_indent=blanks)
Tim Petersa45da922001-08-12 03:45:50 +0000535
Tim Petersde14a302002-04-01 05:04:46 +0000536# Map sys.platform to a string containing the basenames of tests
537# expected to be skipped on that platform.
Tim Peters2a182db2002-10-09 01:07:11 +0000538#
539# Special cases:
540# test_pep277
541# The _ExpectedSkips constructor adds this to the set of expected
542# skips if not os.path.supports_unicode_filenames.
Tim Peters1b445d32002-11-24 18:53:11 +0000543# test_normalization
544# Whether a skip is expected here depends on whether a large test
545# input file has been downloaded. test_normalization.skip_expected
Tim Peters1babdfc2002-11-24 19:19:09 +0000546# controls that.
Tim Petersb4ee4eb2002-12-04 03:26:57 +0000547# test_socket_ssl
548# Controlled by test_socket_ssl.skip_expected. Requires the network
549# resource, and a socket module with ssl support.
Neal Norwitz55b61d22003-02-28 19:57:03 +0000550# test_timeout
551# Controlled by test_timeout.skip_expected. Requires the network
552# resource and a socket module.
Tim Petersde14a302002-04-01 05:04:46 +0000553
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000554_expectations = {
555 'win32':
556 """
557 test_al
Skip Montanaro823ba282003-05-06 20:36:24 +0000558 test_bsddb185
Tim Peters78e35f92002-11-22 20:00:34 +0000559 test_bsddb3
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000560 test_cd
561 test_cl
562 test_commands
563 test_crypt
Tim Petersd7030572001-10-22 22:06:08 +0000564 test_curses
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000565 test_dbm
566 test_dl
Tim Petersdeb121a2002-04-11 19:52:58 +0000567 test_email_codecs
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000568 test_fcntl
569 test_fork1
570 test_gdbm
571 test_gl
572 test_grp
573 test_imgfile
Tim Petersfd8e6e52003-03-04 00:26:38 +0000574 test_ioctl
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000575 test_largefile
576 test_linuxaudiodev
577 test_mhlib
Tim Petersde14a302002-04-01 05:04:46 +0000578 test_mpz
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000579 test_nis
580 test_openpty
Tim Petersefc4b122002-12-10 18:47:56 +0000581 test_ossaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000582 test_poll
Tim Peters003eb302003-02-17 21:48:48 +0000583 test_posix
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000584 test_pty
585 test_pwd
Tim Peters1e33ffa2002-04-23 23:09:02 +0000586 test_resource
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000587 test_signal
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000588 test_sunaudiodev
589 test_timing
590 """,
591 'linux2':
592 """
593 test_al
Skip Montanaro823ba282003-05-06 20:36:24 +0000594 test_bsddb185
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000595 test_cd
596 test_cl
Guido van Rossumf66dacd2001-10-23 15:10:55 +0000597 test_curses
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000598 test_dl
Guido van Rossum6184c112002-04-16 02:14:04 +0000599 test_email_codecs
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000600 test_gl
601 test_imgfile
602 test_largefile
Guido van Rossum4507ec72003-02-14 19:29:22 +0000603 test_linuxaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000604 test_nis
605 test_ntpath
Guido van Rossum4507ec72003-02-14 19:29:22 +0000606 test_ossaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000607 test_sunaudiodev
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000608 """,
Jack Jansen49a806e2001-08-28 14:49:00 +0000609 'mac':
Guido van Rossumaa782362001-09-02 03:58:41 +0000610 """
611 test_al
Jack Jansen67975142003-01-08 16:31:11 +0000612 test_atexit
Guido van Rossumaa782362001-09-02 03:58:41 +0000613 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000614 test_bsddb185
Jack Jansen67975142003-01-08 16:31:11 +0000615 test_bsddb3
616 test_bz2
Guido van Rossumaa782362001-09-02 03:58:41 +0000617 test_cd
618 test_cl
619 test_commands
620 test_crypt
Jack Jansenb3be2162001-11-30 14:16:36 +0000621 test_curses
Guido van Rossumaa782362001-09-02 03:58:41 +0000622 test_dbm
623 test_dl
Jack Jansen67975142003-01-08 16:31:11 +0000624 test_email_codecs
Guido van Rossumaa782362001-09-02 03:58:41 +0000625 test_fcntl
626 test_fork1
627 test_gl
628 test_grp
Jack Jansenc4d6bdd2003-03-07 15:38:11 +0000629 test_ioctl
Guido van Rossumaa782362001-09-02 03:58:41 +0000630 test_imgfile
631 test_largefile
632 test_linuxaudiodev
633 test_locale
634 test_mmap
Jack Jansen67975142003-01-08 16:31:11 +0000635 test_mpz
Guido van Rossumaa782362001-09-02 03:58:41 +0000636 test_nis
637 test_ntpath
638 test_openpty
Jack Jansen67975142003-01-08 16:31:11 +0000639 test_ossaudiodev
Guido van Rossumaa782362001-09-02 03:58:41 +0000640 test_poll
Jack Jansen67975142003-01-08 16:31:11 +0000641 test_popen
Guido van Rossumaa782362001-09-02 03:58:41 +0000642 test_popen2
Jack Jansen5bb97e62003-02-21 22:33:55 +0000643 test_posix
Guido van Rossumaa782362001-09-02 03:58:41 +0000644 test_pty
645 test_pwd
Jack Jansen67975142003-01-08 16:31:11 +0000646 test_resource
Guido van Rossumaa782362001-09-02 03:58:41 +0000647 test_signal
Guido van Rossumaa782362001-09-02 03:58:41 +0000648 test_sunaudiodev
649 test_sundry
Jack Jansenc4d6bdd2003-03-07 15:38:11 +0000650 test_tarfile
Guido van Rossumaa782362001-09-02 03:58:41 +0000651 test_timing
Guido van Rossumaa782362001-09-02 03:58:41 +0000652 """,
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000653 'unixware7':
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000654 """
655 test_al
656 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000657 test_bsddb185
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000658 test_cd
659 test_cl
660 test_dl
661 test_gl
662 test_imgfile
663 test_largefile
664 test_linuxaudiodev
665 test_minidom
666 test_nis
667 test_ntpath
668 test_openpty
669 test_pyexpat
670 test_sax
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000671 test_sunaudiodev
672 test_sundry
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000673 """,
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000674 'openunix8':
675 """
676 test_al
677 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000678 test_bsddb185
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000679 test_cd
680 test_cl
681 test_dl
682 test_gl
683 test_imgfile
684 test_largefile
685 test_linuxaudiodev
686 test_minidom
687 test_nis
688 test_ntpath
689 test_openpty
690 test_pyexpat
691 test_sax
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000692 test_sunaudiodev
693 test_sundry
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000694 """,
695 'sco_sv3':
696 """
697 test_al
698 test_asynchat
699 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000700 test_bsddb185
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000701 test_cd
702 test_cl
703 test_dl
704 test_fork1
705 test_gettext
706 test_gl
707 test_imgfile
708 test_largefile
709 test_linuxaudiodev
710 test_locale
711 test_minidom
712 test_nis
713 test_ntpath
714 test_openpty
715 test_pyexpat
716 test_queue
717 test_sax
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000718 test_sunaudiodev
719 test_sundry
720 test_thread
721 test_threaded_import
722 test_threadedtempfile
723 test_threading
Martin v. Löwis21ee4092002-09-30 16:19:48 +0000724 """,
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000725 'riscos':
726 """
727 test_al
728 test_asynchat
Martin v. Löwisa94568a2003-05-10 07:36:56 +0000729 test_atexit
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000730 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000731 test_bsddb185
Martin v. Löwisa94568a2003-05-10 07:36:56 +0000732 test_bsddb3
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000733 test_cd
734 test_cl
735 test_commands
736 test_crypt
737 test_dbm
738 test_dl
739 test_fcntl
740 test_fork1
741 test_gdbm
742 test_gl
743 test_grp
744 test_imgfile
745 test_largefile
746 test_linuxaudiodev
747 test_locale
748 test_mmap
749 test_nis
750 test_ntpath
751 test_openpty
752 test_poll
753 test_popen2
754 test_pty
755 test_pwd
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000756 test_strop
757 test_sunaudiodev
758 test_sundry
759 test_thread
760 test_threaded_import
761 test_threadedtempfile
762 test_threading
763 test_timing
Guido van Rossume2ae77b2001-10-24 20:42:55 +0000764 """,
Jack Jansen8a97f4a2001-12-05 23:27:32 +0000765 'darwin':
Jack Jansen398c2362001-12-02 21:41:36 +0000766 """
767 test_al
Jack Jansenacda3392002-12-30 23:03:13 +0000768 test_bsddb
Guido van Rossum9d427002002-12-03 10:24:56 +0000769 test_bsddb3
Jack Jansen398c2362001-12-02 21:41:36 +0000770 test_cd
771 test_cl
772 test_curses
773 test_dl
Guido van Rossum9d427002002-12-03 10:24:56 +0000774 test_email_codecs
Jack Jansen398c2362001-12-02 21:41:36 +0000775 test_gdbm
776 test_gl
777 test_imgfile
778 test_largefile
779 test_linuxaudiodev
Jack Jansenacda3392002-12-30 23:03:13 +0000780 test_locale
Jack Jansen398c2362001-12-02 21:41:36 +0000781 test_minidom
Guido van Rossum9d427002002-12-03 10:24:56 +0000782 test_mpz
Jack Jansen398c2362001-12-02 21:41:36 +0000783 test_nis
784 test_ntpath
Jack Jansenacda3392002-12-30 23:03:13 +0000785 test_ossaudiodev
Jack Jansen398c2362001-12-02 21:41:36 +0000786 test_poll
Jack Jansen398c2362001-12-02 21:41:36 +0000787 test_sunaudiodev
Jack Jansen398c2362001-12-02 21:41:36 +0000788 """,
Guido van Rossum11c3f092002-07-17 15:08:24 +0000789 'sunos5':
790 """
791 test_al
792 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000793 test_bsddb185
Guido van Rossum11c3f092002-07-17 15:08:24 +0000794 test_cd
795 test_cl
796 test_curses
797 test_dbm
798 test_email_codecs
799 test_gdbm
800 test_gl
801 test_gzip
802 test_imgfile
803 test_linuxaudiodev
804 test_mpz
805 test_openpty
Guido van Rossum11c3f092002-07-17 15:08:24 +0000806 test_zipfile
807 test_zlib
Jeremy Hyltoned375e12002-07-17 15:56:55 +0000808 """,
Skip Montanarob3230212002-03-15 02:54:03 +0000809 'hp-ux11':
810 """
811 test_al
812 test_bsddb
Skip Montanaro823ba282003-05-06 20:36:24 +0000813 test_bsddb185
Skip Montanarob3230212002-03-15 02:54:03 +0000814 test_cd
815 test_cl
816 test_curses
817 test_dl
818 test_gdbm
819 test_gl
820 test_gzip
821 test_imgfile
822 test_largefile
823 test_linuxaudiodev
824 test_locale
825 test_minidom
826 test_nis
827 test_ntpath
828 test_openpty
829 test_pyexpat
830 test_sax
Skip Montanarob3230212002-03-15 02:54:03 +0000831 test_sunaudiodev
Skip Montanarob3230212002-03-15 02:54:03 +0000832 test_zipfile
833 test_zlib
834 """,
Martin v. Löwisf90ae202002-06-11 06:22:31 +0000835 'atheos':
Tim Petersc411dba2002-07-16 21:35:23 +0000836 """
837 test_al
Skip Montanaro823ba282003-05-06 20:36:24 +0000838 test_bsddb185
Tim Petersc411dba2002-07-16 21:35:23 +0000839 test_cd
840 test_cl
841 test_curses
842 test_dl
843 test_email_codecs
844 test_gdbm
845 test_gl
846 test_imgfile
847 test_largefile
848 test_linuxaudiodev
849 test_locale
850 test_mhlib
851 test_mmap
852 test_mpz
853 test_nis
854 test_poll
855 test_popen2
856 test_resource
Tim Petersc411dba2002-07-16 21:35:23 +0000857 test_sunaudiodev
Tim Petersc411dba2002-07-16 21:35:23 +0000858 """,
Jason Tishler25115942002-12-05 15:18:15 +0000859 'cygwin':
860 """
861 test_al
Skip Montanaro823ba282003-05-06 20:36:24 +0000862 test_bsddb185
Tim Petersb0f89e02002-12-05 17:20:25 +0000863 test_bsddb3
Jason Tishler25115942002-12-05 15:18:15 +0000864 test_cd
865 test_cl
866 test_curses
867 test_dbm
868 test_email_codecs
869 test_gl
870 test_imgfile
Jason Tishlerc23f39c2003-07-22 18:35:58 +0000871 test_ioctl
Jason Tishler25115942002-12-05 15:18:15 +0000872 test_largefile
873 test_linuxaudiodev
874 test_locale
875 test_mpz
876 test_nis
Jason Tishler5c4ded22003-02-05 16:46:01 +0000877 test_ossaudiodev
Jason Tishler25115942002-12-05 15:18:15 +0000878 test_socketserver
879 test_sunaudiodev
Jason Tishler25115942002-12-05 15:18:15 +0000880 """,
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000881 'os2emx':
882 """
883 test_al
884 test_audioop
Skip Montanaro823ba282003-05-06 20:36:24 +0000885 test_bsddb185
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000886 test_bsddb3
887 test_cd
888 test_cl
889 test_commands
890 test_curses
891 test_dl
892 test_email_codecs
893 test_gl
894 test_imgfile
895 test_largefile
896 test_linuxaudiodev
897 test_mhlib
898 test_mmap
899 test_nis
900 test_openpty
901 test_ossaudiodev
902 test_pty
903 test_resource
904 test_signal
905 test_sunaudiodev
Andrew MacIntyrefd07e7d2002-12-31 11:26:50 +0000906 """,
Martin v. Löwis56f88112003-06-07 20:01:37 +0000907 'freebsd4':
908 """
909 test_aepack
910 test_al
911 test_bsddb
912 test_bsddb3
913 test_cd
914 test_cl
915 test_email_codecs
916 test_gl
917 test_imgfile
918 test_linuxaudiodev
919 test_locale
920 test_macfs
921 test_macostools
922 test_nis
923 test_normalization
924 test_ossaudiodev
925 test_pep277
926 test_plistlib
927 test_scriptpackages
928 test_socket_ssl
929 test_socketserver
930 test_sunaudiodev
931 test_timeout
932 test_unicode_file
933 test_urllibnet
934 test_winreg
935 test_winsound
936 """,
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000937}
938
Tim Petersb5b7b782001-08-12 01:20:39 +0000939class _ExpectedSkips:
940 def __init__(self):
Tim Peters2a182db2002-10-09 01:07:11 +0000941 import os.path
Tim Peters1b445d32002-11-24 18:53:11 +0000942 from test import test_normalization
Tim Petersb4ee4eb2002-12-04 03:26:57 +0000943 from test import test_socket_ssl
Neal Norwitz55b61d22003-02-28 19:57:03 +0000944 from test import test_timeout
Tim Peters1b445d32002-11-24 18:53:11 +0000945
Tim Peters7c7efe92002-08-23 17:55:54 +0000946 self.valid = False
Tim Petersde14a302002-04-01 05:04:46 +0000947 if sys.platform in _expectations:
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000948 s = _expectations[sys.platform]
Tim Peters7c7efe92002-08-23 17:55:54 +0000949 self.expected = Set(s.split())
Tim Peters1b445d32002-11-24 18:53:11 +0000950
Tim Peters2a182db2002-10-09 01:07:11 +0000951 if not os.path.supports_unicode_filenames:
952 self.expected.add('test_pep277')
Tim Peters1b445d32002-11-24 18:53:11 +0000953
954 if test_normalization.skip_expected:
955 self.expected.add('test_normalization')
956
Tim Petersb4ee4eb2002-12-04 03:26:57 +0000957 if test_socket_ssl.skip_expected:
958 self.expected.add('test_socket_ssl')
959
Neal Norwitz55b61d22003-02-28 19:57:03 +0000960 if test_timeout.skip_expected:
961 self.expected.add('test_timeout')
962
Jack Jansen6afc5e02003-01-29 16:24:16 +0000963 if not sys.platform in ("mac", "darwin"):
Neal Norwitz7035c982003-03-29 22:01:17 +0000964 MAC_ONLY = ["test_macostools", "test_macfs", "test_aepack",
965 "test_plistlib", "test_scriptpackages"]
966 for skip in MAC_ONLY:
967 self.expected.add(skip)
Tim Petersecd79eb2003-01-29 00:35:32 +0000968
969 if sys.platform != "win32":
Neal Norwitz7035c982003-03-29 22:01:17 +0000970 WIN_ONLY = ["test_unicode_file", "test_winreg",
971 "test_winsound"]
972 for skip in WIN_ONLY:
973 self.expected.add(skip)
Tim Petersf2715e02003-02-19 02:35:07 +0000974
Tim Peters7c7efe92002-08-23 17:55:54 +0000975 self.valid = True
Tim Petersb5b7b782001-08-12 01:20:39 +0000976
977 def isvalid(self):
978 "Return true iff _ExpectedSkips knows about the current platform."
979 return self.valid
980
981 def getexpected(self):
982 """Return set of test names we expect to skip on current platform.
983
984 self.isvalid() must be true.
985 """
986
987 assert self.isvalid()
988 return self.expected
989
Guido van Rossum152494a1996-12-20 03:12:20 +0000990if __name__ == '__main__':
Barry Warsaw408b6d32002-07-30 23:27:12 +0000991 # Remove regrtest.py's own directory from the module search path. This
992 # prevents relative imports from working, and relative imports will screw
993 # up the testing framework. E.g. if both test.test_support and
994 # test_support are imported, they will not contain the same globals, and
995 # much of the testing framework relies on the globals in the
996 # test.test_support module.
997 mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
998 i = pathlen = len(sys.path)
999 while i >= 0:
1000 i -= 1
1001 if os.path.abspath(os.path.normpath(sys.path[i])) == mydir:
1002 del sys.path[i]
1003 if len(sys.path) == pathlen:
1004 print 'Could not find %r in sys.path to remove it' % mydir
Barry Warsaw08fca522001-08-20 22:33:46 +00001005 main()