Update for release.
[python/dscho.git] / Lib / test / regrtest.py
blobc433c8bc48b5e286715917962195bd428027c3de
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 curses - Tests that use curses and will modify the terminal's
50 state and output modes.
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.
56 network - It is okay to run tests that use external network
57 resource, e.g. testing SSL support for sockets.
59 bsddb - It is okay to run the bsddb testsuite, which takes
60 a long time to complete.
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'.
65 """
67 import sys
68 import os
69 import getopt
70 import traceback
71 import random
72 import StringIO
73 import warnings
74 from sets import Set
76 # I see no other way to suppress these warnings;
77 # putting them in test_grammar.py has no effect:
78 warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning,
79 ".*test.test_grammar$")
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>")
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))
102 from test import test_support
104 RESOURCE_NAMES = ('curses', 'largefile', 'network', 'bsddb')
107 def usage(code, msg=''):
108 print __doc__
109 if msg: print msg
110 sys.exit(code)
113 def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
114 exclude=0, single=0, randomize=0, fromfile=None, findleaks=0,
115 use_resources=None):
116 """Execute a test suite.
118 This also parses command-line options and modifies its behavior
119 accordingly.
121 tests -- a list of strings containing test names (optional)
122 testdir -- the directory in which to look for tests (optional)
124 Users other than the Python test suite will certainly want to
125 specify testdir; if it's omitted, the directory containing the
126 Python test suite is searched for.
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.
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.
139 test_support.record_original_stdout(sys.stdout)
140 try:
141 opts, args = getopt.getopt(sys.argv[1:], 'hvgqxsrf:lu:t:',
142 ['help', 'verbose', 'quiet', 'generate',
143 'exclude', 'single', 'random', 'fromfile',
144 'findleaks', 'use=', 'threshold='])
145 except getopt.error, msg:
146 usage(2, msg)
148 # Defaults
149 if use_resources is None:
150 use_resources = []
151 for o, a in opts:
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
167 elif o in ('-f', '--fromfile'):
168 fromfile = a
169 elif o in ('-l', '--findleaks'):
170 findleaks = 1
171 elif o in ('-t', '--threshold'):
172 import gc
173 gc.set_threshold(int(a))
174 elif o in ('-u', '--use'):
175 u = [x.lower() for x in a.split(',')]
176 for r in u:
177 if r == 'all':
178 use_resources[:] = RESOURCE_NAMES
179 continue
180 remove = False
181 if r[0] == '-':
182 remove = True
183 r = r[1:]
184 if r not in RESOURCE_NAMES:
185 usage(1, 'Invalid -u/--use option: ' + a)
186 if remove:
187 if r in use_resources:
188 use_resources.remove(r)
189 elif r not in use_resources:
190 use_resources.append(r)
191 if generate and verbose:
192 usage(2, "-g and -v don't go together!")
193 if single and fromfile:
194 usage(2, "-s and -f don't go together!")
196 good = []
197 bad = []
198 skipped = []
200 if findleaks:
201 try:
202 import gc
203 except ImportError:
204 print 'No GC available, disabling findleaks.'
205 findleaks = 0
206 else:
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)
211 found_garbage = []
213 if single:
214 from tempfile import gettempdir
215 filename = os.path.join(gettempdir(), 'pynexttest')
216 try:
217 fp = open(filename, 'r')
218 next = fp.read().strip()
219 tests = [next]
220 fp.close()
221 except IOError:
222 pass
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()
233 # Strip .py extensions.
234 if args:
235 args = map(removepy, args)
236 if tests:
237 tests = map(removepy, tests)
239 stdtests = STDTESTS[:]
240 nottests = NOTTESTS[:]
241 if exclude:
242 for arg in args:
243 if arg in stdtests:
244 stdtests.remove(arg)
245 nottests[:0] = args
246 args = []
247 tests = tests or args or findtests(testdir, stdtests, nottests)
248 if single:
249 tests = tests[:1]
250 if randomize:
251 random.shuffle(tests)
252 test_support.verbose = verbose # Tell tests to be moderately quiet
253 test_support.use_resources = use_resources
254 save_modules = sys.modules.keys()
255 for test in tests:
256 if not quiet:
257 print test
258 sys.stdout.flush()
259 ok = runtest(test, generate, verbose, quiet, testdir)
260 if ok > 0:
261 good.append(test)
262 elif ok == 0:
263 bad.append(test)
264 else:
265 skipped.append(test)
266 if findleaks:
267 gc.collect()
268 if gc.garbage:
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
273 found_garbage.extend(gc.garbage)
274 del gc.garbage[:]
275 # Unload the newly imported modules (best effort finalization)
276 for module in sys.modules.keys():
277 if module not in save_modules and module.startswith("test."):
278 test_support.unload(module)
280 # The lists won't be sorted if running with -r
281 good.sort()
282 bad.sort()
283 skipped.sort()
285 if good and not quiet:
286 if not bad and not skipped and len(good) > 1:
287 print "All",
288 print count(len(good), "test"), "OK."
289 if verbose:
290 print "CAUTION: stdout isn't compared in verbose mode:"
291 print "a test that passes in verbose mode may fail without it."
292 if bad:
293 print count(len(bad), "test"), "failed:"
294 printlist(bad)
295 if skipped and not quiet:
296 print count(len(skipped), "test"), "skipped:"
297 printlist(skipped)
299 e = _ExpectedSkips()
300 plat = sys.platform
301 if e.isvalid():
302 surprise = Set(skipped) - e.getexpected()
303 if surprise:
304 print count(len(surprise), "skip"), \
305 "unexpected on", plat + ":"
306 printlist(surprise)
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 + "."
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)
327 sys.exit(len(bad) > 0)
330 STDTESTS = [
331 'test_grammar',
332 'test_opcodes',
333 'test_operations',
334 'test_builtin',
335 'test_exceptions',
336 'test_types',
339 NOTTESTS = [
340 'test_support',
341 'test_b1',
342 'test_b2',
343 'test_future1',
344 'test_future2',
345 'test_future3',
348 def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
349 """Return a list of all applicable test modules."""
350 if not testdir: testdir = findtestdir()
351 names = os.listdir(testdir)
352 tests = []
353 for name in names:
354 if name[:5] == "test_" and name[-3:] == os.extsep+"py":
355 modname = name[:-3]
356 if modname not in stdtests and modname not in nottests:
357 tests.append(modname)
358 tests.sort()
359 return stdtests + tests
361 def runtest(test, generate, verbose, quiet, testdir = None):
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
367 quiet -- if true, don't print 'skipped' messages (probably redundant)
368 testdir -- test directory
370 test_support.unload(test)
371 if not testdir: testdir = findtestdir()
372 outputdir = os.path.join(testdir, "output")
373 outputfile = os.path.join(outputdir, test)
374 if verbose:
375 cfp = None
376 else:
377 cfp = StringIO.StringIO()
378 try:
379 save_stdout = sys.stdout
380 try:
381 if cfp:
382 sys.stdout = cfp
383 print test # Output file starts with test name
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)
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()
398 finally:
399 sys.stdout = save_stdout
400 except (ImportError, test_support.TestSkipped), msg:
401 if not quiet:
402 print test, "skipped --", msg
403 sys.stdout.flush()
404 return -1
405 except KeyboardInterrupt:
406 raise
407 except test_support.TestFailed, msg:
408 print "test", test, "failed --", msg
409 sys.stdout.flush()
410 return 0
411 except:
412 type, value = sys.exc_info()[:2]
413 print "test", test, "crashed --", str(type) + ":", value
414 sys.stdout.flush()
415 if verbose:
416 traceback.print_exc(file=sys.stdout)
417 sys.stdout.flush()
418 return 0
419 else:
420 if not cfp:
421 return 1
422 output = cfp.getvalue()
423 if generate:
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:
429 print "output file", outputfile, \
430 "is no longer needed; consider removing it"
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:"
447 sys.stdout.flush()
448 reportdiff(expected, output)
449 sys.stdout.flush()
450 return 0
452 def reportdiff(expected, output):
453 import difflib
454 print "*" * 70
455 a = expected.splitlines(1)
456 b = output.splitlines(1)
457 sm = difflib.SequenceMatcher(a=a, b=b)
458 tuples = sm.get_opcodes()
460 def pair(x0, x1):
461 # x0:x1 are 0-based slice indices; convert to 1-based line indices.
462 x0 += 1
463 if x0 >= x1:
464 return "line " + str(x0)
465 else:
466 return "lines %d-%d" % (x0, x1)
468 for op, a0, a1, b0, b1 in tuples:
469 if op == 'equal':
470 pass
472 elif op == 'delete':
473 print "***", pair(a0, a1), "of expected output missing:"
474 for line in a[a0:a1]:
475 print "-", line,
477 elif op == 'replace':
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,
483 elif op == 'insert':
484 print "***", pair(b0, b1), "of actual output doesn't appear", \
485 "in expected output after line", str(a1)+":"
486 for line in b[b0:b1]:
487 print "+", line,
489 else:
490 print "get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1)
492 print "*" * 70
494 def findtestdir():
495 if __name__ == '__main__':
496 file = sys.argv[0]
497 else:
498 file = __file__
499 testdir = os.path.dirname(file) or os.curdir
500 return testdir
502 def removepy(name):
503 if name.endswith(os.extsep + "py"):
504 name = name[:-3]
505 return name
507 def count(n, word):
508 if n == 1:
509 return "%d %s" % (n, word)
510 else:
511 return "%d %ss" % (n, word)
513 def printlist(x, width=70, indent=4):
514 """Print the elements of iterable x to stdout.
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.
521 from textwrap import fill
522 blanks = ' ' * indent
523 print fill(' '.join(map(str, x)), width,
524 initial_indent=blanks, subsequent_indent=blanks)
526 # Map sys.platform to a string containing the basenames of tests
527 # expected to be skipped on that platform.
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.
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
536 # controls that.
537 # test_socket_ssl
538 # Controlled by test_socket_ssl.skip_expected. Requires the network
539 # resource, and a socket module with ssl support.
541 _expectations = {
542 'win32':
544 test_al
545 test_bsddb3
546 test_cd
547 test_cl
548 test_commands
549 test_crypt
550 test_curses
551 test_dbm
552 test_dl
553 test_email_codecs
554 test_fcntl
555 test_fork1
556 test_gdbm
557 test_gl
558 test_grp
559 test_iconv_codec
560 test_imgfile
561 test_largefile
562 test_linuxaudiodev
563 test_mhlib
564 test_mpz
565 test_nis
566 test_openpty
567 test_ossaudiodev
568 test_poll
569 test_pty
570 test_pwd
571 test_resource
572 test_signal
573 test_socketserver
574 test_sunaudiodev
575 test_timing
576 """,
577 'linux2':
579 test_al
580 test_cd
581 test_cl
582 test_curses
583 test_dl
584 test_email_codecs
585 test_gl
586 test_imgfile
587 test_largefile
588 test_nis
589 test_ntpath
590 test_socketserver
591 test_sunaudiodev
592 test_unicode_file
593 test_winreg
594 test_winsound
595 """,
596 'mac':
598 test_al
599 test_atexit
600 test_bsddb
601 test_bsddb3
602 test_bz2
603 test_cd
604 test_cl
605 test_commands
606 test_crypt
607 test_curses
608 test_dbm
609 test_dl
610 test_email_codecs
611 test_fcntl
612 test_fork1
613 test_gl
614 test_grp
615 test_iconv_codec
616 test_imgfile
617 test_largefile
618 test_linuxaudiodev
619 test_locale
620 test_mmap
621 test_mpz
622 test_nis
623 test_ntpath
624 test_openpty
625 test_ossaudiodev
626 test_poll
627 test_popen
628 test_popen2
629 test_pty
630 test_pwd
631 test_resource
632 test_signal
633 test_socketserver
634 test_sunaudiodev
635 test_sundry
636 test_timing
637 test_unicode_file
638 test_winreg
639 test_winsound
640 """,
641 'unixware7':
643 test_al
644 test_bsddb
645 test_cd
646 test_cl
647 test_dl
648 test_gl
649 test_imgfile
650 test_largefile
651 test_linuxaudiodev
652 test_minidom
653 test_nis
654 test_ntpath
655 test_openpty
656 test_pyexpat
657 test_sax
658 test_socketserver
659 test_sunaudiodev
660 test_sundry
661 test_unicode_file
662 test_winreg
663 test_winsound
664 """,
665 'openunix8':
667 test_al
668 test_bsddb
669 test_cd
670 test_cl
671 test_dl
672 test_gl
673 test_imgfile
674 test_largefile
675 test_linuxaudiodev
676 test_minidom
677 test_nis
678 test_ntpath
679 test_openpty
680 test_pyexpat
681 test_sax
682 test_socketserver
683 test_sunaudiodev
684 test_sundry
685 test_unicode_file
686 test_winreg
687 test_winsound
688 """,
689 'sco_sv3':
691 test_al
692 test_asynchat
693 test_bsddb
694 test_cd
695 test_cl
696 test_dl
697 test_fork1
698 test_gettext
699 test_gl
700 test_imgfile
701 test_largefile
702 test_linuxaudiodev
703 test_locale
704 test_minidom
705 test_nis
706 test_ntpath
707 test_openpty
708 test_pyexpat
709 test_queue
710 test_sax
711 test_socketserver
712 test_sunaudiodev
713 test_sundry
714 test_thread
715 test_threaded_import
716 test_threadedtempfile
717 test_threading
718 test_unicode_file
719 test_winreg
720 test_winsound
721 """,
722 'riscos':
724 test_al
725 test_asynchat
726 test_bsddb
727 test_cd
728 test_cl
729 test_commands
730 test_crypt
731 test_dbm
732 test_dl
733 test_fcntl
734 test_fork1
735 test_gdbm
736 test_gl
737 test_grp
738 test_imgfile
739 test_largefile
740 test_linuxaudiodev
741 test_locale
742 test_mmap
743 test_nis
744 test_ntpath
745 test_openpty
746 test_poll
747 test_popen2
748 test_pty
749 test_pwd
750 test_socketserver
751 test_strop
752 test_sunaudiodev
753 test_sundry
754 test_thread
755 test_threaded_import
756 test_threadedtempfile
757 test_threading
758 test_timing
759 test_unicode_file
760 test_winreg
761 test_winsound
762 """,
763 'darwin':
765 test_al
766 test_bsddb
767 test_bsddb3
768 test_cd
769 test_cl
770 test_curses
771 test_dl
772 test_email_codecs
773 test_gdbm
774 test_gl
775 test_imgfile
776 test_largefile
777 test_linuxaudiodev
778 test_locale
779 test_minidom
780 test_mpz
781 test_nis
782 test_ntpath
783 test_ossaudiodev
784 test_poll
785 test_socketserver
786 test_sunaudiodev
787 test_unicode_file
788 test_winreg
789 test_winsound
790 """,
791 'sunos5':
793 test_al
794 test_bsddb
795 test_cd
796 test_cl
797 test_curses
798 test_dbm
799 test_email_codecs
800 test_gdbm
801 test_gl
802 test_gzip
803 test_imgfile
804 test_linuxaudiodev
805 test_mpz
806 test_openpty
807 test_socketserver
808 test_winreg
809 test_winsound
810 test_zipfile
811 test_zlib
812 """,
813 'hp-ux11':
815 test_al
816 test_bsddb
817 test_cd
818 test_cl
819 test_curses
820 test_dl
821 test_gdbm
822 test_gl
823 test_gzip
824 test_imgfile
825 test_largefile
826 test_linuxaudiodev
827 test_locale
828 test_minidom
829 test_nis
830 test_ntpath
831 test_openpty
832 test_pyexpat
833 test_sax
834 test_socketserver
835 test_sunaudiodev
836 test_unicode_file
837 test_winreg
838 test_winsound
839 test_zipfile
840 test_zlib
841 """,
842 'atheos':
844 test_al
845 test_cd
846 test_cl
847 test_curses
848 test_dl
849 test_email_codecs
850 test_gdbm
851 test_gl
852 test_imgfile
853 test_largefile
854 test_linuxaudiodev
855 test_locale
856 test_mhlib
857 test_mmap
858 test_mpz
859 test_nis
860 test_poll
861 test_popen2
862 test_resource
863 test_socketserver
864 test_sunaudiodev
865 test_unicode_file
866 test_winreg
867 test_winsound
868 """,
869 'cygwin':
871 test_al
872 test_bsddb3
873 test_cd
874 test_cl
875 test_curses
876 test_dbm
877 test_email_codecs
878 test_gl
879 test_imgfile
880 test_largefile
881 test_linuxaudiodev
882 test_locale
883 test_mpz
884 test_nis
885 test_socketserver
886 test_sunaudiodev
887 test_unicode_file
888 test_winreg
889 test_winsound
890 """,
891 'os2emx':
893 test_al
894 test_audioop
895 test_bsddb3
896 test_cd
897 test_cl
898 test_commands
899 test_curses
900 test_dl
901 test_email_codecs
902 test_gl
903 test_iconv_codec
904 test_imgfile
905 test_largefile
906 test_linuxaudiodev
907 test_mhlib
908 test_mmap
909 test_nis
910 test_openpty
911 test_ossaudiodev
912 test_pty
913 test_resource
914 test_signal
915 test_sunaudiodev
916 test_unicode_file
917 test_winreg
918 test_winsound
919 """,
922 class _ExpectedSkips:
923 def __init__(self):
924 import os.path
925 from test import test_normalization
926 from test import test_socket_ssl
928 self.valid = False
929 if sys.platform in _expectations:
930 s = _expectations[sys.platform]
931 self.expected = Set(s.split())
933 if not os.path.supports_unicode_filenames:
934 self.expected.add('test_pep277')
936 if test_normalization.skip_expected:
937 self.expected.add('test_normalization')
939 if test_socket_ssl.skip_expected:
940 self.expected.add('test_socket_ssl')
942 self.valid = True
944 def isvalid(self):
945 "Return true iff _ExpectedSkips knows about the current platform."
946 return self.valid
948 def getexpected(self):
949 """Return set of test names we expect to skip on current platform.
951 self.isvalid() must be true.
954 assert self.isvalid()
955 return self.expected
957 if __name__ == '__main__':
958 # Remove regrtest.py's own directory from the module search path. This
959 # prevents relative imports from working, and relative imports will screw
960 # up the testing framework. E.g. if both test.test_support and
961 # test_support are imported, they will not contain the same globals, and
962 # much of the testing framework relies on the globals in the
963 # test.test_support module.
964 mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
965 i = pathlen = len(sys.path)
966 while i >= 0:
967 i -= 1
968 if os.path.abspath(os.path.normpath(sys.path[i])) == mydir:
969 del sys.path[i]
970 if len(sys.path) == pathlen:
971 print 'Could not find %r in sys.path to remove it' % mydir
972 main()