blob: 6e5f91b7b582649426f1f91affd3a535086c6ba6 [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
Neil Schemenauer8a00abc2000-10-13 01:32:42 +000017-l: findleaks -- if GC is available detect tests that leak memory
Barry Warsaw08fca522001-08-20 22:33:46 +000018-u: use -- specify which special resource intensive tests to run
19-h: help -- print this text and exit
Guido van Rossum152494a1996-12-20 03:12:20 +000020
21If non-option arguments are present, they are names for tests to run,
22unless -x is given, in which case they are names for tests not to run.
23If no test names are given, all tests are run.
Guido van Rossumf58ed251997-03-07 21:04:33 +000024
Guido van Rossuma4122201997-08-18 20:08:24 +000025-v is incompatible with -g and does not compare test output files.
Barry Warsawe11e3de1999-01-28 19:51:51 +000026
Barry Warsaw22e41822001-02-23 18:31:40 +000027-s means to run only a single test and exit. This is useful when doing memory
28analysis on the Python interpreter (which tend to consume to many resources to
29run the full regression test non-stop). The file /tmp/pynexttest is read to
30find the next test to run. If this file is missing, the first test_*.py file
31in testdir or on the command line is used. (actually tempfile.gettempdir() is
32used instead of /tmp).
Barry Warsawe11e3de1999-01-28 19:51:51 +000033
Barry Warsaw08fca522001-08-20 22:33:46 +000034-u is used to specify which special resource intensive tests to run, such as
35those requiring large file support or network connectivity. The argument is a
36comma-separated list of words indicating the resources to test. Currently
37only the following are defined:
38
39 largefile - It is okay to run some test that may create huge files. These
40 tests can take a long time and may consume >2GB of disk space
41 temporarily.
42
43 network - It is okay to run tests that use external network resource,
44 e.g. testing SSL support for sockets.
Guido van Rossum152494a1996-12-20 03:12:20 +000045"""
46
47import sys
Guido van Rossum152494a1996-12-20 03:12:20 +000048import os
49import getopt
Guido van Rossum9e48b271997-07-16 01:56:13 +000050import traceback
Skip Montanaroab1c7912000-06-30 16:39:27 +000051import random
Fred Drakeae1bb172001-05-21 21:08:12 +000052import StringIO
Guido van Rossum152494a1996-12-20 03:12:20 +000053
54import test_support
55
Barry Warsaw08fca522001-08-20 22:33:46 +000056def usage(code, msg=''):
57 print __doc__
58 if msg: print msg
59 sys.exit(code)
60
61
Skip Montanaroab1c7912000-06-30 16:39:27 +000062def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
Neil Schemenauerd569f232000-09-22 15:29:28 +000063 exclude=0, single=0, randomize=0, findleaks=0,
Barry Warsaw08fca522001-08-20 22:33:46 +000064 use_resources=None):
Guido van Rossum6fd83b71998-08-01 17:04:08 +000065 """Execute a test suite.
66
Thomas Wouters7e474022000-07-16 12:04:32 +000067 This also parses command-line options and modifies its behavior
Fred Drake004d5e62000-10-23 17:22:08 +000068 accordingly.
Guido van Rossum6fd83b71998-08-01 17:04:08 +000069
70 tests -- a list of strings containing test names (optional)
71 testdir -- the directory in which to look for tests (optional)
72
73 Users other than the Python test suite will certainly want to
74 specify testdir; if it's omitted, the directory containing the
Fred Drake004d5e62000-10-23 17:22:08 +000075 Python test suite is searched for.
Guido van Rossum6fd83b71998-08-01 17:04:08 +000076
77 If the tests argument is omitted, the tests listed on the
78 command-line will be used. If that's empty, too, then all *.py
79 files beginning with test_ will be used.
Skip Montanaroab1c7912000-06-30 16:39:27 +000080
Barry Warsaw08fca522001-08-20 22:33:46 +000081 The other default arguments (verbose, quiet, generate, exclude, single,
82 randomize, findleaks, and use_resources) allow programmers calling main()
Barry Warsawa873b032000-08-03 15:50:37 +000083 directly to set the values that would normally be set by flags on the
84 command line.
85
Guido van Rossum6fd83b71998-08-01 17:04:08 +000086 """
Fred Drake004d5e62000-10-23 17:22:08 +000087
Tim Peters8dee8092001-09-25 20:05:11 +000088 test_support.record_original_stdout(sys.stdout)
Guido van Rossum152494a1996-12-20 03:12:20 +000089 try:
Barry Warsaw08fca522001-08-20 22:33:46 +000090 opts, args = getopt.getopt(sys.argv[1:], 'hvgqxsrlu:',
91 ['help', 'verbose', 'quiet', 'generate',
92 'exclude', 'single', 'random',
93 'findleaks', 'use='])
Guido van Rossum152494a1996-12-20 03:12:20 +000094 except getopt.error, msg:
Barry Warsaw08fca522001-08-20 22:33:46 +000095 usage(2, msg)
96
97 # Defaults
98 if use_resources is None:
99 use_resources = []
Guido van Rossum152494a1996-12-20 03:12:20 +0000100 for o, a in opts:
Barry Warsaw08fca522001-08-20 22:33:46 +0000101 if o in ('-h', '--help'):
102 usage(0)
103 elif o in ('-v', '--verbose'):
104 verbose += 1
105 elif o in ('-q', '--quiet'):
106 quiet = 1;
107 verbose = 0
108 elif o in ('-g', '--generate'):
109 generate = 1
110 elif o in ('-x', '--exclude'):
111 exclude = 1
112 elif o in ('-s', '--single'):
113 single = 1
114 elif o in ('-r', '--randomize'):
115 randomize = 1
116 elif o in ('-l', '--findleaks'):
117 findleaks = 1
118 elif o in ('-u', '--use'):
Guido van Rossumfe3f6962001-09-06 16:09:41 +0000119 u = [x.lower() for x in a.split(',')]
120 for r in u:
Barry Warsaw08fca522001-08-20 22:33:46 +0000121 if r not in ('largefile', 'network'):
122 usage(1, 'Invalid -u/--use option: %s' % a)
Guido van Rossumfe3f6962001-09-06 16:09:41 +0000123 use_resources.extend(u)
Guido van Rossuma4122201997-08-18 20:08:24 +0000124 if generate and verbose:
Barry Warsaw08fca522001-08-20 22:33:46 +0000125 usage(2, "-g and -v don't go together!")
126
Guido van Rossum152494a1996-12-20 03:12:20 +0000127 good = []
128 bad = []
129 skipped = []
Barry Warsawe11e3de1999-01-28 19:51:51 +0000130
Neil Schemenauerd569f232000-09-22 15:29:28 +0000131 if findleaks:
Barry Warsawa873b032000-08-03 15:50:37 +0000132 try:
133 import gc
134 except ImportError:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000135 print 'No GC available, disabling findleaks.'
Neil Schemenauerd569f232000-09-22 15:29:28 +0000136 findleaks = 0
Barry Warsawa873b032000-08-03 15:50:37 +0000137 else:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000138 # Uncomment the line below to report garbage that is not
139 # freeable by reference counting alone. By default only
140 # garbage that is not collectable by the GC is reported.
141 #gc.set_debug(gc.DEBUG_SAVEALL)
Neil Schemenauerd569f232000-09-22 15:29:28 +0000142 found_garbage = []
Barry Warsawa873b032000-08-03 15:50:37 +0000143
Barry Warsawe11e3de1999-01-28 19:51:51 +0000144 if single:
145 from tempfile import gettempdir
146 filename = os.path.join(gettempdir(), 'pynexttest')
147 try:
148 fp = open(filename, 'r')
Eric S. Raymondfc170b12001-02-09 11:51:27 +0000149 next = fp.read().strip()
Barry Warsawe11e3de1999-01-28 19:51:51 +0000150 tests = [next]
151 fp.close()
152 except IOError:
153 pass
Guido van Rossuma4122201997-08-18 20:08:24 +0000154 for i in range(len(args)):
Guido van Rossum41360a41998-03-26 19:42:58 +0000155 # Strip trailing ".py" from arguments
156 if args[i][-3:] == '.py':
157 args[i] = args[i][:-3]
Guido van Rossum6c74fea1998-08-25 12:29:08 +0000158 stdtests = STDTESTS[:]
159 nottests = NOTTESTS[:]
Guido van Rossum152494a1996-12-20 03:12:20 +0000160 if exclude:
Guido van Rossum6c74fea1998-08-25 12:29:08 +0000161 for arg in args:
162 if arg in stdtests:
163 stdtests.remove(arg)
164 nottests[:0] = args
Guido van Rossum41360a41998-03-26 19:42:58 +0000165 args = []
Guido van Rossum747e1ca1998-08-24 13:48:36 +0000166 tests = tests or args or findtests(testdir, stdtests, nottests)
Barry Warsawe11e3de1999-01-28 19:51:51 +0000167 if single:
168 tests = tests[:1]
Skip Montanaroab1c7912000-06-30 16:39:27 +0000169 if randomize:
170 random.shuffle(tests)
Guido van Rossum41360a41998-03-26 19:42:58 +0000171 test_support.verbose = verbose # Tell tests to be moderately quiet
Barry Warsaw08fca522001-08-20 22:33:46 +0000172 test_support.use_resources = use_resources
Guido van Rossum5796d262000-04-21 21:35:06 +0000173 save_modules = sys.modules.keys()
Guido van Rossum152494a1996-12-20 03:12:20 +0000174 for test in tests:
Guido van Rossum41360a41998-03-26 19:42:58 +0000175 if not quiet:
176 print test
Trent Mickf29f47b2000-08-11 19:02:59 +0000177 ok = runtest(test, generate, verbose, quiet, testdir)
Guido van Rossum41360a41998-03-26 19:42:58 +0000178 if ok > 0:
179 good.append(test)
180 elif ok == 0:
181 bad.append(test)
182 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000183 skipped.append(test)
Neil Schemenauerd569f232000-09-22 15:29:28 +0000184 if findleaks:
185 gc.collect()
186 if gc.garbage:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000187 print "Warning: test created", len(gc.garbage),
188 print "uncollectable object(s)."
189 # move the uncollectable objects somewhere so we don't see
190 # them again
Neil Schemenauerd569f232000-09-22 15:29:28 +0000191 found_garbage.extend(gc.garbage)
192 del gc.garbage[:]
Guido van Rossum5796d262000-04-21 21:35:06 +0000193 # Unload the newly imported modules (best effort finalization)
194 for module in sys.modules.keys():
Guido van Rossum51931142000-05-05 14:27:39 +0000195 if module not in save_modules and module.startswith("test."):
Guido van Rossum5796d262000-04-21 21:35:06 +0000196 test_support.unload(module)
Guido van Rossum152494a1996-12-20 03:12:20 +0000197 if good and not quiet:
Guido van Rossum41360a41998-03-26 19:42:58 +0000198 if not bad and not skipped and len(good) > 1:
199 print "All",
200 print count(len(good), "test"), "OK."
Tim Peters1a4d77b2000-12-30 22:21:22 +0000201 if verbose:
202 print "CAUTION: stdout isn't compared in verbose mode: a test"
203 print "that passes in verbose mode may fail without it."
Guido van Rossum152494a1996-12-20 03:12:20 +0000204 if bad:
Tim Petersa45da922001-08-12 03:45:50 +0000205 print count(len(bad), "test"), "failed:"
206 printlist(bad)
Guido van Rossum152494a1996-12-20 03:12:20 +0000207 if skipped and not quiet:
Tim Petersa45da922001-08-12 03:45:50 +0000208 print count(len(skipped), "test"), "skipped:"
209 printlist(skipped)
Barry Warsawe11e3de1999-01-28 19:51:51 +0000210
Tim Petersb5b7b782001-08-12 01:20:39 +0000211 e = _ExpectedSkips()
Tim Petersa2be2d62001-08-12 02:01:09 +0000212 plat = sys.platform
Tim Petersb5b7b782001-08-12 01:20:39 +0000213 if e.isvalid():
214 surprise = _Set(skipped) - e.getexpected()
Tim Petersb5b7b782001-08-12 01:20:39 +0000215 if surprise:
216 print count(len(surprise), "skip"), \
Tim Petersa45da922001-08-12 03:45:50 +0000217 "unexpected on", plat + ":"
218 printlist(surprise)
Tim Petersb5b7b782001-08-12 01:20:39 +0000219 else:
220 print "Those skips are all expected on", plat + "."
221 else:
222 print "Ask someone to teach regrtest.py about which tests are"
223 print "expected to get skipped on", plat + "."
224
Barry Warsawe11e3de1999-01-28 19:51:51 +0000225 if single:
226 alltests = findtests(testdir, stdtests, nottests)
227 for i in range(len(alltests)):
228 if tests[0] == alltests[i]:
229 if i == len(alltests) - 1:
230 os.unlink(filename)
231 else:
232 fp = open(filename, 'w')
233 fp.write(alltests[i+1] + '\n')
234 fp.close()
235 break
236 else:
237 os.unlink(filename)
238
Barry Warsaw08fca522001-08-20 22:33:46 +0000239 sys.exit(len(bad) > 0)
240
Guido van Rossum152494a1996-12-20 03:12:20 +0000241
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000242STDTESTS = [
Guido van Rossum152494a1996-12-20 03:12:20 +0000243 'test_grammar',
244 'test_opcodes',
245 'test_operations',
246 'test_builtin',
247 'test_exceptions',
248 'test_types',
249 ]
250
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000251NOTTESTS = [
Guido van Rossum152494a1996-12-20 03:12:20 +0000252 'test_support',
253 'test_b1',
254 'test_b2',
Jeremy Hylton62e2c7e2001-02-28 17:48:06 +0000255 'test_future1',
256 'test_future2',
Jeremy Hylton8471a352001-08-20 20:33:42 +0000257 'test_future3',
Guido van Rossum152494a1996-12-20 03:12:20 +0000258 ]
259
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000260def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
Guido van Rossum152494a1996-12-20 03:12:20 +0000261 """Return a list of all applicable test modules."""
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000262 if not testdir: testdir = findtestdir()
Guido van Rossum152494a1996-12-20 03:12:20 +0000263 names = os.listdir(testdir)
264 tests = []
265 for name in names:
Guido van Rossum41360a41998-03-26 19:42:58 +0000266 if name[:5] == "test_" and name[-3:] == ".py":
267 modname = name[:-3]
268 if modname not in stdtests and modname not in nottests:
269 tests.append(modname)
Guido van Rossum152494a1996-12-20 03:12:20 +0000270 tests.sort()
271 return stdtests + tests
272
Trent Mickf29f47b2000-08-11 19:02:59 +0000273def runtest(test, generate, verbose, quiet, testdir = None):
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000274 """Run a single test.
275 test -- the name of the test
276 generate -- if true, generate output, instead of running the test
277 and comparing it to a previously created output file
278 verbose -- if true, print more messages
Trent Mickf29f47b2000-08-11 19:02:59 +0000279 quiet -- if true, don't print 'skipped' messages (probably redundant)
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000280 testdir -- test directory
281 """
Guido van Rossum152494a1996-12-20 03:12:20 +0000282 test_support.unload(test)
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000283 if not testdir: testdir = findtestdir()
Guido van Rossum152494a1996-12-20 03:12:20 +0000284 outputdir = os.path.join(testdir, "output")
285 outputfile = os.path.join(outputdir, test)
Tim Peters9390cc12001-09-28 20:14:46 +0000286 if verbose:
Guido van Rossum41360a41998-03-26 19:42:58 +0000287 cfp = None
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000288 else:
Fred Drake88a56852001-09-28 20:16:30 +0000289 cfp = StringIO.StringIO()
Guido van Rossum152494a1996-12-20 03:12:20 +0000290 try:
Tim Peters342ca752001-09-25 19:13:20 +0000291 save_stdout = sys.stdout
Guido van Rossum41360a41998-03-26 19:42:58 +0000292 try:
293 if cfp:
294 sys.stdout = cfp
295 print test # Output file starts with test name
Tim Petersd9742212001-05-22 18:28:25 +0000296 the_module = __import__(test, globals(), locals(), [])
297 # Most tests run to completion simply as a side-effect of
298 # being imported. For the benefit of tests that can't run
299 # that way (like test_threaded_import), explicitly invoke
300 # their test_main() function (if it exists).
301 indirect_test = getattr(the_module, "test_main", None)
302 if indirect_test is not None:
303 indirect_test()
Guido van Rossum41360a41998-03-26 19:42:58 +0000304 finally:
Tim Peters342ca752001-09-25 19:13:20 +0000305 sys.stdout = save_stdout
Thomas Wouters3af826e2000-08-04 13:17:51 +0000306 except (ImportError, test_support.TestSkipped), msg:
Trent Mickf29f47b2000-08-11 19:02:59 +0000307 if not quiet:
Guido van Rossumeb949052001-09-18 20:34:19 +0000308 print "test", test, "skipped --", msg
Guido van Rossum41360a41998-03-26 19:42:58 +0000309 return -1
Fred Drakefe5c22a2000-08-18 16:04:05 +0000310 except KeyboardInterrupt:
311 raise
Guido van Rossum152494a1996-12-20 03:12:20 +0000312 except test_support.TestFailed, msg:
Guido van Rossum41360a41998-03-26 19:42:58 +0000313 print "test", test, "failed --", msg
314 return 0
Guido van Rossum9e48b271997-07-16 01:56:13 +0000315 except:
Guido van Rossum41360a41998-03-26 19:42:58 +0000316 type, value = sys.exc_info()[:2]
Fred Drake27c4b392000-08-23 20:34:40 +0000317 print "test", test, "crashed --", str(type) + ":", value
Guido van Rossum41360a41998-03-26 19:42:58 +0000318 if verbose:
319 traceback.print_exc(file=sys.stdout)
320 return 0
Guido van Rossum152494a1996-12-20 03:12:20 +0000321 else:
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000322 if not cfp:
323 return 1
324 output = cfp.getvalue()
Fred Drakee51fe8d2001-05-29 17:10:51 +0000325 if generate:
Fred Drakee51fe8d2001-05-29 17:10:51 +0000326 if output == test + "\n":
327 if os.path.exists(outputfile):
328 # Write it since it already exists (and the contents
329 # may have changed), but let the user know it isn't
330 # needed:
Fred Drakee51fe8d2001-05-29 17:10:51 +0000331 print "output file", outputfile, \
332 "is no longer needed; consider removing it"
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000333 else:
334 # We don't need it, so don't create it.
335 return 1
336 fp = open(outputfile, "w")
337 fp.write(output)
338 fp.close()
339 return 1
340 if os.path.exists(outputfile):
341 fp = open(outputfile, "r")
342 expected = fp.read()
343 fp.close()
344 else:
345 expected = test + "\n"
346 if output == expected:
347 return 1
348 print "test", test, "produced unexpected output:"
349 reportdiff(expected, output)
350 return 0
351
352def reportdiff(expected, output):
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000353 import difflib
Tim Petersc377b162001-09-22 05:31:03 +0000354 print "*" * 70
355 a = expected.splitlines(1)
356 b = output.splitlines(1)
Guido van Rossumcf691932001-09-21 21:06:22 +0000357 sm = difflib.SequenceMatcher(a=a, b=b)
358 tuples = sm.get_opcodes()
Tim Petersc377b162001-09-22 05:31:03 +0000359
Guido van Rossumcf691932001-09-21 21:06:22 +0000360 def pair(x0, x1):
Tim Petersc377b162001-09-22 05:31:03 +0000361 # x0:x1 are 0-based slice indices; convert to 1-based line indices.
Guido van Rossumcf691932001-09-21 21:06:22 +0000362 x0 += 1
363 if x0 >= x1:
Tim Petersc377b162001-09-22 05:31:03 +0000364 return "line " + str(x0)
Guido van Rossumcf691932001-09-21 21:06:22 +0000365 else:
Tim Petersc377b162001-09-22 05:31:03 +0000366 return "lines %d-%d" % (x0, x1)
367
Guido van Rossumcf691932001-09-21 21:06:22 +0000368 for op, a0, a1, b0, b1 in tuples:
369 if op == 'equal':
370 pass
Tim Petersc377b162001-09-22 05:31:03 +0000371
Guido van Rossumcf691932001-09-21 21:06:22 +0000372 elif op == 'delete':
Tim Petersc377b162001-09-22 05:31:03 +0000373 print "***", pair(a0, a1), "of expected output missing:"
Guido van Rossumcf691932001-09-21 21:06:22 +0000374 for line in a[a0:a1]:
Tim Petersc377b162001-09-22 05:31:03 +0000375 print "-", line,
376
Guido van Rossumcf691932001-09-21 21:06:22 +0000377 elif op == 'replace':
Tim Petersc377b162001-09-22 05:31:03 +0000378 print "*** mismatch between", pair(a0, a1), "of expected", \
379 "output and", pair(b0, b1), "of actual output:"
380 for line in difflib.ndiff(a[a0:a1], b[b0:b1]):
381 print line,
382
Guido van Rossumcf691932001-09-21 21:06:22 +0000383 elif op == 'insert':
Tim Petersc377b162001-09-22 05:31:03 +0000384 print "***", pair(b0, b1), "of actual output doesn't appear", \
385 "in expected output after line", str(a1)+":"
Guido van Rossumcf691932001-09-21 21:06:22 +0000386 for line in b[b0:b1]:
Tim Petersc377b162001-09-22 05:31:03 +0000387 print "+", line,
388
Guido van Rossumcf691932001-09-21 21:06:22 +0000389 else:
390 print "get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1)
Tim Petersc377b162001-09-22 05:31:03 +0000391
Guido van Rossum0fcca4e2001-09-21 20:31:52 +0000392 print "*" * 70
Guido van Rossum152494a1996-12-20 03:12:20 +0000393
394def findtestdir():
395 if __name__ == '__main__':
Guido van Rossum41360a41998-03-26 19:42:58 +0000396 file = sys.argv[0]
Guido van Rossum152494a1996-12-20 03:12:20 +0000397 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000398 file = __file__
Guido van Rossum152494a1996-12-20 03:12:20 +0000399 testdir = os.path.dirname(file) or os.curdir
400 return testdir
401
402def count(n, word):
403 if n == 1:
Guido van Rossum41360a41998-03-26 19:42:58 +0000404 return "%d %s" % (n, word)
Guido van Rossum152494a1996-12-20 03:12:20 +0000405 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000406 return "%d %ss" % (n, word)
Guido van Rossum152494a1996-12-20 03:12:20 +0000407
Tim Petersa45da922001-08-12 03:45:50 +0000408def printlist(x, width=70, indent=4):
409 """Print the elements of a sequence to stdout.
410
411 Optional arg width (default 70) is the maximum line length.
412 Optional arg indent (default 4) is the number of blanks with which to
413 begin each line.
414 """
415
416 line = ' ' * indent
417 for one in map(str, x):
418 w = len(line) + len(one)
419 if line[-1:] == ' ':
420 pad = ''
421 else:
422 pad = ' '
423 w += 1
424 if w > width:
425 print line
426 line = ' ' * indent + one
427 else:
428 line += pad + one
429 if len(line) > indent:
430 print line
431
Tim Petersb5b7b782001-08-12 01:20:39 +0000432class _Set:
433 def __init__(self, seq=[]):
434 data = self.data = {}
435 for x in seq:
436 data[x] = 1
437
438 def __len__(self):
439 return len(self.data)
440
441 def __sub__(self, other):
442 "Return set of all elements in self not in other."
443 result = _Set()
444 data = result.data = self.data.copy()
445 for x in other.data:
446 if x in data:
447 del data[x]
448 return result
449
Jeremy Hylton39f77bc2001-08-12 21:53:08 +0000450 def __iter__(self):
451 return iter(self.data)
452
Tim Petersb5b7b782001-08-12 01:20:39 +0000453 def tolist(self, sorted=1):
454 "Return _Set elements as a list."
455 data = self.data.keys()
456 if sorted:
457 data.sort()
458 return data
459
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000460_expectations = {
461 'win32':
462 """
463 test_al
464 test_cd
465 test_cl
466 test_commands
467 test_crypt
468 test_dbm
469 test_dl
470 test_fcntl
471 test_fork1
472 test_gdbm
473 test_gl
474 test_grp
475 test_imgfile
476 test_largefile
477 test_linuxaudiodev
478 test_mhlib
479 test_nis
480 test_openpty
481 test_poll
482 test_pty
483 test_pwd
484 test_signal
Barry Warsaw08fca522001-08-20 22:33:46 +0000485 test_socket_ssl
Tim Petersa86f0c12001-09-18 02:18:57 +0000486 test_socketserver
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000487 test_sunaudiodev
488 test_timing
489 """,
490 'linux2':
491 """
492 test_al
493 test_cd
494 test_cl
495 test_dl
496 test_gl
497 test_imgfile
498 test_largefile
499 test_nis
500 test_ntpath
Barry Warsaw08fca522001-08-20 22:33:46 +0000501 test_socket_ssl
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000502 test_socketserver
503 test_sunaudiodev
504 test_unicode_file
505 test_winreg
506 test_winsound
507 """,
Jack Jansen49a806e2001-08-28 14:49:00 +0000508 'mac':
Guido van Rossumaa782362001-09-02 03:58:41 +0000509 """
510 test_al
511 test_bsddb
512 test_cd
513 test_cl
514 test_commands
515 test_crypt
516 test_dbm
517 test_dl
518 test_fcntl
519 test_fork1
520 test_gl
521 test_grp
522 test_imgfile
523 test_largefile
524 test_linuxaudiodev
525 test_locale
526 test_mmap
527 test_nis
528 test_ntpath
529 test_openpty
530 test_poll
531 test_popen2
532 test_pty
533 test_pwd
534 test_signal
535 test_socket_ssl
536 test_socketserver
537 test_sunaudiodev
538 test_sundry
539 test_timing
540 test_unicode_file
541 test_winreg
542 test_winsound
543 """,
Martin v. Löwis0ace3262001-09-05 14:38:48 +0000544 'unixware5':
545 """
546 test_al
547 test_bsddb
548 test_cd
549 test_cl
550 test_dl
551 test_gl
552 test_imgfile
553 test_largefile
554 test_linuxaudiodev
555 test_minidom
556 test_nis
557 test_ntpath
558 test_openpty
559 test_pyexpat
560 test_sax
561 test_socketserver
562 test_sunaudiodev
563 test_sundry
564 test_unicode_file
565 test_winreg
566 test_winsound
567 """,
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000568}
569
Tim Petersb5b7b782001-08-12 01:20:39 +0000570class _ExpectedSkips:
571 def __init__(self):
572 self.valid = 0
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000573 if _expectations.has_key(sys.platform):
574 s = _expectations[sys.platform]
Tim Petersb5b7b782001-08-12 01:20:39 +0000575 self.expected = _Set(s.split())
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000576 self.valid = 1
Tim Petersb5b7b782001-08-12 01:20:39 +0000577
578 def isvalid(self):
579 "Return true iff _ExpectedSkips knows about the current platform."
580 return self.valid
581
582 def getexpected(self):
583 """Return set of test names we expect to skip on current platform.
584
585 self.isvalid() must be true.
586 """
587
588 assert self.isvalid()
589 return self.expected
590
Guido van Rossum152494a1996-12-20 03:12:20 +0000591if __name__ == '__main__':
Barry Warsaw08fca522001-08-20 22:33:46 +0000592 main()