test_whitespace_eater_unicode(): Make this test Python 2.1 compatible.
[python/dscho.git] / Lib / test / regrtest.py
blobc2d546d577be61cc9de5b0c0dd7c00bbe2e4a0e2
1 #! /usr/bin/env python
3 """Regression test.
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.
9 Command line options:
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
17 -f: fromfile -- read names of tests to run from a file (see below)
18 -l: findleaks -- if GC is available detect tests that leak memory
19 -u: use -- specify which special resource intensive tests to run
20 -h: help -- print this text and exit
21 -t: threshold -- call gc.set_threshold(N)
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.
27 -v is incompatible with -g and does not compare test output files.
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).
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.
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:
47 all - Enable all special resources.
49 audio - Tests that use the audio device. (There are known
50 cases of broken audio drivers that can crash Python or
51 even the Linux kernel.)
53 curses - Tests that use curses and will modify the terminal's
54 state and output modes.
56 largefile - It is okay to run some test that may create huge
57 files. These tests can take a long time and may
58 consume >2GB of disk space temporarily.
60 network - It is okay to run tests that use external network
61 resource, e.g. testing SSL support for sockets.
63 bsddb - It is okay to run the bsddb testsuite, which takes
64 a long time to complete.
66 To enable all resources except one, use '-uall,-<resource>'. For
67 example, to run all the tests except for the bsddb tests, give the
68 option '-uall,-bsddb'.
69 """
71 import sys
72 import os
73 import getopt
74 import traceback
75 import random
76 import StringIO
77 import warnings
78 from sets import Set
80 # I see no other way to suppress these warnings;
81 # putting them in test_grammar.py has no effect:
82 warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
83 ".*test.test_grammar$")
84 if sys.maxint > 0x7fffffff:
85 # Also suppress them in <string>, because for 64-bit platforms,
86 # that's where test_grammar.py hides them.
87 warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
88 "<string>")
90 # MacOSX (a.k.a. Darwin) has a default stack size that is too small
91 # for deeply recursive regular expressions. We see this as crashes in
92 # the Python test suite when running test_re.py and test_sre.py. The
93 # fix is to set the stack limit to 2048.
94 # This approach may also be useful for other Unixy platforms that
95 # suffer from small default stack limits.
96 if sys.platform == 'darwin':
97 try:
98 import resource
99 except ImportError:
100 pass
101 else:
102 soft, hard = resource.getrlimit(resource.RLIMIT_STACK)
103 newsoft = min(hard, max(soft, 1024*2048))
104 resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard))
106 from test import test_support
108 RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', 'bsddb')
111 def usage(code, msg=''):
112 print __doc__
113 if msg: print msg
114 sys.exit(code)
117 def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
118 exclude=0, single=0, randomize=0, fromfile=None, findleaks=0,
119 use_resources=None):
120 """Execute a test suite.
122 This also parses command-line options and modifies its behavior
123 accordingly.
125 tests -- a list of strings containing test names (optional)
126 testdir -- the directory in which to look for tests (optional)
128 Users other than the Python test suite will certainly want to
129 specify testdir; if it's omitted, the directory containing the
130 Python test suite is searched for.
132 If the tests argument is omitted, the tests listed on the
133 command-line will be used. If that's empty, too, then all *.py
134 files beginning with test_ will be used.
136 The other default arguments (verbose, quiet, generate, exclude,
137 single, randomize, findleaks, and use_resources) allow programmers
138 calling main() directly to set the values that would normally be
139 set by flags on the command line.
143 test_support.record_original_stdout(sys.stdout)
144 try:
145 opts, args = getopt.getopt(sys.argv[1:], 'hvgqxsrf:lu:t:',
146 ['help', 'verbose', 'quiet', 'generate',
147 'exclude', 'single', 'random', 'fromfile',
148 'findleaks', 'use=', 'threshold='])
149 except getopt.error, msg:
150 usage(2, msg)
152 # Defaults
153 if use_resources is None:
154 use_resources = []
155 for o, a in opts:
156 if o in ('-h', '--help'):
157 usage(0)
158 elif o in ('-v', '--verbose'):
159 verbose += 1
160 elif o in ('-q', '--quiet'):
161 quiet = 1;
162 verbose = 0
163 elif o in ('-g', '--generate'):
164 generate = 1
165 elif o in ('-x', '--exclude'):
166 exclude = 1
167 elif o in ('-s', '--single'):
168 single = 1
169 elif o in ('-r', '--randomize'):
170 randomize = 1
171 elif o in ('-f', '--fromfile'):
172 fromfile = a
173 elif o in ('-l', '--findleaks'):
174 findleaks = 1
175 elif o in ('-t', '--threshold'):
176 import gc
177 gc.set_threshold(int(a))
178 elif o in ('-u', '--use'):
179 u = [x.lower() for x in a.split(',')]
180 for r in u:
181 if r == 'all':
182 use_resources[:] = RESOURCE_NAMES
183 continue
184 remove = False
185 if r[0] == '-':
186 remove = True
187 r = r[1:]
188 if r not in RESOURCE_NAMES:
189 usage(1, 'Invalid -u/--use option: ' + a)
190 if remove:
191 if r in use_resources:
192 use_resources.remove(r)
193 elif r not in use_resources:
194 use_resources.append(r)
195 if generate and verbose:
196 usage(2, "-g and -v don't go together!")
197 if single and fromfile:
198 usage(2, "-s and -f don't go together!")
200 good = []
201 bad = []
202 skipped = []
203 resource_denieds = []
205 if findleaks:
206 try:
207 import gc
208 except ImportError:
209 print 'No GC available, disabling findleaks.'
210 findleaks = 0
211 else:
212 # Uncomment the line below to report garbage that is not
213 # freeable by reference counting alone. By default only
214 # garbage that is not collectable by the GC is reported.
215 #gc.set_debug(gc.DEBUG_SAVEALL)
216 found_garbage = []
218 if single:
219 from tempfile import gettempdir
220 filename = os.path.join(gettempdir(), 'pynexttest')
221 try:
222 fp = open(filename, 'r')
223 next = fp.read().strip()
224 tests = [next]
225 fp.close()
226 except IOError:
227 pass
229 if fromfile:
230 tests = []
231 fp = open(fromfile)
232 for line in fp:
233 guts = line.split() # assuming no test has whitespace in its name
234 if guts and not guts[0].startswith('#'):
235 tests.extend(guts)
236 fp.close()
238 # Strip .py extensions.
239 if args:
240 args = map(removepy, args)
241 if tests:
242 tests = map(removepy, tests)
244 stdtests = STDTESTS[:]
245 nottests = NOTTESTS[:]
246 if exclude:
247 for arg in args:
248 if arg in stdtests:
249 stdtests.remove(arg)
250 nottests[:0] = args
251 args = []
252 tests = tests or args or findtests(testdir, stdtests, nottests)
253 if single:
254 tests = tests[:1]
255 if randomize:
256 random.shuffle(tests)
257 test_support.verbose = verbose # Tell tests to be moderately quiet
258 test_support.use_resources = use_resources
259 save_modules = sys.modules.keys()
260 for test in tests:
261 if not quiet:
262 print test
263 sys.stdout.flush()
264 ok = runtest(test, generate, verbose, quiet, testdir)
265 if ok > 0:
266 good.append(test)
267 elif ok == 0:
268 bad.append(test)
269 else:
270 skipped.append(test)
271 if ok == -2:
272 resource_denieds.append(test)
273 if findleaks:
274 gc.collect()
275 if gc.garbage:
276 print "Warning: test created", len(gc.garbage),
277 print "uncollectable object(s)."
278 # move the uncollectable objects somewhere so we don't see
279 # them again
280 found_garbage.extend(gc.garbage)
281 del gc.garbage[:]
282 # Unload the newly imported modules (best effort finalization)
283 for module in sys.modules.keys():
284 if module not in save_modules and module.startswith("test."):
285 test_support.unload(module)
287 # The lists won't be sorted if running with -r
288 good.sort()
289 bad.sort()
290 skipped.sort()
292 if good and not quiet:
293 if not bad and not skipped and len(good) > 1:
294 print "All",
295 print count(len(good), "test"), "OK."
296 if verbose:
297 print "CAUTION: stdout isn't compared in verbose mode:"
298 print "a test that passes in verbose mode may fail without it."
299 if bad:
300 print count(len(bad), "test"), "failed:"
301 printlist(bad)
302 if skipped and not quiet:
303 print count(len(skipped), "test"), "skipped:"
304 printlist(skipped)
306 e = _ExpectedSkips()
307 plat = sys.platform
308 if e.isvalid():
309 surprise = Set(skipped) - e.getexpected() - Set(resource_denieds)
310 if surprise:
311 print count(len(surprise), "skip"), \
312 "unexpected on", plat + ":"
313 printlist(surprise)
314 else:
315 print "Those skips are all expected on", plat + "."
316 else:
317 print "Ask someone to teach regrtest.py about which tests are"
318 print "expected to get skipped on", plat + "."
320 if single:
321 alltests = findtests(testdir, stdtests, nottests)
322 for i in range(len(alltests)):
323 if tests[0] == alltests[i]:
324 if i == len(alltests) - 1:
325 os.unlink(filename)
326 else:
327 fp = open(filename, 'w')
328 fp.write(alltests[i+1] + '\n')
329 fp.close()
330 break
331 else:
332 os.unlink(filename)
334 sys.exit(len(bad) > 0)
337 STDTESTS = [
338 'test_grammar',
339 'test_opcodes',
340 'test_operations',
341 'test_builtin',
342 'test_exceptions',
343 'test_types',
346 NOTTESTS = [
347 'test_support',
348 'test_future1',
349 'test_future2',
350 'test_future3',
353 def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
354 """Return a list of all applicable test modules."""
355 if not testdir: testdir = findtestdir()
356 names = os.listdir(testdir)
357 tests = []
358 for name in names:
359 if name[:5] == "test_" and name[-3:] == os.extsep+"py":
360 modname = name[:-3]
361 if modname not in stdtests and modname not in nottests:
362 tests.append(modname)
363 tests.sort()
364 return stdtests + tests
366 def runtest(test, generate, verbose, quiet, testdir = None):
367 """Run a single test.
368 test -- the name of the test
369 generate -- if true, generate output, instead of running the test
370 and comparing it to a previously created output file
371 verbose -- if true, print more messages
372 quiet -- if true, don't print 'skipped' messages (probably redundant)
373 testdir -- test directory
375 test_support.unload(test)
376 if not testdir: testdir = findtestdir()
377 outputdir = os.path.join(testdir, "output")
378 outputfile = os.path.join(outputdir, test)
379 if verbose:
380 cfp = None
381 else:
382 cfp = StringIO.StringIO()
383 try:
384 save_stdout = sys.stdout
385 try:
386 if cfp:
387 sys.stdout = cfp
388 print test # Output file starts with test name
389 if test.startswith('test.'):
390 abstest = test
391 else:
392 # Always import it from the test package
393 abstest = 'test.' + test
394 the_package = __import__(abstest, globals(), locals(), [])
395 the_module = getattr(the_package, test)
396 # Most tests run to completion simply as a side-effect of
397 # being imported. For the benefit of tests that can't run
398 # that way (like test_threaded_import), explicitly invoke
399 # their test_main() function (if it exists).
400 indirect_test = getattr(the_module, "test_main", None)
401 if indirect_test is not None:
402 indirect_test()
403 finally:
404 sys.stdout = save_stdout
405 except test_support.ResourceDenied, msg:
406 if not quiet:
407 print test, "skipped --", msg
408 sys.stdout.flush()
409 return -2
410 except (ImportError, test_support.TestSkipped), msg:
411 if not quiet:
412 print test, "skipped --", msg
413 sys.stdout.flush()
414 return -1
415 except KeyboardInterrupt:
416 raise
417 except test_support.TestFailed, msg:
418 print "test", test, "failed --", msg
419 sys.stdout.flush()
420 return 0
421 except:
422 type, value = sys.exc_info()[:2]
423 print "test", test, "crashed --", str(type) + ":", value
424 sys.stdout.flush()
425 if verbose:
426 traceback.print_exc(file=sys.stdout)
427 sys.stdout.flush()
428 return 0
429 else:
430 if not cfp:
431 return 1
432 output = cfp.getvalue()
433 if generate:
434 if output == test + "\n":
435 if os.path.exists(outputfile):
436 # Write it since it already exists (and the contents
437 # may have changed), but let the user know it isn't
438 # needed:
439 print "output file", outputfile, \
440 "is no longer needed; consider removing it"
441 else:
442 # We don't need it, so don't create it.
443 return 1
444 fp = open(outputfile, "w")
445 fp.write(output)
446 fp.close()
447 return 1
448 if os.path.exists(outputfile):
449 fp = open(outputfile, "r")
450 expected = fp.read()
451 fp.close()
452 else:
453 expected = test + "\n"
454 if output == expected:
455 return 1
456 print "test", test, "produced unexpected output:"
457 sys.stdout.flush()
458 reportdiff(expected, output)
459 sys.stdout.flush()
460 return 0
462 def reportdiff(expected, output):
463 import difflib
464 print "*" * 70
465 a = expected.splitlines(1)
466 b = output.splitlines(1)
467 sm = difflib.SequenceMatcher(a=a, b=b)
468 tuples = sm.get_opcodes()
470 def pair(x0, x1):
471 # x0:x1 are 0-based slice indices; convert to 1-based line indices.
472 x0 += 1
473 if x0 >= x1:
474 return "line " + str(x0)
475 else:
476 return "lines %d-%d" % (x0, x1)
478 for op, a0, a1, b0, b1 in tuples:
479 if op == 'equal':
480 pass
482 elif op == 'delete':
483 print "***", pair(a0, a1), "of expected output missing:"
484 for line in a[a0:a1]:
485 print "-", line,
487 elif op == 'replace':
488 print "*** mismatch between", pair(a0, a1), "of expected", \
489 "output and", pair(b0, b1), "of actual output:"
490 for line in difflib.ndiff(a[a0:a1], b[b0:b1]):
491 print line,
493 elif op == 'insert':
494 print "***", pair(b0, b1), "of actual output doesn't appear", \
495 "in expected output after line", str(a1)+":"
496 for line in b[b0:b1]:
497 print "+", line,
499 else:
500 print "get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1)
502 print "*" * 70
504 def findtestdir():
505 if __name__ == '__main__':
506 file = sys.argv[0]
507 else:
508 file = __file__
509 testdir = os.path.dirname(file) or os.curdir
510 return testdir
512 def removepy(name):
513 if name.endswith(os.extsep + "py"):
514 name = name[:-3]
515 return name
517 def count(n, word):
518 if n == 1:
519 return "%d %s" % (n, word)
520 else:
521 return "%d %ss" % (n, word)
523 def printlist(x, width=70, indent=4):
524 """Print the elements of iterable x to stdout.
526 Optional arg width (default 70) is the maximum line length.
527 Optional arg indent (default 4) is the number of blanks with which to
528 begin each line.
531 from textwrap import fill
532 blanks = ' ' * indent
533 print fill(' '.join(map(str, x)), width,
534 initial_indent=blanks, subsequent_indent=blanks)
536 # Map sys.platform to a string containing the basenames of tests
537 # expected to be skipped on that platform.
539 # Special cases:
540 # test_pep277
541 # The _ExpectedSkips constructor adds this to the set of expected
542 # skips if not os.path.supports_unicode_filenames.
543 # test_normalization
544 # Whether a skip is expected here depends on whether a large test
545 # input file has been downloaded. test_normalization.skip_expected
546 # controls that.
547 # test_socket_ssl
548 # Controlled by test_socket_ssl.skip_expected. Requires the network
549 # resource, and a socket module with ssl support.
550 # test_timeout
551 # Controlled by test_timeout.skip_expected. Requires the network
552 # resource and a socket module.
554 _expectations = {
555 'win32':
557 test_al
558 test_bsddb3
559 test_cd
560 test_cl
561 test_commands
562 test_crypt
563 test_curses
564 test_dbm
565 test_dl
566 test_email_codecs
567 test_fcntl
568 test_fork1
569 test_gdbm
570 test_gl
571 test_grp
572 test_iconv_codecs
573 test_imgfile
574 test_ioctl
575 test_largefile
576 test_linuxaudiodev
577 test_macfs
578 test_macostools
579 test_mhlib
580 test_mpz
581 test_nis
582 test_openpty
583 test_ossaudiodev
584 test_plistlib
585 test_poll
586 test_posix
587 test_pty
588 test_pwd
589 test_resource
590 test_signal
591 test_socketserver
592 test_sunaudiodev
593 test_timing
594 """,
595 'linux2':
597 test_al
598 test_cd
599 test_cl
600 test_curses
601 test_dl
602 test_email_codecs
603 test_gl
604 test_imgfile
605 test_largefile
606 test_linuxaudiodev
607 test_macfs
608 test_macostools
609 test_nis
610 test_ntpath
611 test_ossaudiodev
612 test_plistlib
613 test_socketserver
614 test_sunaudiodev
615 test_unicode_file
616 """,
617 'mac':
619 test_al
620 test_atexit
621 test_bsddb
622 test_bsddb3
623 test_bz2
624 test_cd
625 test_cl
626 test_commands
627 test_crypt
628 test_curses
629 test_dbm
630 test_dl
631 test_email_codecs
632 test_fcntl
633 test_fork1
634 test_gl
635 test_grp
636 test_iconv_codecs
637 test_ioctl
638 test_imgfile
639 test_largefile
640 test_linuxaudiodev
641 test_locale
642 test_mmap
643 test_mpz
644 test_nis
645 test_ntpath
646 test_openpty
647 test_ossaudiodev
648 test_poll
649 test_popen
650 test_popen2
651 test_posix
652 test_pty
653 test_pwd
654 test_resource
655 test_signal
656 test_socketserver
657 test_sunaudiodev
658 test_sundry
659 test_tarfile
660 test_timing
661 test_unicode_file
662 """,
663 'unixware7':
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_macfs
675 test_macostools
676 test_minidom
677 test_nis
678 test_ntpath
679 test_openpty
680 test_plistlib
681 test_pyexpat
682 test_sax
683 test_socketserver
684 test_sunaudiodev
685 test_sundry
686 test_unicode_file
687 """,
688 'openunix8':
690 test_al
691 test_bsddb
692 test_cd
693 test_cl
694 test_dl
695 test_gl
696 test_imgfile
697 test_largefile
698 test_linuxaudiodev
699 test_macfs
700 test_macostools
701 test_minidom
702 test_nis
703 test_ntpath
704 test_openpty
705 test_plistlib
706 test_pyexpat
707 test_sax
708 test_socketserver
709 test_sunaudiodev
710 test_sundry
711 test_unicode_file
712 """,
713 'sco_sv3':
715 test_al
716 test_asynchat
717 test_bsddb
718 test_cd
719 test_cl
720 test_dl
721 test_fork1
722 test_gettext
723 test_gl
724 test_imgfile
725 test_largefile
726 test_linuxaudiodev
727 test_locale
728 test_macfs
729 test_macostools
730 test_minidom
731 test_nis
732 test_ntpath
733 test_openpty
734 test_plistlib
735 test_pyexpat
736 test_queue
737 test_sax
738 test_socketserver
739 test_sunaudiodev
740 test_sundry
741 test_thread
742 test_threaded_import
743 test_threadedtempfile
744 test_threading
745 test_unicode_file
746 """,
747 'riscos':
749 test_al
750 test_asynchat
751 test_bsddb
752 test_cd
753 test_cl
754 test_commands
755 test_crypt
756 test_dbm
757 test_dl
758 test_fcntl
759 test_fork1
760 test_gdbm
761 test_gl
762 test_grp
763 test_imgfile
764 test_largefile
765 test_linuxaudiodev
766 test_locale
767 test_macfs
768 test_macostools
769 test_mmap
770 test_nis
771 test_ntpath
772 test_openpty
773 test_plistlib
774 test_poll
775 test_popen2
776 test_pty
777 test_pwd
778 test_socketserver
779 test_strop
780 test_sunaudiodev
781 test_sundry
782 test_thread
783 test_threaded_import
784 test_threadedtempfile
785 test_threading
786 test_timing
787 test_unicode_file
788 """,
789 'darwin':
791 test_al
792 test_bsddb
793 test_bsddb3
794 test_cd
795 test_cl
796 test_curses
797 test_dl
798 test_email_codecs
799 test_gdbm
800 test_gl
801 test_iconv_codecs
802 test_imgfile
803 test_largefile
804 test_linuxaudiodev
805 test_locale
806 test_minidom
807 test_mpz
808 test_nis
809 test_ntpath
810 test_ossaudiodev
811 test_poll
812 test_socketserver
813 test_sunaudiodev
814 test_unicode_file
815 """,
816 'sunos5':
818 test_al
819 test_bsddb
820 test_cd
821 test_cl
822 test_curses
823 test_dbm
824 test_email_codecs
825 test_gdbm
826 test_gl
827 test_gzip
828 test_imgfile
829 test_linuxaudiodev
830 test_macfs
831 test_macostools
832 test_mpz
833 test_openpty
834 test_plistlib
835 test_socketserver
836 test_zipfile
837 test_zlib
838 """,
839 'hp-ux11':
841 test_al
842 test_bsddb
843 test_cd
844 test_cl
845 test_curses
846 test_dl
847 test_gdbm
848 test_gl
849 test_gzip
850 test_imgfile
851 test_largefile
852 test_linuxaudiodev
853 test_locale
854 test_macfs
855 test_macostools
856 test_minidom
857 test_nis
858 test_ntpath
859 test_openpty
860 test_plistlib
861 test_pyexpat
862 test_sax
863 test_socketserver
864 test_sunaudiodev
865 test_unicode_file
866 test_zipfile
867 test_zlib
868 """,
869 'atheos':
871 test_al
872 test_cd
873 test_cl
874 test_curses
875 test_dl
876 test_email_codecs
877 test_gdbm
878 test_gl
879 test_imgfile
880 test_largefile
881 test_linuxaudiodev
882 test_locale
883 test_macfs
884 test_macostools
885 test_mhlib
886 test_mmap
887 test_mpz
888 test_nis
889 test_plistlib
890 test_poll
891 test_popen2
892 test_resource
893 test_socketserver
894 test_sunaudiodev
895 test_unicode_file
896 """,
897 'cygwin':
899 test_al
900 test_bsddb3
901 test_cd
902 test_cl
903 test_curses
904 test_dbm
905 test_email_codecs
906 test_gl
907 test_imgfile
908 test_largefile
909 test_linuxaudiodev
910 test_locale
911 test_macfs
912 test_macostools
913 test_mpz
914 test_nis
915 test_ossaudiodev
916 test_plistlib
917 test_socketserver
918 test_sunaudiodev
919 test_unicode_file
920 """,
921 'os2emx':
923 test_al
924 test_audioop
925 test_bsddb3
926 test_cd
927 test_cl
928 test_commands
929 test_curses
930 test_dl
931 test_email_codecs
932 test_gl
933 test_iconv_codecs
934 test_imgfile
935 test_largefile
936 test_linuxaudiodev
937 test_macfs
938 test_macostools
939 test_mhlib
940 test_mmap
941 test_nis
942 test_openpty
943 test_ossaudiodev
944 test_plistlib
945 test_pty
946 test_resource
947 test_signal
948 test_sunaudiodev
949 test_unicode_file
950 """,
953 class _ExpectedSkips:
954 def __init__(self):
955 import os.path
956 from test import test_normalization
957 from test import test_socket_ssl
958 from test import test_timeout
960 self.valid = False
961 if sys.platform in _expectations:
962 s = _expectations[sys.platform]
963 self.expected = Set(s.split())
965 if not os.path.supports_unicode_filenames:
966 self.expected.add('test_pep277')
968 if test_normalization.skip_expected:
969 self.expected.add('test_normalization')
971 if test_socket_ssl.skip_expected:
972 self.expected.add('test_socket_ssl')
974 if test_timeout.skip_expected:
975 self.expected.add('test_timeout')
977 if not sys.platform in ("mac", "darwin"):
978 self.expected.add("test_macostools")
979 self.expected.add("test_macfs")
980 self.expected.add("test_aepack")
982 if sys.platform != "win32":
983 self.expected.add("test_winreg")
984 self.expected.add("test_winsound")
986 self.valid = True
988 def isvalid(self):
989 "Return true iff _ExpectedSkips knows about the current platform."
990 return self.valid
992 def getexpected(self):
993 """Return set of test names we expect to skip on current platform.
995 self.isvalid() must be true.
998 assert self.isvalid()
999 return self.expected
1001 if __name__ == '__main__':
1002 # Remove regrtest.py's own directory from the module search path. This
1003 # prevents relative imports from working, and relative imports will screw
1004 # up the testing framework. E.g. if both test.test_support and
1005 # test_support are imported, they will not contain the same globals, and
1006 # much of the testing framework relies on the globals in the
1007 # test.test_support module.
1008 mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
1009 i = pathlen = len(sys.path)
1010 while i >= 0:
1011 i -= 1
1012 if os.path.abspath(os.path.normpath(sys.path[i])) == mydir:
1013 del sys.path[i]
1014 if len(sys.path) == pathlen:
1015 print 'Could not find %r in sys.path to remove it' % mydir
1016 main()