Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | """Regression test. |
| 4 | |
| 5 | This will find all modules whose name is "test_*" in the test |
| 6 | directory, and run them. Various command line options provide |
| 7 | additional facilities. |
| 8 | |
| 9 | Command line options: |
| 10 | |
Barry Warsaw | a873b03 | 2000-08-03 15:50:37 +0000 | [diff] [blame] | 11 | -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 Peters | c5000df | 2002-06-02 21:42:01 +0000 | [diff] [blame] | 17 | -f: fromfile -- read names of tests to run from a file (see below) |
Neil Schemenauer | 8a00abc | 2000-10-13 01:32:42 +0000 | [diff] [blame] | 18 | -l: findleaks -- if GC is available detect tests that leak memory |
Barry Warsaw | 08fca52 | 2001-08-20 22:33:46 +0000 | [diff] [blame] | 19 | -u: use -- specify which special resource intensive tests to run |
| 20 | -h: help -- print this text and exit |
Guido van Rossum | 9e9d4f8 | 2002-06-07 15:17:03 +0000 | [diff] [blame] | 21 | -t: threshold -- call gc.set_threshold(N) |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 22 | |
| 23 | If non-option arguments are present, they are names for tests to run, |
| 24 | unless -x is given, in which case they are names for tests not to run. |
| 25 | If no test names are given, all tests are run. |
Guido van Rossum | f58ed25 | 1997-03-07 21:04:33 +0000 | [diff] [blame] | 26 | |
Guido van Rossum | a412220 | 1997-08-18 20:08:24 +0000 | [diff] [blame] | 27 | -v is incompatible with -g and does not compare test output files. |
Barry Warsaw | e11e3de | 1999-01-28 19:51:51 +0000 | [diff] [blame] | 28 | |
Guido van Rossum | 9e9d4f8 | 2002-06-07 15:17:03 +0000 | [diff] [blame] | 29 | -s means to run only a single test and exit. This is useful when |
| 30 | doing memory analysis on the Python interpreter (which tend to consume |
| 31 | too many resources to run the full regression test non-stop). The |
| 32 | file /tmp/pynexttest is read to find the next test to run. If this |
| 33 | file is missing, the first test_*.py file in testdir or on the command |
| 34 | line is used. (actually tempfile.gettempdir() is used instead of |
| 35 | /tmp). |
Barry Warsaw | e11e3de | 1999-01-28 19:51:51 +0000 | [diff] [blame] | 36 | |
Guido van Rossum | 9e9d4f8 | 2002-06-07 15:17:03 +0000 | [diff] [blame] | 37 | -f reads the names of tests from the file given as f's argument, one |
| 38 | or more test names per line. Whitespace is ignored. Blank lines and |
| 39 | lines beginning with '#' are ignored. This is especially useful for |
| 40 | whittling down failures involving interactions among tests. |
Tim Peters | c5000df | 2002-06-02 21:42:01 +0000 | [diff] [blame] | 41 | |
Guido van Rossum | 9e9d4f8 | 2002-06-07 15:17:03 +0000 | [diff] [blame] | 42 | -u is used to specify which special resource intensive tests to run, |
| 43 | such as those requiring large file support or network connectivity. |
| 44 | The argument is a comma-separated list of words indicating the |
| 45 | resources to test. Currently only the following are defined: |
Barry Warsaw | 08fca52 | 2001-08-20 22:33:46 +0000 | [diff] [blame] | 46 | |
Fred Drake | 3a15dac | 2002-04-11 16:39:16 +0000 | [diff] [blame] | 47 | all - Enable all special resources. |
| 48 | |
Andrew M. Kuchling | 2158df0 | 2001-10-22 15:26:09 +0000 | [diff] [blame] | 49 | curses - Tests that use curses and will modify the terminal's |
| 50 | state and output modes. |
Tim Peters | 1633a2e | 2001-10-30 05:56:40 +0000 | [diff] [blame] | 51 | |
Guido van Rossum | 9e9d4f8 | 2002-06-07 15:17:03 +0000 | [diff] [blame] | 52 | largefile - It is okay to run some test that may create huge |
| 53 | files. These tests can take a long time and may |
| 54 | consume >2GB of disk space temporarily. |
Barry Warsaw | 08fca52 | 2001-08-20 22:33:46 +0000 | [diff] [blame] | 55 | |
Guido van Rossum | 9e9d4f8 | 2002-06-07 15:17:03 +0000 | [diff] [blame] | 56 | network - It is okay to run tests that use external network |
| 57 | resource, e.g. testing SSL support for sockets. |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 58 | |
| 59 | bsddb - It is okay to run the bsddb testsuite, which takes |
| 60 | a long time to complete. |
Fred Drake | 4dd0f7e | 2002-11-26 21:44:56 +0000 | [diff] [blame] | 61 | |
| 62 | To enable all resources except one, use '-uall,-<resource>'. For |
| 63 | example, to run all the tests except for the bsddb tests, give the |
| 64 | option '-uall,-bsddb'. |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 65 | """ |
| 66 | |
| 67 | import sys |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 68 | import os |
| 69 | import getopt |
Guido van Rossum | 9e48b27 | 1997-07-16 01:56:13 +0000 | [diff] [blame] | 70 | import traceback |
Skip Montanaro | ab1c791 | 2000-06-30 16:39:27 +0000 | [diff] [blame] | 71 | import random |
Fred Drake | ae1bb17 | 2001-05-21 21:08:12 +0000 | [diff] [blame] | 72 | import StringIO |
Guido van Rossum | dc15c27 | 2002-08-12 21:55:51 +0000 | [diff] [blame] | 73 | import warnings |
Tim Peters | 7c7efe9 | 2002-08-23 17:55:54 +0000 | [diff] [blame] | 74 | from sets import Set |
Guido van Rossum | dc15c27 | 2002-08-12 21:55:51 +0000 | [diff] [blame] | 75 | |
| 76 | # I see no other way to suppress these warnings; |
| 77 | # putting them in test_grammar.py has no effect: |
Guido van Rossum | 88b1def | 2002-08-14 17:54:48 +0000 | [diff] [blame] | 78 | warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning, |
Guido van Rossum | dc15c27 | 2002-08-12 21:55:51 +0000 | [diff] [blame] | 79 | ".*test.test_grammar$") |
Guido van Rossum | c34c4fc | 2002-09-19 00:42:16 +0000 | [diff] [blame] | 80 | if sys.maxint > 0x7fffffff: |
| 81 | # Also suppress them in <string>, because for 64-bit platforms, |
| 82 | # that's where test_grammar.py hides them. |
| 83 | warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning, |
| 84 | "<string>") |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 85 | |
Guido van Rossum | bb48465 | 2002-12-02 09:56:21 +0000 | [diff] [blame] | 86 | # MacOSX (a.k.a. Darwin) has a default stack size that is too small |
| 87 | # for deeply recursive regular expressions. We see this as crashes in |
| 88 | # the Python test suite when running test_re.py and test_sre.py. The |
| 89 | # fix is to set the stack limit to 2048. |
| 90 | # This approach may also be useful for other Unixy platforms that |
| 91 | # suffer from small default stack limits. |
| 92 | if sys.platform == 'darwin': |
| 93 | try: |
| 94 | import resource |
| 95 | except ImportError: |
| 96 | pass |
| 97 | else: |
| 98 | soft, hard = resource.getrlimit(resource.RLIMIT_STACK) |
| 99 | newsoft = min(hard, max(soft, 1024*2048)) |
| 100 | resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard)) |
| 101 | |
Barry Warsaw | 04f357c | 2002-07-23 19:04:11 +0000 | [diff] [blame] | 102 | from test import test_support |
Fred Drake | 3a15dac | 2002-04-11 16:39:16 +0000 | [diff] [blame] | 103 | |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 104 | RESOURCE_NAMES = ('curses', 'largefile', 'network', 'bsddb') |
Fred Drake | 3a15dac | 2002-04-11 16:39:16 +0000 | [diff] [blame] | 105 | |
| 106 | |
Barry Warsaw | 08fca52 | 2001-08-20 22:33:46 +0000 | [diff] [blame] | 107 | def usage(code, msg=''): |
| 108 | print __doc__ |
| 109 | if msg: print msg |
| 110 | sys.exit(code) |
| 111 | |
| 112 | |
Skip Montanaro | ab1c791 | 2000-06-30 16:39:27 +0000 | [diff] [blame] | 113 | def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0, |
Tim Peters | c5000df | 2002-06-02 21:42:01 +0000 | [diff] [blame] | 114 | exclude=0, single=0, randomize=0, fromfile=None, findleaks=0, |
Barry Warsaw | 08fca52 | 2001-08-20 22:33:46 +0000 | [diff] [blame] | 115 | use_resources=None): |
Guido van Rossum | 6fd83b7 | 1998-08-01 17:04:08 +0000 | [diff] [blame] | 116 | """Execute a test suite. |
| 117 | |
Thomas Wouters | 7e47402 | 2000-07-16 12:04:32 +0000 | [diff] [blame] | 118 | This also parses command-line options and modifies its behavior |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 119 | accordingly. |
Guido van Rossum | 6fd83b7 | 1998-08-01 17:04:08 +0000 | [diff] [blame] | 120 | |
| 121 | tests -- a list of strings containing test names (optional) |
| 122 | testdir -- the directory in which to look for tests (optional) |
| 123 | |
| 124 | Users other than the Python test suite will certainly want to |
| 125 | specify testdir; if it's omitted, the directory containing the |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 126 | Python test suite is searched for. |
Guido van Rossum | 6fd83b7 | 1998-08-01 17:04:08 +0000 | [diff] [blame] | 127 | |
| 128 | If the tests argument is omitted, the tests listed on the |
| 129 | command-line will be used. If that's empty, too, then all *.py |
| 130 | files beginning with test_ will be used. |
Skip Montanaro | ab1c791 | 2000-06-30 16:39:27 +0000 | [diff] [blame] | 131 | |
Guido van Rossum | 9e9d4f8 | 2002-06-07 15:17:03 +0000 | [diff] [blame] | 132 | The other default arguments (verbose, quiet, generate, exclude, |
| 133 | single, randomize, findleaks, and use_resources) allow programmers |
| 134 | calling main() directly to set the values that would normally be |
| 135 | set by flags on the command line. |
Barry Warsaw | a873b03 | 2000-08-03 15:50:37 +0000 | [diff] [blame] | 136 | |
Guido van Rossum | 6fd83b7 | 1998-08-01 17:04:08 +0000 | [diff] [blame] | 137 | """ |
Fred Drake | 004d5e6 | 2000-10-23 17:22:08 +0000 | [diff] [blame] | 138 | |
Tim Peters | 8dee809 | 2001-09-25 20:05:11 +0000 | [diff] [blame] | 139 | test_support.record_original_stdout(sys.stdout) |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 140 | try: |
Guido van Rossum | 9e9d4f8 | 2002-06-07 15:17:03 +0000 | [diff] [blame] | 141 | opts, args = getopt.getopt(sys.argv[1:], 'hvgqxsrf:lu:t:', |
Barry Warsaw | 08fca52 | 2001-08-20 22:33:46 +0000 | [diff] [blame] | 142 | ['help', 'verbose', 'quiet', 'generate', |
Tim Peters | c5000df | 2002-06-02 21:42:01 +0000 | [diff] [blame] | 143 | 'exclude', 'single', 'random', 'fromfile', |
Guido van Rossum | 9e9d4f8 | 2002-06-07 15:17:03 +0000 | [diff] [blame] | 144 | 'findleaks', 'use=', 'threshold=']) |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 145 | except getopt.error, msg: |
Barry Warsaw | 08fca52 | 2001-08-20 22:33:46 +0000 | [diff] [blame] | 146 | usage(2, msg) |
| 147 | |
| 148 | # Defaults |
| 149 | if use_resources is None: |
| 150 | use_resources = [] |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 151 | for o, a in opts: |
Barry Warsaw | 08fca52 | 2001-08-20 22:33:46 +0000 | [diff] [blame] | 152 | if o in ('-h', '--help'): |
| 153 | usage(0) |
| 154 | elif o in ('-v', '--verbose'): |
| 155 | verbose += 1 |
| 156 | elif o in ('-q', '--quiet'): |
| 157 | quiet = 1; |
| 158 | verbose = 0 |
| 159 | elif o in ('-g', '--generate'): |
| 160 | generate = 1 |
| 161 | elif o in ('-x', '--exclude'): |
| 162 | exclude = 1 |
| 163 | elif o in ('-s', '--single'): |
| 164 | single = 1 |
| 165 | elif o in ('-r', '--randomize'): |
| 166 | randomize = 1 |
Tim Peters | c5000df | 2002-06-02 21:42:01 +0000 | [diff] [blame] | 167 | elif o in ('-f', '--fromfile'): |
| 168 | fromfile = a |
Barry Warsaw | 08fca52 | 2001-08-20 22:33:46 +0000 | [diff] [blame] | 169 | elif o in ('-l', '--findleaks'): |
| 170 | findleaks = 1 |
Guido van Rossum | 9e9d4f8 | 2002-06-07 15:17:03 +0000 | [diff] [blame] | 171 | elif o in ('-t', '--threshold'): |
| 172 | import gc |
| 173 | gc.set_threshold(int(a)) |
Barry Warsaw | 08fca52 | 2001-08-20 22:33:46 +0000 | [diff] [blame] | 174 | elif o in ('-u', '--use'): |
Guido van Rossum | fe3f696 | 2001-09-06 16:09:41 +0000 | [diff] [blame] | 175 | u = [x.lower() for x in a.split(',')] |
| 176 | for r in u: |
Fred Drake | 3a15dac | 2002-04-11 16:39:16 +0000 | [diff] [blame] | 177 | if r == 'all': |
Fred Drake | 4dd0f7e | 2002-11-26 21:44:56 +0000 | [diff] [blame] | 178 | use_resources[:] = RESOURCE_NAMES |
| 179 | continue |
| 180 | remove = False |
| 181 | if r[0] == '-': |
| 182 | remove = True |
| 183 | r = r[1:] |
Fred Drake | 3a15dac | 2002-04-11 16:39:16 +0000 | [diff] [blame] | 184 | if r not in RESOURCE_NAMES: |
| 185 | usage(1, 'Invalid -u/--use option: ' + a) |
Fred Drake | 4dd0f7e | 2002-11-26 21:44:56 +0000 | [diff] [blame] | 186 | if remove: |
| 187 | if r in use_resources: |
| 188 | use_resources.remove(r) |
| 189 | elif r not in use_resources: |
Andrew MacIntyre | e41abab | 2002-04-30 12:11:04 +0000 | [diff] [blame] | 190 | use_resources.append(r) |
Guido van Rossum | a412220 | 1997-08-18 20:08:24 +0000 | [diff] [blame] | 191 | if generate and verbose: |
Barry Warsaw | 08fca52 | 2001-08-20 22:33:46 +0000 | [diff] [blame] | 192 | usage(2, "-g and -v don't go together!") |
Tim Peters | c5000df | 2002-06-02 21:42:01 +0000 | [diff] [blame] | 193 | if single and fromfile: |
| 194 | usage(2, "-s and -f don't go together!") |
Barry Warsaw | 08fca52 | 2001-08-20 22:33:46 +0000 | [diff] [blame] | 195 | |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 196 | good = [] |
| 197 | bad = [] |
| 198 | skipped = [] |
Barry Warsaw | e11e3de | 1999-01-28 19:51:51 +0000 | [diff] [blame] | 199 | |
Neil Schemenauer | d569f23 | 2000-09-22 15:29:28 +0000 | [diff] [blame] | 200 | if findleaks: |
Barry Warsaw | a873b03 | 2000-08-03 15:50:37 +0000 | [diff] [blame] | 201 | try: |
| 202 | import gc |
| 203 | except ImportError: |
Neil Schemenauer | 8a00abc | 2000-10-13 01:32:42 +0000 | [diff] [blame] | 204 | print 'No GC available, disabling findleaks.' |
Neil Schemenauer | d569f23 | 2000-09-22 15:29:28 +0000 | [diff] [blame] | 205 | findleaks = 0 |
Barry Warsaw | a873b03 | 2000-08-03 15:50:37 +0000 | [diff] [blame] | 206 | else: |
Neil Schemenauer | 8a00abc | 2000-10-13 01:32:42 +0000 | [diff] [blame] | 207 | # Uncomment the line below to report garbage that is not |
| 208 | # freeable by reference counting alone. By default only |
| 209 | # garbage that is not collectable by the GC is reported. |
| 210 | #gc.set_debug(gc.DEBUG_SAVEALL) |
Neil Schemenauer | d569f23 | 2000-09-22 15:29:28 +0000 | [diff] [blame] | 211 | found_garbage = [] |
Barry Warsaw | a873b03 | 2000-08-03 15:50:37 +0000 | [diff] [blame] | 212 | |
Barry Warsaw | e11e3de | 1999-01-28 19:51:51 +0000 | [diff] [blame] | 213 | if single: |
| 214 | from tempfile import gettempdir |
| 215 | filename = os.path.join(gettempdir(), 'pynexttest') |
| 216 | try: |
| 217 | fp = open(filename, 'r') |
Eric S. Raymond | fc170b1 | 2001-02-09 11:51:27 +0000 | [diff] [blame] | 218 | next = fp.read().strip() |
Barry Warsaw | e11e3de | 1999-01-28 19:51:51 +0000 | [diff] [blame] | 219 | tests = [next] |
| 220 | fp.close() |
| 221 | except IOError: |
| 222 | pass |
Tim Peters | c5000df | 2002-06-02 21:42:01 +0000 | [diff] [blame] | 223 | |
| 224 | if fromfile: |
| 225 | tests = [] |
| 226 | fp = open(fromfile) |
| 227 | for line in fp: |
| 228 | guts = line.split() # assuming no test has whitespace in its name |
| 229 | if guts and not guts[0].startswith('#'): |
| 230 | tests.extend(guts) |
| 231 | fp.close() |
| 232 | |
| 233 | # Strip .py extensions. |
| 234 | if args: |
| 235 | args = map(removepy, args) |
| 236 | if tests: |
| 237 | tests = map(removepy, tests) |
| 238 | |
Guido van Rossum | 6c74fea | 1998-08-25 12:29:08 +0000 | [diff] [blame] | 239 | stdtests = STDTESTS[:] |
| 240 | nottests = NOTTESTS[:] |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 241 | if exclude: |
Guido van Rossum | 6c74fea | 1998-08-25 12:29:08 +0000 | [diff] [blame] | 242 | for arg in args: |
| 243 | if arg in stdtests: |
| 244 | stdtests.remove(arg) |
| 245 | nottests[:0] = args |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 246 | args = [] |
Guido van Rossum | 747e1ca | 1998-08-24 13:48:36 +0000 | [diff] [blame] | 247 | tests = tests or args or findtests(testdir, stdtests, nottests) |
Barry Warsaw | e11e3de | 1999-01-28 19:51:51 +0000 | [diff] [blame] | 248 | if single: |
| 249 | tests = tests[:1] |
Skip Montanaro | ab1c791 | 2000-06-30 16:39:27 +0000 | [diff] [blame] | 250 | if randomize: |
| 251 | random.shuffle(tests) |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 252 | test_support.verbose = verbose # Tell tests to be moderately quiet |
Barry Warsaw | 08fca52 | 2001-08-20 22:33:46 +0000 | [diff] [blame] | 253 | test_support.use_resources = use_resources |
Guido van Rossum | 5796d26 | 2000-04-21 21:35:06 +0000 | [diff] [blame] | 254 | save_modules = sys.modules.keys() |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 255 | for test in tests: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 256 | if not quiet: |
| 257 | print test |
Guido van Rossum | 3cda93e | 2002-09-13 21:28:03 +0000 | [diff] [blame] | 258 | sys.stdout.flush() |
Trent Mick | f29f47b | 2000-08-11 19:02:59 +0000 | [diff] [blame] | 259 | ok = runtest(test, generate, verbose, quiet, testdir) |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 260 | if ok > 0: |
| 261 | good.append(test) |
| 262 | elif ok == 0: |
| 263 | bad.append(test) |
| 264 | else: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 265 | skipped.append(test) |
Neil Schemenauer | d569f23 | 2000-09-22 15:29:28 +0000 | [diff] [blame] | 266 | if findleaks: |
| 267 | gc.collect() |
| 268 | if gc.garbage: |
Neil Schemenauer | 8a00abc | 2000-10-13 01:32:42 +0000 | [diff] [blame] | 269 | print "Warning: test created", len(gc.garbage), |
| 270 | print "uncollectable object(s)." |
| 271 | # move the uncollectable objects somewhere so we don't see |
| 272 | # them again |
Neil Schemenauer | d569f23 | 2000-09-22 15:29:28 +0000 | [diff] [blame] | 273 | found_garbage.extend(gc.garbage) |
| 274 | del gc.garbage[:] |
Guido van Rossum | 5796d26 | 2000-04-21 21:35:06 +0000 | [diff] [blame] | 275 | # Unload the newly imported modules (best effort finalization) |
| 276 | for module in sys.modules.keys(): |
Guido van Rossum | 5193114 | 2000-05-05 14:27:39 +0000 | [diff] [blame] | 277 | if module not in save_modules and module.startswith("test."): |
Guido van Rossum | 5796d26 | 2000-04-21 21:35:06 +0000 | [diff] [blame] | 278 | test_support.unload(module) |
Jeremy Hylton | 7a1ea0e | 2001-10-17 13:45:28 +0000 | [diff] [blame] | 279 | |
| 280 | # The lists won't be sorted if running with -r |
| 281 | good.sort() |
| 282 | bad.sort() |
| 283 | skipped.sort() |
Tim Peters | e0c446b | 2001-10-18 21:57:37 +0000 | [diff] [blame] | 284 | |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 285 | if good and not quiet: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 286 | if not bad and not skipped and len(good) > 1: |
| 287 | print "All", |
| 288 | print count(len(good), "test"), "OK." |
Tim Peters | 1a4d77b | 2000-12-30 22:21:22 +0000 | [diff] [blame] | 289 | if verbose: |
Barry Warsaw | 408b6d3 | 2002-07-30 23:27:12 +0000 | [diff] [blame] | 290 | print "CAUTION: stdout isn't compared in verbose mode:" |
| 291 | print "a test that passes in verbose mode may fail without it." |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 292 | if bad: |
Tim Peters | a45da92 | 2001-08-12 03:45:50 +0000 | [diff] [blame] | 293 | print count(len(bad), "test"), "failed:" |
| 294 | printlist(bad) |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 295 | if skipped and not quiet: |
Tim Peters | a45da92 | 2001-08-12 03:45:50 +0000 | [diff] [blame] | 296 | print count(len(skipped), "test"), "skipped:" |
| 297 | printlist(skipped) |
Barry Warsaw | e11e3de | 1999-01-28 19:51:51 +0000 | [diff] [blame] | 298 | |
Tim Peters | b5b7b78 | 2001-08-12 01:20:39 +0000 | [diff] [blame] | 299 | e = _ExpectedSkips() |
Tim Peters | a2be2d6 | 2001-08-12 02:01:09 +0000 | [diff] [blame] | 300 | plat = sys.platform |
Tim Peters | b5b7b78 | 2001-08-12 01:20:39 +0000 | [diff] [blame] | 301 | if e.isvalid(): |
Tim Peters | 7c7efe9 | 2002-08-23 17:55:54 +0000 | [diff] [blame] | 302 | surprise = Set(skipped) - e.getexpected() |
Tim Peters | b5b7b78 | 2001-08-12 01:20:39 +0000 | [diff] [blame] | 303 | if surprise: |
| 304 | print count(len(surprise), "skip"), \ |
Tim Peters | a45da92 | 2001-08-12 03:45:50 +0000 | [diff] [blame] | 305 | "unexpected on", plat + ":" |
| 306 | printlist(surprise) |
Tim Peters | b5b7b78 | 2001-08-12 01:20:39 +0000 | [diff] [blame] | 307 | else: |
| 308 | print "Those skips are all expected on", plat + "." |
| 309 | else: |
| 310 | print "Ask someone to teach regrtest.py about which tests are" |
| 311 | print "expected to get skipped on", plat + "." |
| 312 | |
Barry Warsaw | e11e3de | 1999-01-28 19:51:51 +0000 | [diff] [blame] | 313 | if single: |
| 314 | alltests = findtests(testdir, stdtests, nottests) |
| 315 | for i in range(len(alltests)): |
| 316 | if tests[0] == alltests[i]: |
| 317 | if i == len(alltests) - 1: |
| 318 | os.unlink(filename) |
| 319 | else: |
| 320 | fp = open(filename, 'w') |
| 321 | fp.write(alltests[i+1] + '\n') |
| 322 | fp.close() |
| 323 | break |
| 324 | else: |
| 325 | os.unlink(filename) |
| 326 | |
Barry Warsaw | 08fca52 | 2001-08-20 22:33:46 +0000 | [diff] [blame] | 327 | sys.exit(len(bad) > 0) |
| 328 | |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 329 | |
Guido van Rossum | 6fd83b7 | 1998-08-01 17:04:08 +0000 | [diff] [blame] | 330 | STDTESTS = [ |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 331 | 'test_grammar', |
| 332 | 'test_opcodes', |
| 333 | 'test_operations', |
| 334 | 'test_builtin', |
| 335 | 'test_exceptions', |
| 336 | 'test_types', |
| 337 | ] |
| 338 | |
Guido van Rossum | 6fd83b7 | 1998-08-01 17:04:08 +0000 | [diff] [blame] | 339 | NOTTESTS = [ |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 340 | 'test_support', |
| 341 | 'test_b1', |
| 342 | 'test_b2', |
Jeremy Hylton | 62e2c7e | 2001-02-28 17:48:06 +0000 | [diff] [blame] | 343 | 'test_future1', |
| 344 | 'test_future2', |
Jeremy Hylton | 8471a35 | 2001-08-20 20:33:42 +0000 | [diff] [blame] | 345 | 'test_future3', |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 346 | ] |
| 347 | |
Guido van Rossum | 6fd83b7 | 1998-08-01 17:04:08 +0000 | [diff] [blame] | 348 | def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS): |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 349 | """Return a list of all applicable test modules.""" |
Guido van Rossum | 6fd83b7 | 1998-08-01 17:04:08 +0000 | [diff] [blame] | 350 | if not testdir: testdir = findtestdir() |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 351 | names = os.listdir(testdir) |
| 352 | tests = [] |
| 353 | for name in names: |
Guido van Rossum | e2ae77b | 2001-10-24 20:42:55 +0000 | [diff] [blame] | 354 | if name[:5] == "test_" and name[-3:] == os.extsep+"py": |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 355 | modname = name[:-3] |
| 356 | if modname not in stdtests and modname not in nottests: |
| 357 | tests.append(modname) |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 358 | tests.sort() |
| 359 | return stdtests + tests |
| 360 | |
Trent Mick | f29f47b | 2000-08-11 19:02:59 +0000 | [diff] [blame] | 361 | def runtest(test, generate, verbose, quiet, testdir = None): |
Guido van Rossum | 6fd83b7 | 1998-08-01 17:04:08 +0000 | [diff] [blame] | 362 | """Run a single test. |
| 363 | test -- the name of the test |
| 364 | generate -- if true, generate output, instead of running the test |
| 365 | and comparing it to a previously created output file |
| 366 | verbose -- if true, print more messages |
Trent Mick | f29f47b | 2000-08-11 19:02:59 +0000 | [diff] [blame] | 367 | quiet -- if true, don't print 'skipped' messages (probably redundant) |
Guido van Rossum | 6fd83b7 | 1998-08-01 17:04:08 +0000 | [diff] [blame] | 368 | testdir -- test directory |
| 369 | """ |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 370 | test_support.unload(test) |
Guido van Rossum | 6fd83b7 | 1998-08-01 17:04:08 +0000 | [diff] [blame] | 371 | if not testdir: testdir = findtestdir() |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 372 | outputdir = os.path.join(testdir, "output") |
| 373 | outputfile = os.path.join(outputdir, test) |
Tim Peters | 9390cc1 | 2001-09-28 20:14:46 +0000 | [diff] [blame] | 374 | if verbose: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 375 | cfp = None |
Guido van Rossum | 0fcca4e | 2001-09-21 20:31:52 +0000 | [diff] [blame] | 376 | else: |
Fred Drake | 88a5685 | 2001-09-28 20:16:30 +0000 | [diff] [blame] | 377 | cfp = StringIO.StringIO() |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 378 | try: |
Tim Peters | 342ca75 | 2001-09-25 19:13:20 +0000 | [diff] [blame] | 379 | save_stdout = sys.stdout |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 380 | try: |
| 381 | if cfp: |
| 382 | sys.stdout = cfp |
| 383 | print test # Output file starts with test name |
Barry Warsaw | 408b6d3 | 2002-07-30 23:27:12 +0000 | [diff] [blame] | 384 | if test.startswith('test.'): |
| 385 | abstest = test |
| 386 | else: |
| 387 | # Always import it from the test package |
| 388 | abstest = 'test.' + test |
| 389 | the_package = __import__(abstest, globals(), locals(), []) |
| 390 | the_module = getattr(the_package, test) |
Tim Peters | d974221 | 2001-05-22 18:28:25 +0000 | [diff] [blame] | 391 | # Most tests run to completion simply as a side-effect of |
| 392 | # being imported. For the benefit of tests that can't run |
| 393 | # that way (like test_threaded_import), explicitly invoke |
| 394 | # their test_main() function (if it exists). |
| 395 | indirect_test = getattr(the_module, "test_main", None) |
| 396 | if indirect_test is not None: |
| 397 | indirect_test() |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 398 | finally: |
Tim Peters | 342ca75 | 2001-09-25 19:13:20 +0000 | [diff] [blame] | 399 | sys.stdout = save_stdout |
Thomas Wouters | 3af826e | 2000-08-04 13:17:51 +0000 | [diff] [blame] | 400 | except (ImportError, test_support.TestSkipped), msg: |
Trent Mick | f29f47b | 2000-08-11 19:02:59 +0000 | [diff] [blame] | 401 | if not quiet: |
Fred Drake | de4742b | 2002-10-17 20:36:08 +0000 | [diff] [blame] | 402 | print test, "skipped --", msg |
Guido van Rossum | 3cda93e | 2002-09-13 21:28:03 +0000 | [diff] [blame] | 403 | sys.stdout.flush() |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 404 | return -1 |
Fred Drake | fe5c22a | 2000-08-18 16:04:05 +0000 | [diff] [blame] | 405 | except KeyboardInterrupt: |
| 406 | raise |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 407 | except test_support.TestFailed, msg: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 408 | print "test", test, "failed --", msg |
Guido van Rossum | 3cda93e | 2002-09-13 21:28:03 +0000 | [diff] [blame] | 409 | sys.stdout.flush() |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 410 | return 0 |
Guido van Rossum | 9e48b27 | 1997-07-16 01:56:13 +0000 | [diff] [blame] | 411 | except: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 412 | type, value = sys.exc_info()[:2] |
Fred Drake | 27c4b39 | 2000-08-23 20:34:40 +0000 | [diff] [blame] | 413 | print "test", test, "crashed --", str(type) + ":", value |
Guido van Rossum | 3cda93e | 2002-09-13 21:28:03 +0000 | [diff] [blame] | 414 | sys.stdout.flush() |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 415 | if verbose: |
| 416 | traceback.print_exc(file=sys.stdout) |
Guido van Rossum | 3cda93e | 2002-09-13 21:28:03 +0000 | [diff] [blame] | 417 | sys.stdout.flush() |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 418 | return 0 |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 419 | else: |
Guido van Rossum | 0fcca4e | 2001-09-21 20:31:52 +0000 | [diff] [blame] | 420 | if not cfp: |
| 421 | return 1 |
| 422 | output = cfp.getvalue() |
Fred Drake | e51fe8d | 2001-05-29 17:10:51 +0000 | [diff] [blame] | 423 | if generate: |
Fred Drake | e51fe8d | 2001-05-29 17:10:51 +0000 | [diff] [blame] | 424 | if output == test + "\n": |
| 425 | if os.path.exists(outputfile): |
| 426 | # Write it since it already exists (and the contents |
| 427 | # may have changed), but let the user know it isn't |
| 428 | # needed: |
Fred Drake | e51fe8d | 2001-05-29 17:10:51 +0000 | [diff] [blame] | 429 | print "output file", outputfile, \ |
| 430 | "is no longer needed; consider removing it" |
Guido van Rossum | 0fcca4e | 2001-09-21 20:31:52 +0000 | [diff] [blame] | 431 | else: |
| 432 | # We don't need it, so don't create it. |
| 433 | return 1 |
| 434 | fp = open(outputfile, "w") |
| 435 | fp.write(output) |
| 436 | fp.close() |
| 437 | return 1 |
| 438 | if os.path.exists(outputfile): |
| 439 | fp = open(outputfile, "r") |
| 440 | expected = fp.read() |
| 441 | fp.close() |
| 442 | else: |
| 443 | expected = test + "\n" |
| 444 | if output == expected: |
| 445 | return 1 |
| 446 | print "test", test, "produced unexpected output:" |
Guido van Rossum | 3cda93e | 2002-09-13 21:28:03 +0000 | [diff] [blame] | 447 | sys.stdout.flush() |
Guido van Rossum | 0fcca4e | 2001-09-21 20:31:52 +0000 | [diff] [blame] | 448 | reportdiff(expected, output) |
Guido van Rossum | 3cda93e | 2002-09-13 21:28:03 +0000 | [diff] [blame] | 449 | sys.stdout.flush() |
Guido van Rossum | 0fcca4e | 2001-09-21 20:31:52 +0000 | [diff] [blame] | 450 | return 0 |
| 451 | |
| 452 | def reportdiff(expected, output): |
Guido van Rossum | 0fcca4e | 2001-09-21 20:31:52 +0000 | [diff] [blame] | 453 | import difflib |
Tim Peters | c377b16 | 2001-09-22 05:31:03 +0000 | [diff] [blame] | 454 | print "*" * 70 |
| 455 | a = expected.splitlines(1) |
| 456 | b = output.splitlines(1) |
Guido van Rossum | cf69193 | 2001-09-21 21:06:22 +0000 | [diff] [blame] | 457 | sm = difflib.SequenceMatcher(a=a, b=b) |
| 458 | tuples = sm.get_opcodes() |
Tim Peters | c377b16 | 2001-09-22 05:31:03 +0000 | [diff] [blame] | 459 | |
Guido van Rossum | cf69193 | 2001-09-21 21:06:22 +0000 | [diff] [blame] | 460 | def pair(x0, x1): |
Tim Peters | c377b16 | 2001-09-22 05:31:03 +0000 | [diff] [blame] | 461 | # x0:x1 are 0-based slice indices; convert to 1-based line indices. |
Guido van Rossum | cf69193 | 2001-09-21 21:06:22 +0000 | [diff] [blame] | 462 | x0 += 1 |
| 463 | if x0 >= x1: |
Tim Peters | c377b16 | 2001-09-22 05:31:03 +0000 | [diff] [blame] | 464 | return "line " + str(x0) |
Guido van Rossum | cf69193 | 2001-09-21 21:06:22 +0000 | [diff] [blame] | 465 | else: |
Tim Peters | c377b16 | 2001-09-22 05:31:03 +0000 | [diff] [blame] | 466 | return "lines %d-%d" % (x0, x1) |
| 467 | |
Guido van Rossum | cf69193 | 2001-09-21 21:06:22 +0000 | [diff] [blame] | 468 | for op, a0, a1, b0, b1 in tuples: |
| 469 | if op == 'equal': |
| 470 | pass |
Tim Peters | c377b16 | 2001-09-22 05:31:03 +0000 | [diff] [blame] | 471 | |
Guido van Rossum | cf69193 | 2001-09-21 21:06:22 +0000 | [diff] [blame] | 472 | elif op == 'delete': |
Tim Peters | c377b16 | 2001-09-22 05:31:03 +0000 | [diff] [blame] | 473 | print "***", pair(a0, a1), "of expected output missing:" |
Guido van Rossum | cf69193 | 2001-09-21 21:06:22 +0000 | [diff] [blame] | 474 | for line in a[a0:a1]: |
Tim Peters | c377b16 | 2001-09-22 05:31:03 +0000 | [diff] [blame] | 475 | print "-", line, |
| 476 | |
Guido van Rossum | cf69193 | 2001-09-21 21:06:22 +0000 | [diff] [blame] | 477 | elif op == 'replace': |
Tim Peters | c377b16 | 2001-09-22 05:31:03 +0000 | [diff] [blame] | 478 | print "*** mismatch between", pair(a0, a1), "of expected", \ |
| 479 | "output and", pair(b0, b1), "of actual output:" |
| 480 | for line in difflib.ndiff(a[a0:a1], b[b0:b1]): |
| 481 | print line, |
| 482 | |
Guido van Rossum | cf69193 | 2001-09-21 21:06:22 +0000 | [diff] [blame] | 483 | elif op == 'insert': |
Tim Peters | c377b16 | 2001-09-22 05:31:03 +0000 | [diff] [blame] | 484 | print "***", pair(b0, b1), "of actual output doesn't appear", \ |
| 485 | "in expected output after line", str(a1)+":" |
Guido van Rossum | cf69193 | 2001-09-21 21:06:22 +0000 | [diff] [blame] | 486 | for line in b[b0:b1]: |
Tim Peters | c377b16 | 2001-09-22 05:31:03 +0000 | [diff] [blame] | 487 | print "+", line, |
| 488 | |
Guido van Rossum | cf69193 | 2001-09-21 21:06:22 +0000 | [diff] [blame] | 489 | else: |
| 490 | print "get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1) |
Tim Peters | c377b16 | 2001-09-22 05:31:03 +0000 | [diff] [blame] | 491 | |
Guido van Rossum | 0fcca4e | 2001-09-21 20:31:52 +0000 | [diff] [blame] | 492 | print "*" * 70 |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 493 | |
| 494 | def findtestdir(): |
| 495 | if __name__ == '__main__': |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 496 | file = sys.argv[0] |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 497 | else: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 498 | file = __file__ |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 499 | testdir = os.path.dirname(file) or os.curdir |
| 500 | return testdir |
| 501 | |
Tim Peters | c5000df | 2002-06-02 21:42:01 +0000 | [diff] [blame] | 502 | def removepy(name): |
| 503 | if name.endswith(os.extsep + "py"): |
| 504 | name = name[:-3] |
| 505 | return name |
| 506 | |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 507 | def count(n, word): |
| 508 | if n == 1: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 509 | return "%d %s" % (n, word) |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 510 | else: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 511 | return "%d %ss" % (n, word) |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 512 | |
Tim Peters | a45da92 | 2001-08-12 03:45:50 +0000 | [diff] [blame] | 513 | def printlist(x, width=70, indent=4): |
Tim Peters | 7c7efe9 | 2002-08-23 17:55:54 +0000 | [diff] [blame] | 514 | """Print the elements of iterable x to stdout. |
Tim Peters | a45da92 | 2001-08-12 03:45:50 +0000 | [diff] [blame] | 515 | |
| 516 | Optional arg width (default 70) is the maximum line length. |
| 517 | Optional arg indent (default 4) is the number of blanks with which to |
| 518 | begin each line. |
| 519 | """ |
| 520 | |
Tim Peters | ba78bc4 | 2002-07-04 19:45:06 +0000 | [diff] [blame] | 521 | from textwrap import fill |
| 522 | blanks = ' ' * indent |
| 523 | print fill(' '.join(map(str, x)), width, |
| 524 | initial_indent=blanks, subsequent_indent=blanks) |
Tim Peters | a45da92 | 2001-08-12 03:45:50 +0000 | [diff] [blame] | 525 | |
Tim Peters | de14a30 | 2002-04-01 05:04:46 +0000 | [diff] [blame] | 526 | # Map sys.platform to a string containing the basenames of tests |
| 527 | # expected to be skipped on that platform. |
Tim Peters | 2a182db | 2002-10-09 01:07:11 +0000 | [diff] [blame] | 528 | # |
| 529 | # Special cases: |
| 530 | # test_pep277 |
| 531 | # The _ExpectedSkips constructor adds this to the set of expected |
| 532 | # skips if not os.path.supports_unicode_filenames. |
Tim Peters | 1b445d3 | 2002-11-24 18:53:11 +0000 | [diff] [blame] | 533 | # test_normalization |
| 534 | # Whether a skip is expected here depends on whether a large test |
| 535 | # input file has been downloaded. test_normalization.skip_expected |
Tim Peters | 1babdfc | 2002-11-24 19:19:09 +0000 | [diff] [blame] | 536 | # controls that. |
Tim Peters | b4ee4eb | 2002-12-04 03:26:57 +0000 | [diff] [blame] | 537 | # test_socket_ssl |
| 538 | # Controlled by test_socket_ssl.skip_expected. Requires the network |
| 539 | # resource, and a socket module with ssl support. |
Tim Peters | de14a30 | 2002-04-01 05:04:46 +0000 | [diff] [blame] | 540 | |
Guido van Rossum | f73e30c | 2001-08-12 02:22:19 +0000 | [diff] [blame] | 541 | _expectations = { |
| 542 | 'win32': |
| 543 | """ |
| 544 | test_al |
Tim Peters | 78e35f9 | 2002-11-22 20:00:34 +0000 | [diff] [blame] | 545 | test_bsddb3 |
Guido van Rossum | f73e30c | 2001-08-12 02:22:19 +0000 | [diff] [blame] | 546 | test_cd |
| 547 | test_cl |
| 548 | test_commands |
| 549 | test_crypt |
Tim Peters | d703057 | 2001-10-22 22:06:08 +0000 | [diff] [blame] | 550 | test_curses |
Guido van Rossum | f73e30c | 2001-08-12 02:22:19 +0000 | [diff] [blame] | 551 | test_dbm |
| 552 | test_dl |
Tim Peters | deb121a | 2002-04-11 19:52:58 +0000 | [diff] [blame] | 553 | test_email_codecs |
Guido van Rossum | f73e30c | 2001-08-12 02:22:19 +0000 | [diff] [blame] | 554 | test_fcntl |
| 555 | test_fork1 |
| 556 | test_gdbm |
| 557 | test_gl |
| 558 | test_grp |
| 559 | test_imgfile |
| 560 | test_largefile |
| 561 | test_linuxaudiodev |
| 562 | test_mhlib |
Tim Peters | de14a30 | 2002-04-01 05:04:46 +0000 | [diff] [blame] | 563 | test_mpz |
Guido van Rossum | f73e30c | 2001-08-12 02:22:19 +0000 | [diff] [blame] | 564 | test_nis |
| 565 | test_openpty |
Tim Peters | efc4b12 | 2002-12-10 18:47:56 +0000 | [diff] [blame] | 566 | test_ossaudiodev |
Guido van Rossum | f73e30c | 2001-08-12 02:22:19 +0000 | [diff] [blame] | 567 | test_poll |
| 568 | test_pty |
| 569 | test_pwd |
Tim Peters | 1e33ffa | 2002-04-23 23:09:02 +0000 | [diff] [blame] | 570 | test_resource |
Guido van Rossum | f73e30c | 2001-08-12 02:22:19 +0000 | [diff] [blame] | 571 | test_signal |
Tim Peters | a86f0c1 | 2001-09-18 02:18:57 +0000 | [diff] [blame] | 572 | test_socketserver |
Guido van Rossum | f73e30c | 2001-08-12 02:22:19 +0000 | [diff] [blame] | 573 | test_sunaudiodev |
| 574 | test_timing |
| 575 | """, |
| 576 | 'linux2': |
| 577 | """ |
| 578 | test_al |
| 579 | test_cd |
| 580 | test_cl |
Guido van Rossum | f66dacd | 2001-10-23 15:10:55 +0000 | [diff] [blame] | 581 | test_curses |
Guido van Rossum | f73e30c | 2001-08-12 02:22:19 +0000 | [diff] [blame] | 582 | test_dl |
Guido van Rossum | 6184c11 | 2002-04-16 02:14:04 +0000 | [diff] [blame] | 583 | test_email_codecs |
Guido van Rossum | f73e30c | 2001-08-12 02:22:19 +0000 | [diff] [blame] | 584 | test_gl |
| 585 | test_imgfile |
| 586 | test_largefile |
| 587 | test_nis |
| 588 | test_ntpath |
| 589 | test_socketserver |
| 590 | test_sunaudiodev |
| 591 | test_unicode_file |
| 592 | test_winreg |
| 593 | test_winsound |
| 594 | """, |
Jack Jansen | 49a806e | 2001-08-28 14:49:00 +0000 | [diff] [blame] | 595 | 'mac': |
Guido van Rossum | aa78236 | 2001-09-02 03:58:41 +0000 | [diff] [blame] | 596 | """ |
| 597 | test_al |
Jack Jansen | 6797514 | 2003-01-08 16:31:11 +0000 | [diff] [blame^] | 598 | test_atexit |
Guido van Rossum | aa78236 | 2001-09-02 03:58:41 +0000 | [diff] [blame] | 599 | test_bsddb |
Jack Jansen | 6797514 | 2003-01-08 16:31:11 +0000 | [diff] [blame^] | 600 | test_bsddb3 |
| 601 | test_bz2 |
Guido van Rossum | aa78236 | 2001-09-02 03:58:41 +0000 | [diff] [blame] | 602 | test_cd |
| 603 | test_cl |
| 604 | test_commands |
| 605 | test_crypt |
Jack Jansen | b3be216 | 2001-11-30 14:16:36 +0000 | [diff] [blame] | 606 | test_curses |
Guido van Rossum | aa78236 | 2001-09-02 03:58:41 +0000 | [diff] [blame] | 607 | test_dbm |
| 608 | test_dl |
Jack Jansen | 6797514 | 2003-01-08 16:31:11 +0000 | [diff] [blame^] | 609 | test_email_codecs |
Guido van Rossum | aa78236 | 2001-09-02 03:58:41 +0000 | [diff] [blame] | 610 | test_fcntl |
| 611 | test_fork1 |
| 612 | test_gl |
| 613 | test_grp |
| 614 | test_imgfile |
| 615 | test_largefile |
| 616 | test_linuxaudiodev |
| 617 | test_locale |
| 618 | test_mmap |
Jack Jansen | 6797514 | 2003-01-08 16:31:11 +0000 | [diff] [blame^] | 619 | test_mpz |
Guido van Rossum | aa78236 | 2001-09-02 03:58:41 +0000 | [diff] [blame] | 620 | test_nis |
| 621 | test_ntpath |
| 622 | test_openpty |
Jack Jansen | 6797514 | 2003-01-08 16:31:11 +0000 | [diff] [blame^] | 623 | test_ossaudiodev |
Guido van Rossum | aa78236 | 2001-09-02 03:58:41 +0000 | [diff] [blame] | 624 | test_poll |
Jack Jansen | 6797514 | 2003-01-08 16:31:11 +0000 | [diff] [blame^] | 625 | test_popen |
Guido van Rossum | aa78236 | 2001-09-02 03:58:41 +0000 | [diff] [blame] | 626 | test_popen2 |
| 627 | test_pty |
| 628 | test_pwd |
Jack Jansen | 6797514 | 2003-01-08 16:31:11 +0000 | [diff] [blame^] | 629 | test_resource |
Guido van Rossum | aa78236 | 2001-09-02 03:58:41 +0000 | [diff] [blame] | 630 | test_signal |
Guido van Rossum | aa78236 | 2001-09-02 03:58:41 +0000 | [diff] [blame] | 631 | test_socketserver |
| 632 | test_sunaudiodev |
| 633 | test_sundry |
| 634 | test_timing |
| 635 | test_unicode_file |
| 636 | test_winreg |
| 637 | test_winsound |
| 638 | """, |
Martin v. Löwis | 21ee409 | 2002-09-30 16:19:48 +0000 | [diff] [blame] | 639 | 'unixware7': |
Martin v. Löwis | 0ace326 | 2001-09-05 14:38:48 +0000 | [diff] [blame] | 640 | """ |
| 641 | test_al |
| 642 | test_bsddb |
| 643 | test_cd |
| 644 | test_cl |
| 645 | test_dl |
| 646 | test_gl |
| 647 | test_imgfile |
| 648 | test_largefile |
| 649 | test_linuxaudiodev |
| 650 | test_minidom |
| 651 | test_nis |
| 652 | test_ntpath |
| 653 | test_openpty |
| 654 | test_pyexpat |
| 655 | test_sax |
| 656 | test_socketserver |
| 657 | test_sunaudiodev |
| 658 | test_sundry |
| 659 | test_unicode_file |
| 660 | test_winreg |
| 661 | test_winsound |
| 662 | """, |
Martin v. Löwis | 21ee409 | 2002-09-30 16:19:48 +0000 | [diff] [blame] | 663 | 'openunix8': |
| 664 | """ |
| 665 | test_al |
| 666 | test_bsddb |
| 667 | test_cd |
| 668 | test_cl |
| 669 | test_dl |
| 670 | test_gl |
| 671 | test_imgfile |
| 672 | test_largefile |
| 673 | test_linuxaudiodev |
| 674 | test_minidom |
| 675 | test_nis |
| 676 | test_ntpath |
| 677 | test_openpty |
| 678 | test_pyexpat |
| 679 | test_sax |
| 680 | test_socketserver |
| 681 | test_sunaudiodev |
| 682 | test_sundry |
| 683 | test_unicode_file |
| 684 | test_winreg |
| 685 | test_winsound |
| 686 | """, |
| 687 | 'sco_sv3': |
| 688 | """ |
| 689 | test_al |
| 690 | test_asynchat |
| 691 | test_bsddb |
| 692 | test_cd |
| 693 | test_cl |
| 694 | test_dl |
| 695 | test_fork1 |
| 696 | test_gettext |
| 697 | test_gl |
| 698 | test_imgfile |
| 699 | test_largefile |
| 700 | test_linuxaudiodev |
| 701 | test_locale |
| 702 | test_minidom |
| 703 | test_nis |
| 704 | test_ntpath |
| 705 | test_openpty |
| 706 | test_pyexpat |
| 707 | test_queue |
| 708 | test_sax |
| 709 | test_socketserver |
| 710 | test_sunaudiodev |
| 711 | test_sundry |
| 712 | test_thread |
| 713 | test_threaded_import |
| 714 | test_threadedtempfile |
| 715 | test_threading |
| 716 | test_unicode_file |
| 717 | test_winreg |
| 718 | test_winsound |
| 719 | """, |
Guido van Rossum | e2ae77b | 2001-10-24 20:42:55 +0000 | [diff] [blame] | 720 | 'riscos': |
| 721 | """ |
| 722 | test_al |
| 723 | test_asynchat |
| 724 | test_bsddb |
| 725 | test_cd |
| 726 | test_cl |
| 727 | test_commands |
| 728 | test_crypt |
| 729 | test_dbm |
| 730 | test_dl |
| 731 | test_fcntl |
| 732 | test_fork1 |
| 733 | test_gdbm |
| 734 | test_gl |
| 735 | test_grp |
| 736 | test_imgfile |
| 737 | test_largefile |
| 738 | test_linuxaudiodev |
| 739 | test_locale |
| 740 | test_mmap |
| 741 | test_nis |
| 742 | test_ntpath |
| 743 | test_openpty |
| 744 | test_poll |
| 745 | test_popen2 |
| 746 | test_pty |
| 747 | test_pwd |
Guido van Rossum | e2ae77b | 2001-10-24 20:42:55 +0000 | [diff] [blame] | 748 | test_socketserver |
| 749 | test_strop |
| 750 | test_sunaudiodev |
| 751 | test_sundry |
| 752 | test_thread |
| 753 | test_threaded_import |
| 754 | test_threadedtempfile |
| 755 | test_threading |
| 756 | test_timing |
| 757 | test_unicode_file |
| 758 | test_winreg |
| 759 | test_winsound |
| 760 | """, |
Jack Jansen | 8a97f4a | 2001-12-05 23:27:32 +0000 | [diff] [blame] | 761 | 'darwin': |
Jack Jansen | 398c236 | 2001-12-02 21:41:36 +0000 | [diff] [blame] | 762 | """ |
| 763 | test_al |
Jack Jansen | acda339 | 2002-12-30 23:03:13 +0000 | [diff] [blame] | 764 | test_bsddb |
Guido van Rossum | 9d42700 | 2002-12-03 10:24:56 +0000 | [diff] [blame] | 765 | test_bsddb3 |
Jack Jansen | 398c236 | 2001-12-02 21:41:36 +0000 | [diff] [blame] | 766 | test_cd |
| 767 | test_cl |
| 768 | test_curses |
| 769 | test_dl |
Guido van Rossum | 9d42700 | 2002-12-03 10:24:56 +0000 | [diff] [blame] | 770 | test_email_codecs |
Jack Jansen | 398c236 | 2001-12-02 21:41:36 +0000 | [diff] [blame] | 771 | test_gdbm |
| 772 | test_gl |
| 773 | test_imgfile |
| 774 | test_largefile |
| 775 | test_linuxaudiodev |
Jack Jansen | acda339 | 2002-12-30 23:03:13 +0000 | [diff] [blame] | 776 | test_locale |
Jack Jansen | 398c236 | 2001-12-02 21:41:36 +0000 | [diff] [blame] | 777 | test_minidom |
Guido van Rossum | 9d42700 | 2002-12-03 10:24:56 +0000 | [diff] [blame] | 778 | test_mpz |
Jack Jansen | 398c236 | 2001-12-02 21:41:36 +0000 | [diff] [blame] | 779 | test_nis |
| 780 | test_ntpath |
Jack Jansen | acda339 | 2002-12-30 23:03:13 +0000 | [diff] [blame] | 781 | test_ossaudiodev |
Jack Jansen | 398c236 | 2001-12-02 21:41:36 +0000 | [diff] [blame] | 782 | test_poll |
Jack Jansen | f839c27 | 2001-12-14 21:28:53 +0000 | [diff] [blame] | 783 | test_socketserver |
Jack Jansen | 398c236 | 2001-12-02 21:41:36 +0000 | [diff] [blame] | 784 | test_sunaudiodev |
Jack Jansen | f839c27 | 2001-12-14 21:28:53 +0000 | [diff] [blame] | 785 | test_unicode_file |
Jack Jansen | 398c236 | 2001-12-02 21:41:36 +0000 | [diff] [blame] | 786 | test_winreg |
| 787 | test_winsound |
| 788 | """, |
Guido van Rossum | 11c3f09 | 2002-07-17 15:08:24 +0000 | [diff] [blame] | 789 | 'sunos5': |
| 790 | """ |
| 791 | test_al |
| 792 | test_bsddb |
| 793 | test_cd |
| 794 | test_cl |
| 795 | test_curses |
| 796 | test_dbm |
| 797 | test_email_codecs |
| 798 | test_gdbm |
| 799 | test_gl |
| 800 | test_gzip |
| 801 | test_imgfile |
| 802 | test_linuxaudiodev |
| 803 | test_mpz |
| 804 | test_openpty |
Guido van Rossum | 11c3f09 | 2002-07-17 15:08:24 +0000 | [diff] [blame] | 805 | test_socketserver |
| 806 | test_winreg |
| 807 | test_winsound |
| 808 | test_zipfile |
| 809 | test_zlib |
Jeremy Hylton | ed375e1 | 2002-07-17 15:56:55 +0000 | [diff] [blame] | 810 | """, |
Skip Montanaro | b323021 | 2002-03-15 02:54:03 +0000 | [diff] [blame] | 811 | 'hp-ux11': |
| 812 | """ |
| 813 | test_al |
| 814 | test_bsddb |
| 815 | test_cd |
| 816 | test_cl |
| 817 | test_curses |
| 818 | test_dl |
| 819 | test_gdbm |
| 820 | test_gl |
| 821 | test_gzip |
| 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_sax |
Skip Montanaro | b323021 | 2002-03-15 02:54:03 +0000 | [diff] [blame] | 832 | test_socketserver |
| 833 | test_sunaudiodev |
| 834 | test_unicode_file |
| 835 | test_winreg |
| 836 | test_winsound |
| 837 | test_zipfile |
| 838 | test_zlib |
| 839 | """, |
Martin v. Löwis | f90ae20 | 2002-06-11 06:22:31 +0000 | [diff] [blame] | 840 | 'atheos': |
Tim Peters | c411dba | 2002-07-16 21:35:23 +0000 | [diff] [blame] | 841 | """ |
| 842 | test_al |
| 843 | test_cd |
| 844 | test_cl |
| 845 | test_curses |
| 846 | test_dl |
| 847 | test_email_codecs |
| 848 | test_gdbm |
| 849 | test_gl |
| 850 | test_imgfile |
| 851 | test_largefile |
| 852 | test_linuxaudiodev |
| 853 | test_locale |
| 854 | test_mhlib |
| 855 | test_mmap |
| 856 | test_mpz |
| 857 | test_nis |
| 858 | test_poll |
| 859 | test_popen2 |
| 860 | test_resource |
Tim Peters | c411dba | 2002-07-16 21:35:23 +0000 | [diff] [blame] | 861 | test_socketserver |
| 862 | test_sunaudiodev |
| 863 | test_unicode_file |
| 864 | test_winreg |
| 865 | test_winsound |
| 866 | """, |
Jason Tishler | 2511594 | 2002-12-05 15:18:15 +0000 | [diff] [blame] | 867 | 'cygwin': |
| 868 | """ |
| 869 | test_al |
Tim Peters | b0f89e0 | 2002-12-05 17:20:25 +0000 | [diff] [blame] | 870 | test_bsddb3 |
Jason Tishler | 2511594 | 2002-12-05 15:18:15 +0000 | [diff] [blame] | 871 | test_cd |
| 872 | test_cl |
| 873 | test_curses |
| 874 | test_dbm |
| 875 | test_email_codecs |
| 876 | test_gl |
| 877 | test_imgfile |
| 878 | test_largefile |
| 879 | test_linuxaudiodev |
| 880 | test_locale |
| 881 | test_mpz |
| 882 | test_nis |
Jason Tishler | 2511594 | 2002-12-05 15:18:15 +0000 | [diff] [blame] | 883 | test_socketserver |
| 884 | test_sunaudiodev |
| 885 | test_unicode_file |
| 886 | test_winreg |
| 887 | test_winsound |
| 888 | """, |
Andrew MacIntyre | fd07e7d | 2002-12-31 11:26:50 +0000 | [diff] [blame] | 889 | 'os2emx': |
| 890 | """ |
| 891 | test_al |
| 892 | test_audioop |
| 893 | test_bsddb3 |
| 894 | test_cd |
| 895 | test_cl |
| 896 | test_commands |
| 897 | test_curses |
| 898 | test_dl |
| 899 | test_email_codecs |
| 900 | test_gl |
| 901 | test_imgfile |
| 902 | test_largefile |
| 903 | test_linuxaudiodev |
| 904 | test_mhlib |
| 905 | test_mmap |
| 906 | test_nis |
| 907 | test_openpty |
| 908 | test_ossaudiodev |
| 909 | test_pty |
| 910 | test_resource |
| 911 | test_signal |
| 912 | test_sunaudiodev |
| 913 | test_unicode_file |
| 914 | test_winreg |
| 915 | test_winsound |
| 916 | """, |
Guido van Rossum | f73e30c | 2001-08-12 02:22:19 +0000 | [diff] [blame] | 917 | } |
| 918 | |
Tim Peters | b5b7b78 | 2001-08-12 01:20:39 +0000 | [diff] [blame] | 919 | class _ExpectedSkips: |
| 920 | def __init__(self): |
Tim Peters | 2a182db | 2002-10-09 01:07:11 +0000 | [diff] [blame] | 921 | import os.path |
Tim Peters | 1b445d3 | 2002-11-24 18:53:11 +0000 | [diff] [blame] | 922 | from test import test_normalization |
Tim Peters | b4ee4eb | 2002-12-04 03:26:57 +0000 | [diff] [blame] | 923 | from test import test_socket_ssl |
Tim Peters | 1b445d3 | 2002-11-24 18:53:11 +0000 | [diff] [blame] | 924 | |
Tim Peters | 7c7efe9 | 2002-08-23 17:55:54 +0000 | [diff] [blame] | 925 | self.valid = False |
Tim Peters | de14a30 | 2002-04-01 05:04:46 +0000 | [diff] [blame] | 926 | if sys.platform in _expectations: |
Guido van Rossum | f73e30c | 2001-08-12 02:22:19 +0000 | [diff] [blame] | 927 | s = _expectations[sys.platform] |
Tim Peters | 7c7efe9 | 2002-08-23 17:55:54 +0000 | [diff] [blame] | 928 | self.expected = Set(s.split()) |
Tim Peters | 1b445d3 | 2002-11-24 18:53:11 +0000 | [diff] [blame] | 929 | |
Tim Peters | 2a182db | 2002-10-09 01:07:11 +0000 | [diff] [blame] | 930 | if not os.path.supports_unicode_filenames: |
| 931 | self.expected.add('test_pep277') |
Tim Peters | 1b445d3 | 2002-11-24 18:53:11 +0000 | [diff] [blame] | 932 | |
| 933 | if test_normalization.skip_expected: |
| 934 | self.expected.add('test_normalization') |
| 935 | |
Tim Peters | b4ee4eb | 2002-12-04 03:26:57 +0000 | [diff] [blame] | 936 | if test_socket_ssl.skip_expected: |
| 937 | self.expected.add('test_socket_ssl') |
| 938 | |
Tim Peters | 7c7efe9 | 2002-08-23 17:55:54 +0000 | [diff] [blame] | 939 | self.valid = True |
Tim Peters | b5b7b78 | 2001-08-12 01:20:39 +0000 | [diff] [blame] | 940 | |
| 941 | def isvalid(self): |
| 942 | "Return true iff _ExpectedSkips knows about the current platform." |
| 943 | return self.valid |
| 944 | |
| 945 | def getexpected(self): |
| 946 | """Return set of test names we expect to skip on current platform. |
| 947 | |
| 948 | self.isvalid() must be true. |
| 949 | """ |
| 950 | |
| 951 | assert self.isvalid() |
| 952 | return self.expected |
| 953 | |
Guido van Rossum | 152494a | 1996-12-20 03:12:20 +0000 | [diff] [blame] | 954 | if __name__ == '__main__': |
Barry Warsaw | 408b6d3 | 2002-07-30 23:27:12 +0000 | [diff] [blame] | 955 | # Remove regrtest.py's own directory from the module search path. This |
| 956 | # prevents relative imports from working, and relative imports will screw |
| 957 | # up the testing framework. E.g. if both test.test_support and |
| 958 | # test_support are imported, they will not contain the same globals, and |
| 959 | # much of the testing framework relies on the globals in the |
| 960 | # test.test_support module. |
| 961 | mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0]))) |
| 962 | i = pathlen = len(sys.path) |
| 963 | while i >= 0: |
| 964 | i -= 1 |
| 965 | if os.path.abspath(os.path.normpath(sys.path[i])) == mydir: |
| 966 | del sys.path[i] |
| 967 | if len(sys.path) == pathlen: |
| 968 | print 'Could not find %r in sys.path to remove it' % mydir |
Barry Warsaw | 08fca52 | 2001-08-20 22:33:46 +0000 | [diff] [blame] | 969 | main() |