blob: 62975dd29bca02d79af5f3a393c8d083401d8980 [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
Guido van Rossum152494a1996-12-20 03:12:20 +000088 try:
Barry Warsaw08fca522001-08-20 22:33:46 +000089 opts, args = getopt.getopt(sys.argv[1:], 'hvgqxsrlu:',
90 ['help', 'verbose', 'quiet', 'generate',
91 'exclude', 'single', 'random',
92 'findleaks', 'use='])
Guido van Rossum152494a1996-12-20 03:12:20 +000093 except getopt.error, msg:
Barry Warsaw08fca522001-08-20 22:33:46 +000094 usage(2, msg)
95
96 # Defaults
97 if use_resources is None:
98 use_resources = []
Guido van Rossum152494a1996-12-20 03:12:20 +000099 for o, a in opts:
Barry Warsaw08fca522001-08-20 22:33:46 +0000100 if o in ('-h', '--help'):
101 usage(0)
102 elif o in ('-v', '--verbose'):
103 verbose += 1
104 elif o in ('-q', '--quiet'):
105 quiet = 1;
106 verbose = 0
107 elif o in ('-g', '--generate'):
108 generate = 1
109 elif o in ('-x', '--exclude'):
110 exclude = 1
111 elif o in ('-s', '--single'):
112 single = 1
113 elif o in ('-r', '--randomize'):
114 randomize = 1
115 elif o in ('-l', '--findleaks'):
116 findleaks = 1
117 elif o in ('-u', '--use'):
118 use_resources = [x.lower() for x in a.split(',')]
119 for r in use_resources:
120 if r not in ('largefile', 'network'):
121 usage(1, 'Invalid -u/--use option: %s' % a)
Guido van Rossuma4122201997-08-18 20:08:24 +0000122 if generate and verbose:
Barry Warsaw08fca522001-08-20 22:33:46 +0000123 usage(2, "-g and -v don't go together!")
124
Guido van Rossum152494a1996-12-20 03:12:20 +0000125 good = []
126 bad = []
127 skipped = []
Barry Warsawe11e3de1999-01-28 19:51:51 +0000128
Neil Schemenauerd569f232000-09-22 15:29:28 +0000129 if findleaks:
Barry Warsawa873b032000-08-03 15:50:37 +0000130 try:
131 import gc
132 except ImportError:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000133 print 'No GC available, disabling findleaks.'
Neil Schemenauerd569f232000-09-22 15:29:28 +0000134 findleaks = 0
Barry Warsawa873b032000-08-03 15:50:37 +0000135 else:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000136 # Uncomment the line below to report garbage that is not
137 # freeable by reference counting alone. By default only
138 # garbage that is not collectable by the GC is reported.
139 #gc.set_debug(gc.DEBUG_SAVEALL)
Neil Schemenauerd569f232000-09-22 15:29:28 +0000140 found_garbage = []
Barry Warsawa873b032000-08-03 15:50:37 +0000141
Barry Warsawe11e3de1999-01-28 19:51:51 +0000142 if single:
143 from tempfile import gettempdir
144 filename = os.path.join(gettempdir(), 'pynexttest')
145 try:
146 fp = open(filename, 'r')
Eric S. Raymondfc170b12001-02-09 11:51:27 +0000147 next = fp.read().strip()
Barry Warsawe11e3de1999-01-28 19:51:51 +0000148 tests = [next]
149 fp.close()
150 except IOError:
151 pass
Guido van Rossuma4122201997-08-18 20:08:24 +0000152 for i in range(len(args)):
Guido van Rossum41360a41998-03-26 19:42:58 +0000153 # Strip trailing ".py" from arguments
154 if args[i][-3:] == '.py':
155 args[i] = args[i][:-3]
Guido van Rossum6c74fea1998-08-25 12:29:08 +0000156 stdtests = STDTESTS[:]
157 nottests = NOTTESTS[:]
Guido van Rossum152494a1996-12-20 03:12:20 +0000158 if exclude:
Guido van Rossum6c74fea1998-08-25 12:29:08 +0000159 for arg in args:
160 if arg in stdtests:
161 stdtests.remove(arg)
162 nottests[:0] = args
Guido van Rossum41360a41998-03-26 19:42:58 +0000163 args = []
Guido van Rossum747e1ca1998-08-24 13:48:36 +0000164 tests = tests or args or findtests(testdir, stdtests, nottests)
Barry Warsawe11e3de1999-01-28 19:51:51 +0000165 if single:
166 tests = tests[:1]
Skip Montanaroab1c7912000-06-30 16:39:27 +0000167 if randomize:
168 random.shuffle(tests)
Guido van Rossum41360a41998-03-26 19:42:58 +0000169 test_support.verbose = verbose # Tell tests to be moderately quiet
Barry Warsaw08fca522001-08-20 22:33:46 +0000170 test_support.use_resources = use_resources
Guido van Rossum5796d262000-04-21 21:35:06 +0000171 save_modules = sys.modules.keys()
Guido van Rossum152494a1996-12-20 03:12:20 +0000172 for test in tests:
Guido van Rossum41360a41998-03-26 19:42:58 +0000173 if not quiet:
174 print test
Trent Mickf29f47b2000-08-11 19:02:59 +0000175 ok = runtest(test, generate, verbose, quiet, testdir)
Guido van Rossum41360a41998-03-26 19:42:58 +0000176 if ok > 0:
177 good.append(test)
178 elif ok == 0:
179 bad.append(test)
180 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000181 skipped.append(test)
Neil Schemenauerd569f232000-09-22 15:29:28 +0000182 if findleaks:
183 gc.collect()
184 if gc.garbage:
Neil Schemenauer8a00abc2000-10-13 01:32:42 +0000185 print "Warning: test created", len(gc.garbage),
186 print "uncollectable object(s)."
187 # move the uncollectable objects somewhere so we don't see
188 # them again
Neil Schemenauerd569f232000-09-22 15:29:28 +0000189 found_garbage.extend(gc.garbage)
190 del gc.garbage[:]
Guido van Rossum5796d262000-04-21 21:35:06 +0000191 # Unload the newly imported modules (best effort finalization)
192 for module in sys.modules.keys():
Guido van Rossum51931142000-05-05 14:27:39 +0000193 if module not in save_modules and module.startswith("test."):
Guido van Rossum5796d262000-04-21 21:35:06 +0000194 test_support.unload(module)
Guido van Rossum152494a1996-12-20 03:12:20 +0000195 if good and not quiet:
Guido van Rossum41360a41998-03-26 19:42:58 +0000196 if not bad and not skipped and len(good) > 1:
197 print "All",
198 print count(len(good), "test"), "OK."
Tim Peters1a4d77b2000-12-30 22:21:22 +0000199 if verbose:
200 print "CAUTION: stdout isn't compared in verbose mode: a test"
201 print "that passes in verbose mode may fail without it."
Guido van Rossum152494a1996-12-20 03:12:20 +0000202 if bad:
Tim Petersa45da922001-08-12 03:45:50 +0000203 print count(len(bad), "test"), "failed:"
204 printlist(bad)
Guido van Rossum152494a1996-12-20 03:12:20 +0000205 if skipped and not quiet:
Tim Petersa45da922001-08-12 03:45:50 +0000206 print count(len(skipped), "test"), "skipped:"
207 printlist(skipped)
Barry Warsawe11e3de1999-01-28 19:51:51 +0000208
Tim Petersb5b7b782001-08-12 01:20:39 +0000209 e = _ExpectedSkips()
Tim Petersa2be2d62001-08-12 02:01:09 +0000210 plat = sys.platform
Tim Petersb5b7b782001-08-12 01:20:39 +0000211 if e.isvalid():
212 surprise = _Set(skipped) - e.getexpected()
Tim Petersb5b7b782001-08-12 01:20:39 +0000213 if surprise:
214 print count(len(surprise), "skip"), \
Tim Petersa45da922001-08-12 03:45:50 +0000215 "unexpected on", plat + ":"
216 printlist(surprise)
Tim Petersb5b7b782001-08-12 01:20:39 +0000217 else:
218 print "Those skips are all expected on", plat + "."
219 else:
220 print "Ask someone to teach regrtest.py about which tests are"
221 print "expected to get skipped on", plat + "."
222
Barry Warsawe11e3de1999-01-28 19:51:51 +0000223 if single:
224 alltests = findtests(testdir, stdtests, nottests)
225 for i in range(len(alltests)):
226 if tests[0] == alltests[i]:
227 if i == len(alltests) - 1:
228 os.unlink(filename)
229 else:
230 fp = open(filename, 'w')
231 fp.write(alltests[i+1] + '\n')
232 fp.close()
233 break
234 else:
235 os.unlink(filename)
236
Barry Warsaw08fca522001-08-20 22:33:46 +0000237 sys.exit(len(bad) > 0)
238
Guido van Rossum152494a1996-12-20 03:12:20 +0000239
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000240STDTESTS = [
Guido van Rossum152494a1996-12-20 03:12:20 +0000241 'test_grammar',
242 'test_opcodes',
243 'test_operations',
244 'test_builtin',
245 'test_exceptions',
246 'test_types',
247 ]
248
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000249NOTTESTS = [
Guido van Rossum152494a1996-12-20 03:12:20 +0000250 'test_support',
251 'test_b1',
252 'test_b2',
Jeremy Hylton62e2c7e2001-02-28 17:48:06 +0000253 'test_future1',
254 'test_future2',
Jeremy Hylton8471a352001-08-20 20:33:42 +0000255 'test_future3',
Guido van Rossum152494a1996-12-20 03:12:20 +0000256 ]
257
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000258def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
Guido van Rossum152494a1996-12-20 03:12:20 +0000259 """Return a list of all applicable test modules."""
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000260 if not testdir: testdir = findtestdir()
Guido van Rossum152494a1996-12-20 03:12:20 +0000261 names = os.listdir(testdir)
262 tests = []
263 for name in names:
Guido van Rossum41360a41998-03-26 19:42:58 +0000264 if name[:5] == "test_" and name[-3:] == ".py":
265 modname = name[:-3]
266 if modname not in stdtests and modname not in nottests:
267 tests.append(modname)
Guido van Rossum152494a1996-12-20 03:12:20 +0000268 tests.sort()
269 return stdtests + tests
270
Trent Mickf29f47b2000-08-11 19:02:59 +0000271def runtest(test, generate, verbose, quiet, testdir = None):
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000272 """Run a single test.
273 test -- the name of the test
274 generate -- if true, generate output, instead of running the test
275 and comparing it to a previously created output file
276 verbose -- if true, print more messages
Trent Mickf29f47b2000-08-11 19:02:59 +0000277 quiet -- if true, don't print 'skipped' messages (probably redundant)
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000278 testdir -- test directory
279 """
Guido van Rossum152494a1996-12-20 03:12:20 +0000280 test_support.unload(test)
Guido van Rossum6fd83b71998-08-01 17:04:08 +0000281 if not testdir: testdir = findtestdir()
Guido van Rossum152494a1996-12-20 03:12:20 +0000282 outputdir = os.path.join(testdir, "output")
283 outputfile = os.path.join(outputdir, test)
284 try:
Guido van Rossum41360a41998-03-26 19:42:58 +0000285 if generate:
Fred Drakee51fe8d2001-05-29 17:10:51 +0000286 cfp = StringIO.StringIO()
Guido van Rossum41360a41998-03-26 19:42:58 +0000287 elif verbose:
288 cfp = sys.stdout
289 else:
290 cfp = Compare(outputfile)
Guido van Rossum152494a1996-12-20 03:12:20 +0000291 except IOError:
Guido van Rossum41360a41998-03-26 19:42:58 +0000292 cfp = None
293 print "Warning: can't open", outputfile
Guido van Rossum152494a1996-12-20 03:12:20 +0000294 try:
Guido van Rossum41360a41998-03-26 19:42:58 +0000295 save_stdout = sys.stdout
296 try:
297 if cfp:
298 sys.stdout = cfp
299 print test # Output file starts with test name
Tim Petersd9742212001-05-22 18:28:25 +0000300 the_module = __import__(test, globals(), locals(), [])
301 # Most tests run to completion simply as a side-effect of
302 # being imported. For the benefit of tests that can't run
303 # that way (like test_threaded_import), explicitly invoke
304 # their test_main() function (if it exists).
305 indirect_test = getattr(the_module, "test_main", None)
306 if indirect_test is not None:
307 indirect_test()
Jeremy Hyltonfff9e202000-07-11 15:15:31 +0000308 if cfp and not (generate or verbose):
309 cfp.close()
Guido van Rossum41360a41998-03-26 19:42:58 +0000310 finally:
311 sys.stdout = save_stdout
Thomas Wouters3af826e2000-08-04 13:17:51 +0000312 except (ImportError, test_support.TestSkipped), msg:
Trent Mickf29f47b2000-08-11 19:02:59 +0000313 if not quiet:
314 print "test", test,
315 print "skipped -- ", msg
Guido van Rossum41360a41998-03-26 19:42:58 +0000316 return -1
Fred Drakefe5c22a2000-08-18 16:04:05 +0000317 except KeyboardInterrupt:
318 raise
Guido van Rossum152494a1996-12-20 03:12:20 +0000319 except test_support.TestFailed, msg:
Guido van Rossum41360a41998-03-26 19:42:58 +0000320 print "test", test, "failed --", msg
321 return 0
Guido van Rossum9e48b271997-07-16 01:56:13 +0000322 except:
Guido van Rossum41360a41998-03-26 19:42:58 +0000323 type, value = sys.exc_info()[:2]
Fred Drake27c4b392000-08-23 20:34:40 +0000324 print "test", test, "crashed --", str(type) + ":", value
Guido van Rossum41360a41998-03-26 19:42:58 +0000325 if verbose:
326 traceback.print_exc(file=sys.stdout)
327 return 0
Guido van Rossum152494a1996-12-20 03:12:20 +0000328 else:
Fred Drakee51fe8d2001-05-29 17:10:51 +0000329 if generate:
330 output = cfp.getvalue()
331 if output == test + "\n":
332 if os.path.exists(outputfile):
333 # Write it since it already exists (and the contents
334 # may have changed), but let the user know it isn't
335 # needed:
336 fp = open(outputfile, "w")
337 fp.write(output)
338 fp.close()
339 print "output file", outputfile, \
340 "is no longer needed; consider removing it"
341 # else:
342 # We don't need it, so don't create it.
343 else:
344 fp = open(outputfile, "w")
345 fp.write(output)
346 fp.close()
Guido van Rossum41360a41998-03-26 19:42:58 +0000347 return 1
Guido van Rossum152494a1996-12-20 03:12:20 +0000348
349def findtestdir():
350 if __name__ == '__main__':
Guido van Rossum41360a41998-03-26 19:42:58 +0000351 file = sys.argv[0]
Guido van Rossum152494a1996-12-20 03:12:20 +0000352 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000353 file = __file__
Guido van Rossum152494a1996-12-20 03:12:20 +0000354 testdir = os.path.dirname(file) or os.curdir
355 return testdir
356
357def count(n, word):
358 if n == 1:
Guido van Rossum41360a41998-03-26 19:42:58 +0000359 return "%d %s" % (n, word)
Guido van Rossum152494a1996-12-20 03:12:20 +0000360 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000361 return "%d %ss" % (n, word)
Guido van Rossum152494a1996-12-20 03:12:20 +0000362
Tim Petersa45da922001-08-12 03:45:50 +0000363def printlist(x, width=70, indent=4):
364 """Print the elements of a sequence to stdout.
365
366 Optional arg width (default 70) is the maximum line length.
367 Optional arg indent (default 4) is the number of blanks with which to
368 begin each line.
369 """
370
371 line = ' ' * indent
372 for one in map(str, x):
373 w = len(line) + len(one)
374 if line[-1:] == ' ':
375 pad = ''
376 else:
377 pad = ' '
378 w += 1
379 if w > width:
380 print line
381 line = ' ' * indent + one
382 else:
383 line += pad + one
384 if len(line) > indent:
385 print line
386
Guido van Rossum152494a1996-12-20 03:12:20 +0000387class Compare:
Guido van Rossum152494a1996-12-20 03:12:20 +0000388 def __init__(self, filename):
Fred Drakeae1bb172001-05-21 21:08:12 +0000389 if os.path.exists(filename):
390 self.fp = open(filename, 'r')
391 else:
392 self.fp = StringIO.StringIO(
393 os.path.basename(filename) + "\n")
Tim Peters1a4d77b2000-12-30 22:21:22 +0000394 self.stuffthatmatched = []
Guido van Rossum152494a1996-12-20 03:12:20 +0000395
396 def write(self, data):
Guido van Rossum41360a41998-03-26 19:42:58 +0000397 expected = self.fp.read(len(data))
Tim Peters1a4d77b2000-12-30 22:21:22 +0000398 if data == expected:
399 self.stuffthatmatched.append(expected)
400 else:
401 # This Compare instance is spoofing stdout, so we need to write
402 # to stderr instead.
403 from sys import stderr as e
404 print >> e, "The actual stdout doesn't match the expected stdout."
405 if self.stuffthatmatched:
406 print >> e, "This much did match (between asterisk lines):"
407 print >> e, "*" * 70
408 good = "".join(self.stuffthatmatched)
409 e.write(good)
410 if not good.endswith("\n"):
411 e.write("\n")
412 print >> e, "*" * 70
413 print >> e, "Then ..."
414 else:
415 print >> e, "The first write to stdout clashed:"
416 # Note that the prompts are the same length in next two lines.
417 # This is so what we expected and what we got line up.
418 print >> e, "We expected (repr):", `expected`
419 print >> e, "But instead we got:", `data`
420 raise test_support.TestFailed('Writing: ' + `data`+
421 ', expected: ' + `expected`)
Guido van Rossum152494a1996-12-20 03:12:20 +0000422
Guido van Rossume87ed5f1998-04-23 13:33:21 +0000423 def writelines(self, listoflines):
424 map(self.write, listoflines)
425
Guido van Rossum75fce301997-07-17 14:51:37 +0000426 def flush(self):
Guido van Rossum41360a41998-03-26 19:42:58 +0000427 pass
Guido van Rossum75fce301997-07-17 14:51:37 +0000428
Guido van Rossum152494a1996-12-20 03:12:20 +0000429 def close(self):
Guido van Rossum41360a41998-03-26 19:42:58 +0000430 leftover = self.fp.read()
431 if leftover:
Tim Peters1a4d77b2000-12-30 22:21:22 +0000432 raise test_support.TestFailed('Tail of expected stdout unseen: ' +
433 `leftover`)
Guido van Rossum41360a41998-03-26 19:42:58 +0000434 self.fp.close()
Guido van Rossum152494a1996-12-20 03:12:20 +0000435
436 def isatty(self):
Guido van Rossum41360a41998-03-26 19:42:58 +0000437 return 0
Guido van Rossum152494a1996-12-20 03:12:20 +0000438
Tim Petersb5b7b782001-08-12 01:20:39 +0000439class _Set:
440 def __init__(self, seq=[]):
441 data = self.data = {}
442 for x in seq:
443 data[x] = 1
444
445 def __len__(self):
446 return len(self.data)
447
448 def __sub__(self, other):
449 "Return set of all elements in self not in other."
450 result = _Set()
451 data = result.data = self.data.copy()
452 for x in other.data:
453 if x in data:
454 del data[x]
455 return result
456
Jeremy Hylton39f77bc2001-08-12 21:53:08 +0000457 def __iter__(self):
458 return iter(self.data)
459
Tim Petersb5b7b782001-08-12 01:20:39 +0000460 def tolist(self, sorted=1):
461 "Return _Set elements as a list."
462 data = self.data.keys()
463 if sorted:
464 data.sort()
465 return data
466
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000467_expectations = {
468 'win32':
469 """
470 test_al
471 test_cd
472 test_cl
473 test_commands
474 test_crypt
475 test_dbm
476 test_dl
477 test_fcntl
478 test_fork1
479 test_gdbm
480 test_gl
481 test_grp
482 test_imgfile
483 test_largefile
484 test_linuxaudiodev
485 test_mhlib
486 test_nis
487 test_openpty
488 test_poll
489 test_pty
490 test_pwd
491 test_signal
Barry Warsaw08fca522001-08-20 22:33:46 +0000492 test_socket_ssl
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000493 test_socketserver
494 test_sunaudiodev
495 test_timing
496 """,
497 'linux2':
498 """
499 test_al
500 test_cd
501 test_cl
502 test_dl
503 test_gl
504 test_imgfile
505 test_largefile
506 test_nis
507 test_ntpath
Barry Warsaw08fca522001-08-20 22:33:46 +0000508 test_socket_ssl
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000509 test_socketserver
510 test_sunaudiodev
511 test_unicode_file
512 test_winreg
513 test_winsound
514 """,
Jack Jansen49a806e2001-08-28 14:49:00 +0000515 'mac':
Guido van Rossumaa782362001-09-02 03:58:41 +0000516 """
517 test_al
518 test_bsddb
519 test_cd
520 test_cl
521 test_commands
522 test_crypt
523 test_dbm
524 test_dl
525 test_fcntl
526 test_fork1
527 test_gl
528 test_grp
529 test_imgfile
530 test_largefile
531 test_linuxaudiodev
532 test_locale
533 test_mmap
534 test_nis
535 test_ntpath
536 test_openpty
537 test_poll
538 test_popen2
539 test_pty
540 test_pwd
541 test_signal
542 test_socket_ssl
543 test_socketserver
544 test_sunaudiodev
545 test_sundry
546 test_timing
547 test_unicode_file
548 test_winreg
549 test_winsound
550 """,
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000551}
552
Tim Petersb5b7b782001-08-12 01:20:39 +0000553class _ExpectedSkips:
554 def __init__(self):
555 self.valid = 0
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000556 if _expectations.has_key(sys.platform):
557 s = _expectations[sys.platform]
Tim Petersb5b7b782001-08-12 01:20:39 +0000558 self.expected = _Set(s.split())
Guido van Rossumf73e30c2001-08-12 02:22:19 +0000559 self.valid = 1
Tim Petersb5b7b782001-08-12 01:20:39 +0000560
561 def isvalid(self):
562 "Return true iff _ExpectedSkips knows about the current platform."
563 return self.valid
564
565 def getexpected(self):
566 """Return set of test names we expect to skip on current platform.
567
568 self.isvalid() must be true.
569 """
570
571 assert self.isvalid()
572 return self.expected
573
Guido van Rossum152494a1996-12-20 03:12:20 +0000574if __name__ == '__main__':
Barry Warsaw08fca522001-08-20 22:33:46 +0000575 main()