Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(30404)

Delta Between Two Patch Sets: Lib/test/regrtest.py

Issue 13390: Hunt memory allocations in addition to reference leaks
Left Patch Set: Created 7 years, 10 months ago
Right Patch Set: Created 6 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Include/objimpl.h ('k') | Lib/test/support.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #! /usr/bin/env python3 1 #! /usr/bin/env python3
2 2
3 """ 3 """
4 Usage: 4 Usage:
5 5
6 python -m test [options] [test_name1 [test_name2 ...]] 6 python -m test [options] [test_name1 [test_name2 ...]]
7 python path/to/Lib/test/regrtest.py [options] [test_name1 [test_name2 ...]] 7 python path/to/Lib/test/regrtest.py [options] [test_name1 [test_name2 ...]]
8 8
9 9
10 If no arguments or options are provided, finds all files matching 10 If no arguments or options are provided, finds all files matching
(...skipping 15 matching lines...) Expand all
26 or equals to zero 26 or equals to zero
27 --wait -- wait for user input, e.g., allow a debugger to be attached 27 --wait -- wait for user input, e.g., allow a debugger to be attached
28 28
29 Verbosity 29 Verbosity
30 30
31 -v/--verbose -- run tests in verbose mode with output to stdout 31 -v/--verbose -- run tests in verbose mode with output to stdout
32 -w/--verbose2 -- re-run failed tests in verbose mode 32 -w/--verbose2 -- re-run failed tests in verbose mode
33 -W/--verbose3 -- display test output on failure 33 -W/--verbose3 -- display test output on failure
34 -d/--debug -- print traceback for failed tests 34 -d/--debug -- print traceback for failed tests
35 -q/--quiet -- no output unless one or more tests fail 35 -q/--quiet -- no output unless one or more tests fail
36 -S/--slow -- print the slowest 10 tests 36 -o/--slow -- print the slowest 10 tests
37 --header -- print header with interpreter info 37 --header -- print header with interpreter info
38 38
39 Selecting tests 39 Selecting tests
40 40
41 -r/--random -- randomize test execution order (see below) 41 -r/--random -- randomize test execution order (see below)
42 --randseed -- pass a random seed to reproduce a previous random run 42 --randseed -- pass a random seed to reproduce a previous random run
43 -f/--fromfile -- read names of tests to run from a file (see below) 43 -f/--fromfile -- read names of tests to run from a file (see below)
44 -x/--exclude -- arguments are tests to *exclude* 44 -x/--exclude -- arguments are tests to *exclude*
45 -s/--single -- single step through a set of tests (see below) 45 -s/--single -- single step through a set of tests (see below)
46 -m/--match PAT -- match test cases and methods with glob pattern PAT 46 -m/--match PAT -- match test cases and methods with glob pattern PAT
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 158
159 urlfetch - It is okay to download files required on testing. 159 urlfetch - It is okay to download files required on testing.
160 160
161 gui - Run tests that require a running GUI. 161 gui - Run tests that require a running GUI.
162 162
163 To enable all resources except one, use '-uall,-<resource>'. For 163 To enable all resources except one, use '-uall,-<resource>'. For
164 example, to run all the tests except for the gui tests, give the 164 example, to run all the tests except for the gui tests, give the
165 option '-uall,-gui'. 165 option '-uall,-gui'.
166 """ 166 """
167 167
168 # We import importlib *ASAP* in order to test #15386
169 import importlib
170
168 import builtins 171 import builtins
169 import faulthandler 172 import faulthandler
170 import getopt 173 import getopt
171 import io 174 import io
172 import json 175 import json
173 import logging 176 import logging
174 import os 177 import os
175 import packaging.command
176 import packaging.database
177 import platform 178 import platform
178 import random 179 import random
179 import re 180 import re
181 import shutil
180 import signal 182 import signal
181 import sys 183 import sys
182 import sysconfig 184 import sysconfig
183 import tempfile 185 import tempfile
184 import time 186 import time
185 import traceback 187 import traceback
186 import unittest 188 import unittest
187 import warnings 189 import warnings
188 from inspect import isabstract 190 from inspect import isabstract
189 191
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 signals.append(signal.SIGALRM) 292 signals.append(signal.SIGALRM)
291 if hasattr(signal, 'SIGUSR1'): 293 if hasattr(signal, 'SIGUSR1'):
292 signals.append(signal.SIGUSR1) 294 signals.append(signal.SIGUSR1)
293 for signum in signals: 295 for signum in signals:
294 faulthandler.register(signum, chain=True) 296 faulthandler.register(signum, chain=True)
295 297
296 replace_stdout() 298 replace_stdout()
297 299
298 support.record_original_stdout(sys.stdout) 300 support.record_original_stdout(sys.stdout)
299 try: 301 try:
300 opts, args = getopt.getopt(sys.argv[1:], 'hvqxsSrf:lu:t:TD:NLR:FwWM:nj:G m:', 302 opts, args = getopt.getopt(sys.argv[1:], 'hvqxsoS:rf:lu:t:TD:NLR:FdwWM:n j:Gm:',
301 ['help', 'verbose', 'verbose2', 'verbose3', 'quiet', 303 ['help', 'verbose', 'verbose2', 'verbose3', 'quiet',
302 'exclude', 'single', 'slow', 'random', 'fromfile', 'findleaks', 304 'exclude', 'single', 'slow', 'random', 'fromfile', 'findleaks',
303 'use=', 'threshold=', 'trace', 'coverdir=', 'nocoverdir', 305 'use=', 'threshold=', 'coverdir=', 'nocoverdir',
304 'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=', 306 'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=',
305 'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug', 307 'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug',
306 'start=', 'nowindows', 'header', 'testdir=', 'timeout=', 'wait', 308 'start=', 'nowindows', 'header', 'testdir=', 'timeout=', 'wait',
307 'failfast', 'match']) 309 'failfast', 'match'])
308 except getopt.error as msg: 310 except getopt.error as msg:
309 usage(msg) 311 usage(msg)
310 312
311 # Defaults 313 # Defaults
312 if random_seed is None: 314 if random_seed is None:
313 random_seed = random.randrange(10000000) 315 random_seed = random.randrange(10000000)
(...skipping 18 matching lines...) Expand all
332 failfast = True 334 failfast = True
333 elif o in ('-q', '--quiet'): 335 elif o in ('-q', '--quiet'):
334 quiet = True; 336 quiet = True;
335 verbose = 0 337 verbose = 0
336 elif o in ('-x', '--exclude'): 338 elif o in ('-x', '--exclude'):
337 exclude = True 339 exclude = True
338 elif o in ('-S', '--start'): 340 elif o in ('-S', '--start'):
339 start = a 341 start = a
340 elif o in ('-s', '--single'): 342 elif o in ('-s', '--single'):
341 single = True 343 single = True
342 elif o in ('-S', '--slow'): 344 elif o in ('-o', '--slow'):
343 print_slow = True 345 print_slow = True
344 elif o in ('-r', '--randomize'): 346 elif o in ('-r', '--randomize'):
345 randomize = True 347 randomize = True
346 elif o == '--randseed': 348 elif o == '--randseed':
347 random_seed = int(a) 349 random_seed = int(a)
348 elif o in ('-f', '--fromfile'): 350 elif o in ('-f', '--fromfile'):
349 fromfile = a 351 fromfile = a
350 elif o in ('-m', '--match'): 352 elif o in ('-m', '--match'):
351 match_tests = a 353 match_tests = a
352 elif o in ('-l', '--findleaks'): 354 elif o in ('-l', '--findleaks'):
(...skipping 19 matching lines...) Expand all
372 if not huntrleaks[0]: 374 if not huntrleaks[0]:
373 huntrleaks[0] = 5 375 huntrleaks[0] = 5
374 else: 376 else:
375 huntrleaks[0] = int(huntrleaks[0]) 377 huntrleaks[0] = int(huntrleaks[0])
376 if not huntrleaks[1]: 378 if not huntrleaks[1]:
377 huntrleaks[1] = 4 379 huntrleaks[1] = 4
378 else: 380 else:
379 huntrleaks[1] = int(huntrleaks[1]) 381 huntrleaks[1] = int(huntrleaks[1])
380 if len(huntrleaks) == 2 or not huntrleaks[2]: 382 if len(huntrleaks) == 2 or not huntrleaks[2]:
381 huntrleaks[2:] = ["reflog.txt"] 383 huntrleaks[2:] = ["reflog.txt"]
382 # Avoid false positives due to the character cache in 384 # Avoid false positives due to various caches
383 # stringobject.c filling slowly with random data 385 # filling slowly with random data:
384 warm_char_cache() 386 warm_caches()
385 elif o in ('-M', '--memlimit'): 387 elif o in ('-M', '--memlimit'):
386 support.set_memlimit(a) 388 support.set_memlimit(a)
387 elif o in ('-u', '--use'): 389 elif o in ('-u', '--use'):
388 u = [x.lower() for x in a.split(',')] 390 u = [x.lower() for x in a.split(',')]
389 for r in u: 391 for r in u:
390 if r == 'all': 392 if r == 'all':
391 use_resources[:] = RESOURCE_NAMES 393 use_resources[:] = RESOURCE_NAMES
392 continue 394 continue
393 if r == 'none': 395 if r == 'none':
394 del use_resources[:] 396 del use_resources[:]
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 except (ImportError, NotImplementedError): 433 except (ImportError, NotImplementedError):
432 use_mp = 3 434 use_mp = 3
433 if use_mp == 1: 435 if use_mp == 1:
434 use_mp = None 436 use_mp = None
435 elif o == '--header': 437 elif o == '--header':
436 header = True 438 header = True
437 elif o == '--slaveargs': 439 elif o == '--slaveargs':
438 args, kwargs = json.loads(a) 440 args, kwargs = json.loads(a)
439 try: 441 try:
440 result = runtest(*args, **kwargs) 442 result = runtest(*args, **kwargs)
443 except KeyboardInterrupt:
444 result = INTERRUPTED, ''
441 except BaseException as e: 445 except BaseException as e:
442 result = INTERRUPTED, e.__class__.__name__ 446 traceback.print_exc()
447 result = CHILD_ERROR, str(e)
443 sys.stdout.flush() 448 sys.stdout.flush()
444 print() # Force a newline (just in case) 449 print() # Force a newline (just in case)
445 print(json.dumps(result)) 450 print(json.dumps(result))
446 sys.exit(0) 451 sys.exit(0)
447 elif o == '--testdir': 452 elif o == '--testdir':
448 # CWD is replaced with a temporary dir before calling main(), so we 453 # CWD is replaced with a temporary dir before calling main(), so we
449 # join it with the saved CWD so it ends up where the user expects. 454 # join it with the saved CWD so it ends up where the user expects.
450 testdir = os.path.join(support.SAVEDCWD, a) 455 testdir = os.path.join(support.SAVEDCWD, a)
451 elif o == '--timeout': 456 elif o == '--timeout':
452 if hasattr(faulthandler, 'dump_tracebacks_later'): 457 if hasattr(faulthandler, 'dump_tracebacks_later'):
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 else: 549 else:
545 alltests = findtests(testdir, stdtests, nottests) 550 alltests = findtests(testdir, stdtests, nottests)
546 551
547 selected = tests or args or alltests 552 selected = tests or args or alltests
548 if single: 553 if single:
549 selected = selected[:1] 554 selected = selected[:1]
550 try: 555 try:
551 next_single_test = alltests[alltests.index(selected[0])+1] 556 next_single_test = alltests[alltests.index(selected[0])+1]
552 except IndexError: 557 except IndexError:
553 next_single_test = None 558 next_single_test = None
554 # Remove all the tests that precede start if it's set. 559 # Remove all the selected tests that precede start if it's set.
555 if start: 560 if start:
556 try: 561 try:
557 del tests[:tests.index(start)] 562 del selected[:selected.index(start)]
558 except ValueError: 563 except ValueError:
559 print("Couldn't find starting test (%s), using all tests" % start) 564 print("Couldn't find starting test (%s), using all tests" % start)
560 if randomize: 565 if randomize:
561 random.seed(random_seed) 566 random.seed(random_seed)
562 print("Using random seed", random_seed) 567 print("Using random seed", random_seed)
563 random.shuffle(selected) 568 random.shuffle(selected)
564 if trace: 569 if trace:
565 import trace, tempfile 570 import trace, tempfile
566 tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix, 571 tracer = trace.Trace(ignoredirs=[sys.base_prefix, sys.base_exec_prefix,
567 tempfile.gettempdir()], 572 tempfile.gettempdir()],
568 trace=False, count=True) 573 trace=False, count=True)
569 574
570 test_times = [] 575 test_times = []
571 support.verbose = verbose # Tell tests to be moderately quiet 576 support.verbose = verbose # Tell tests to be moderately quiet
572 support.use_resources = use_resources 577 support.use_resources = use_resources
573 save_modules = sys.modules.keys() 578 save_modules = sys.modules.keys()
574 579
575 def accumulate_result(test, result): 580 def accumulate_result(test, result):
576 ok, test_time = result 581 ok, test_time = result
(...skipping 28 matching lines...) Expand all
605 if use_mp: 610 if use_mp:
606 try: 611 try:
607 from threading import Thread 612 from threading import Thread
608 except ImportError: 613 except ImportError:
609 print("Multiprocess option requires thread support") 614 print("Multiprocess option requires thread support")
610 sys.exit(2) 615 sys.exit(2)
611 from queue import Queue 616 from queue import Queue
612 from subprocess import Popen, PIPE 617 from subprocess import Popen, PIPE
613 debug_output_pat = re.compile(r"\[\d+ refs, \d+ blocks\]$") 618 debug_output_pat = re.compile(r"\[\d+ refs, \d+ blocks\]$")
614 output = Queue() 619 output = Queue()
615 def tests_and_args(): 620 pending = MultiprocessTests(tests)
616 for test in tests:
617 args_tuple = (
618 (test, verbose, quiet),
619 dict(huntrleaks=huntrleaks, use_resources=use_resources,
620 debug=debug, output_on_failure=verbose3,
621 timeout=timeout, failfast=failfast,
622 match_tests=match_tests)
623 )
624 yield (test, args_tuple)
625 pending = tests_and_args()
626 opt_args = support.args_from_interpreter_flags() 621 opt_args = support.args_from_interpreter_flags()
627 base_cmd = [sys.executable] + opt_args + ['-m', 'test.regrtest'] 622 base_cmd = [sys.executable] + opt_args + ['-m', 'test.regrtest']
628 def work(): 623 def work():
629 # A worker thread. 624 # A worker thread.
630 try: 625 try:
631 while True: 626 while True:
632 try: 627 try:
633 test, args_tuple = next(pending) 628 test = next(pending)
634 except StopIteration: 629 except StopIteration:
635 output.put((None, None, None, None)) 630 output.put((None, None, None, None))
636 return 631 return
632 args_tuple = (
633 (test, verbose, quiet),
634 dict(huntrleaks=huntrleaks, use_resources=use_resources,
635 debug=debug, output_on_failure=verbose3,
636 timeout=timeout, failfast=failfast,
637 match_tests=match_tests)
638 )
637 # -E is needed by some tests, e.g. test_import 639 # -E is needed by some tests, e.g. test_import
640 # Running the child from the same working directory ensures
641 # that TEMPDIR for the child is the same when
642 # sysconfig.is_python_build() is true. See issue 15300.
638 popen = Popen(base_cmd + ['--slaveargs', json.dumps(args_tup le)], 643 popen = Popen(base_cmd + ['--slaveargs', json.dumps(args_tup le)],
639 stdout=PIPE, stderr=PIPE, 644 stdout=PIPE, stderr=PIPE,
640 universal_newlines=True, 645 universal_newlines=True,
641 close_fds=(os.name != 'nt')) 646 close_fds=(os.name != 'nt'),
647 cwd=support.SAVEDCWD)
642 stdout, stderr = popen.communicate() 648 stdout, stderr = popen.communicate()
643 retcode = popen.wait() 649 retcode = popen.wait()
644 # Strip last refcount output line if it exists, since it 650 # Strip last refcount output line if it exists, since it
645 # comes from the shutdown of the interpreter in the subcomma nd. 651 # comes from the shutdown of the interpreter in the subcomma nd.
646 stderr = debug_output_pat.sub("", stderr) 652 stderr = debug_output_pat.sub("", stderr)
647 stdout, _, result = stdout.strip().rpartition("\n") 653 stdout, _, result = stdout.strip().rpartition("\n")
648 if retcode != 0: 654 if retcode != 0:
649 result = (CHILD_ERROR, "Exit code %s" % retcode) 655 result = (CHILD_ERROR, "Exit code %s" % retcode)
650 output.put((test, stdout.rstrip(), stderr.rstrip(), resu lt)) 656 output.put((test, stdout.rstrip(), stderr.rstrip(), resu lt))
651 return 657 return
(...skipping 19 matching lines...) Expand all
671 accumulate_result(test, result) 677 accumulate_result(test, result)
672 if not quiet: 678 if not quiet:
673 fmt = "[{1:{0}}{2}/{3}] {4}" if bad else "[{1:{0}}{2}] {4}" 679 fmt = "[{1:{0}}{2}/{3}] {4}" if bad else "[{1:{0}}{2}] {4}"
674 print(fmt.format( 680 print(fmt.format(
675 test_count_width, test_index, test_count, 681 test_count_width, test_index, test_count,
676 len(bad), test)) 682 len(bad), test))
677 if stdout: 683 if stdout:
678 print(stdout) 684 print(stdout)
679 if stderr: 685 if stderr:
680 print(stderr, file=sys.stderr) 686 print(stderr, file=sys.stderr)
687 sys.stdout.flush()
688 sys.stderr.flush()
681 if result[0] == INTERRUPTED: 689 if result[0] == INTERRUPTED:
682 assert result[1] == 'KeyboardInterrupt' 690 raise KeyboardInterrupt
683 raise KeyboardInterrupt # What else?
684 if result[0] == CHILD_ERROR: 691 if result[0] == CHILD_ERROR:
685 raise Exception("Child error on {}: {}".format(test, result[ 1])) 692 raise Exception("Child error on {}: {}".format(test, result[ 1]))
686 test_index += 1 693 test_index += 1
687 except KeyboardInterrupt: 694 except KeyboardInterrupt:
688 interrupted = True 695 interrupted = True
689 pending.close() 696 pending.interrupted = True
690 for worker in workers: 697 for worker in workers:
691 worker.join() 698 worker.join()
692 else: 699 else:
693 for test_index, test in enumerate(tests, 1): 700 for test_index, test in enumerate(tests, 1):
694 if not quiet: 701 if not quiet:
695 fmt = "[{1:{0}}{2}/{3}] {4}" if bad else "[{1:{0}}{2}] {4}" 702 fmt = "[{1:{0}}{2}/{3}] {4}" if bad else "[{1:{0}}{2}] {4}"
696 print(fmt.format( 703 print(fmt.format(
697 test_count_width, test_index, test_count, len(bad), test)) 704 test_count_width, test_index, test_count, len(bad), test))
698 sys.stdout.flush() 705 sys.stdout.flush()
699 if trace: 706 if trace:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 if print_slow: 748 if print_slow:
742 test_times.sort(reverse=True) 749 test_times.sort(reverse=True)
743 print("10 slowest tests:") 750 print("10 slowest tests:")
744 for time, test in test_times[:10]: 751 for time, test in test_times[:10]:
745 print("%s: %.1fs" % (test, time)) 752 print("%s: %.1fs" % (test, time))
746 if bad: 753 if bad:
747 bad = sorted(set(bad) - set(environment_changed)) 754 bad = sorted(set(bad) - set(environment_changed))
748 if bad: 755 if bad:
749 print(count(len(bad), "test"), "failed:") 756 print(count(len(bad), "test"), "failed:")
750 printlist(bad) 757 printlist(bad)
751 if environment_changed: 758 if environment_changed:
752 print("{} altered the execution environment:".format( 759 print("{} altered the execution environment:".format(
753 count(len(environment_changed), "test"))) 760 count(len(environment_changed), "test")))
754 printlist(environment_changed) 761 printlist(environment_changed)
755 if skipped and not quiet: 762 if skipped and not quiet:
756 print(count(len(skipped), "test"), "skipped:") 763 print(count(len(skipped), "test"), "skipped:")
757 printlist(skipped) 764 printlist(skipped)
758
759 e = _ExpectedSkips()
760 plat = sys.platform
761 if e.isvalid():
762 surprise = set(skipped) - e.getexpected() - set(resource_denieds)
763 if surprise:
764 print(count(len(surprise), "skip"), \
765 "unexpected on", plat + ":")
766 printlist(surprise)
767 else:
768 print("Those skips are all expected on", plat + ".")
769 else:
770 print("Ask someone to teach regrtest.py about which tests are")
771 print("expected to get skipped on", plat + ".")
772 765
773 if verbose2 and bad: 766 if verbose2 and bad:
774 print("Re-running failed tests in verbose mode") 767 print("Re-running failed tests in verbose mode")
775 for test in bad: 768 for test in bad:
776 print("Re-running test %r in verbose mode" % test) 769 print("Re-running test %r in verbose mode" % test)
777 sys.stdout.flush() 770 sys.stdout.flush()
778 try: 771 try:
779 verbose = True 772 verbose = True
780 ok = runtest(test, True, quiet, huntrleaks, debug, timeout=timeo ut) 773 ok = runtest(test, True, quiet, huntrleaks, debug, timeout=timeo ut)
781 except KeyboardInterrupt: 774 except KeyboardInterrupt:
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 """Return a list of all applicable test modules.""" 817 """Return a list of all applicable test modules."""
825 testdir = findtestdir(testdir) 818 testdir = findtestdir(testdir)
826 names = os.listdir(testdir) 819 names = os.listdir(testdir)
827 tests = [] 820 tests = []
828 others = set(stdtests) | nottests 821 others = set(stdtests) | nottests
829 for name in names: 822 for name in names:
830 mod, ext = os.path.splitext(name) 823 mod, ext = os.path.splitext(name)
831 if mod[:5] == "test_" and ext in (".py", "") and mod not in others: 824 if mod[:5] == "test_" and ext in (".py", "") and mod not in others:
832 tests.append(mod) 825 tests.append(mod)
833 return stdtests + sorted(tests) 826 return stdtests + sorted(tests)
827
828 # We do not use a generator so multiple threads can call next().
829 class MultiprocessTests(object):
830
831 """A thread-safe iterator over tests for multiprocess mode."""
832
833 def __init__(self, tests):
834 self.interrupted = False
835 self.lock = threading.Lock()
836 self.tests = tests
837
838 def __iter__(self):
839 return self
840
841 def __next__(self):
842 with self.lock:
843 if self.interrupted:
844 raise StopIteration('tests interrupted')
845 return next(self.tests)
834 846
835 def replace_stdout(): 847 def replace_stdout():
836 """Set stdout encoder error handler to backslashreplace (as stderr error 848 """Set stdout encoder error handler to backslashreplace (as stderr error
837 handler) to avoid UnicodeEncodeError when printing a traceback""" 849 handler) to avoid UnicodeEncodeError when printing a traceback"""
838 import atexit 850 import atexit
839 851
840 stdout = sys.stdout 852 stdout = sys.stdout
841 sys.stdout = open(stdout.fileno(), 'w', 853 sys.stdout = open(stdout.fileno(), 'w',
842 encoding=stdout.encoding, 854 encoding=stdout.encoding,
843 errors="backslashreplace", 855 errors="backslashreplace",
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 # 972 #
961 # Note: XXX will have any '.' replaced with '_' characters when determining 973 # Note: XXX will have any '.' replaced with '_' characters when determining
962 # the corresponding method names. 974 # the corresponding method names.
963 975
964 resources = ('sys.argv', 'cwd', 'sys.stdin', 'sys.stdout', 'sys.stderr', 976 resources = ('sys.argv', 'cwd', 'sys.stdin', 'sys.stdout', 'sys.stderr',
965 'os.environ', 'sys.path', 'sys.path_hooks', '__import__', 977 'os.environ', 'sys.path', 'sys.path_hooks', '__import__',
966 'warnings.filters', 'asyncore.socket_map', 978 'warnings.filters', 'asyncore.socket_map',
967 'logging._handlers', 'logging._handlerList', 'sys.gettrace', 979 'logging._handlers', 'logging._handlerList', 'sys.gettrace',
968 'sys.warnoptions', 'threading._dangling', 980 'sys.warnoptions', 'threading._dangling',
969 'multiprocessing.process._dangling', 981 'multiprocessing.process._dangling',
970 'sysconfig._CONFIG_VARS', 'sysconfig._SCHEMES', 982 'sysconfig._CONFIG_VARS', 'sysconfig._INSTALL_SCHEMES',
971 'packaging.command._COMMANDS', 'packaging.database_caches', 983 'support.TESTFN',
972 ) 984 )
973 985
974 def get_sys_argv(self): 986 def get_sys_argv(self):
975 return id(sys.argv), sys.argv, sys.argv[:] 987 return id(sys.argv), sys.argv, sys.argv[:]
976 def restore_sys_argv(self, saved_argv): 988 def restore_sys_argv(self, saved_argv):
977 sys.argv = saved_argv[1] 989 sys.argv = saved_argv[1]
978 sys.argv[:] = saved_argv[2] 990 sys.argv[:] = saved_argv[2]
979 991
980 def get_cwd(self): 992 def get_cwd(self):
981 return os.getcwd() 993 return os.getcwd()
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 def get_asyncore_socket_map(self): 1047 def get_asyncore_socket_map(self):
1036 asyncore = sys.modules.get('asyncore') 1048 asyncore = sys.modules.get('asyncore')
1037 # XXX Making a copy keeps objects alive until __exit__ gets called. 1049 # XXX Making a copy keeps objects alive until __exit__ gets called.
1038 return asyncore and asyncore.socket_map.copy() or {} 1050 return asyncore and asyncore.socket_map.copy() or {}
1039 def restore_asyncore_socket_map(self, saved_map): 1051 def restore_asyncore_socket_map(self, saved_map):
1040 asyncore = sys.modules.get('asyncore') 1052 asyncore = sys.modules.get('asyncore')
1041 if asyncore is not None: 1053 if asyncore is not None:
1042 asyncore.close_all(ignore_all=True) 1054 asyncore.close_all(ignore_all=True)
1043 asyncore.socket_map.update(saved_map) 1055 asyncore.socket_map.update(saved_map)
1044 1056
1057 def get_shutil_archive_formats(self):
1058 # we could call get_archives_formats() but that only returns the
1059 # registry keys; we want to check the values too (the functions that
1060 # are registered)
1061 return shutil._ARCHIVE_FORMATS, shutil._ARCHIVE_FORMATS.copy()
1062 def restore_shutil_archive_formats(self, saved):
1063 shutil._ARCHIVE_FORMATS = saved[0]
1064 shutil._ARCHIVE_FORMATS.clear()
1065 shutil._ARCHIVE_FORMATS.update(saved[1])
1066
1067 def get_shutil_unpack_formats(self):
1068 return shutil._UNPACK_FORMATS, shutil._UNPACK_FORMATS.copy()
1069 def restore_shutil_unpack_formats(self, saved):
1070 shutil._UNPACK_FORMATS = saved[0]
1071 shutil._UNPACK_FORMATS.clear()
1072 shutil._UNPACK_FORMATS.update(saved[1])
1073
1045 def get_logging__handlers(self): 1074 def get_logging__handlers(self):
1046 # _handlers is a WeakValueDictionary 1075 # _handlers is a WeakValueDictionary
1047 return id(logging._handlers), logging._handlers, logging._handlers.copy( ) 1076 return id(logging._handlers), logging._handlers, logging._handlers.copy( )
1048 def restore_logging__handlers(self, saved_handlers): 1077 def restore_logging__handlers(self, saved_handlers):
1049 # Can't easily revert the logging state 1078 # Can't easily revert the logging state
1050 pass 1079 pass
1051 1080
1052 def get_logging__handlerList(self): 1081 def get_logging__handlerList(self):
1053 # _handlerList is a list of weakrefs to handlers 1082 # _handlerList is a list of weakrefs to handlers
1054 return id(logging._handlerList), logging._handlerList, logging._handlerL ist[:] 1083 return id(logging._handlerList), logging._handlerList, logging._handlerL ist[:]
1055 def restore_logging__handlerList(self, saved_handlerList): 1084 def restore_logging__handlerList(self, saved_handlerList):
1056 # Can't easily revert the logging state 1085 # Can't easily revert the logging state
1057 pass 1086 pass
1058
1059 def get_packaging_command__COMMANDS(self):
1060 # registry mapping command names to full dotted path or to the actual
1061 # class (resolved on demand); this check only looks at the names, not
1062 # the types of the values (IOW, if a value changes from a string
1063 # (dotted path) to a class it's okay but if a key (i.e. command class)
1064 # is added we complain)
1065 id_ = id(packaging.command._COMMANDS)
1066 keys = set(packaging.command._COMMANDS)
1067 return id_, keys
1068 def restore_packaging_command__COMMANDS(self, saved):
1069 # if command._COMMANDS was bound to another dict obhect, we can't
1070 # restore the previous object and contents, because the get_ method
1071 # above does not return the dict object (to ignore changes in values)
1072 for key in packaging.command._COMMANDS.keys() - saved[1]:
1073 del packaging.command._COMMANDS[key]
1074
1075 def get_packaging_database_caches(self):
1076 # caching system used by the PEP 376 implementation
1077 # we have one boolean and four dictionaries, initially empty
1078 switch = packaging.database._cache_enabled
1079 saved = []
1080 for name in ('_cache_name', '_cache_name_egg',
1081 '_cache_path', '_cache_path_egg'):
1082 cache = getattr(packaging.database, name)
1083 saved.append((id(cache), cache, cache.copy()))
1084 return switch, saved
1085 def restore_packaging_database_caches(self, saved):
1086 switch, saved_caches = saved
1087 packaging.database._cache_enabled = switch
1088 for offset, name in enumerate(('_cache_name', '_cache_name_egg',
1089 '_cache_path', '_cache_path_egg')):
1090 _, cache, items = saved_caches[offset]
1091 # put back the same object in place
1092 setattr(packaging.database, name, cache)
1093 # now restore its items
1094 cache.clear()
1095 cache.update(items)
1096 1087
1097 def get_sys_warnoptions(self): 1088 def get_sys_warnoptions(self):
1098 return id(sys.warnoptions), sys.warnoptions, sys.warnoptions[:] 1089 return id(sys.warnoptions), sys.warnoptions, sys.warnoptions[:]
1099 def restore_sys_warnoptions(self, saved_options): 1090 def restore_sys_warnoptions(self, saved_options):
1100 sys.warnoptions = saved_options[1] 1091 sys.warnoptions = saved_options[1]
1101 sys.warnoptions[:] = saved_options[2] 1092 sys.warnoptions[:] = saved_options[2]
1102 1093
1103 # Controlling dangling references to Thread objects can make it easier 1094 # Controlling dangling references to Thread objects can make it easier
1104 # to track reference leaks. 1095 # to track reference leaks.
1105 def get_threading__dangling(self): 1096 def get_threading__dangling(self):
(...skipping 22 matching lines...) Expand all
1128 def get_sysconfig__CONFIG_VARS(self): 1119 def get_sysconfig__CONFIG_VARS(self):
1129 # make sure the dict is initialized 1120 # make sure the dict is initialized
1130 sysconfig.get_config_var('prefix') 1121 sysconfig.get_config_var('prefix')
1131 return (id(sysconfig._CONFIG_VARS), sysconfig._CONFIG_VARS, 1122 return (id(sysconfig._CONFIG_VARS), sysconfig._CONFIG_VARS,
1132 dict(sysconfig._CONFIG_VARS)) 1123 dict(sysconfig._CONFIG_VARS))
1133 def restore_sysconfig__CONFIG_VARS(self, saved): 1124 def restore_sysconfig__CONFIG_VARS(self, saved):
1134 sysconfig._CONFIG_VARS = saved[1] 1125 sysconfig._CONFIG_VARS = saved[1]
1135 sysconfig._CONFIG_VARS.clear() 1126 sysconfig._CONFIG_VARS.clear()
1136 sysconfig._CONFIG_VARS.update(saved[2]) 1127 sysconfig._CONFIG_VARS.update(saved[2])
1137 1128
1138 def get_sysconfig__SCHEMES(self): 1129 def get_sysconfig__INSTALL_SCHEMES(self):
1139 # it's mildly evil to look at the internal attribute, but it's easier 1130 return (id(sysconfig._INSTALL_SCHEMES), sysconfig._INSTALL_SCHEMES,
1140 # than copying a RawConfigParser object 1131 sysconfig._INSTALL_SCHEMES.copy())
1141 return (id(sysconfig._SCHEMES), sysconfig._SCHEMES._sections, 1132 def restore_sysconfig__INSTALL_SCHEMES(self, saved):
1142 sysconfig._SCHEMES._sections.copy()) 1133 sysconfig._INSTALL_SCHEMES = saved[1]
1143 def restore_sysconfig__SCHEMES(self, saved): 1134 sysconfig._INSTALL_SCHEMES.clear()
1144 sysconfig._SCHEMES._sections = saved[1] 1135 sysconfig._INSTALL_SCHEMES.update(saved[2])
1145 sysconfig._SCHEMES._sections.clear() 1136
1146 sysconfig._SCHEMES._sections.update(saved[2]) 1137 def get_support_TESTFN(self):
1147 1138 if os.path.isfile(support.TESTFN):
1139 result = 'f'
1140 elif os.path.isdir(support.TESTFN):
1141 result = 'd'
1142 else:
1143 result = None
1144 return result
1145 def restore_support_TESTFN(self, saved_value):
1146 if saved_value is None:
1147 if os.path.isfile(support.TESTFN):
1148 os.unlink(support.TESTFN)
1149 elif os.path.isdir(support.TESTFN):
1150 shutil.rmtree(support.TESTFN)
1148 1151
1149 def resource_info(self): 1152 def resource_info(self):
1150 for name in self.resources: 1153 for name in self.resources:
1151 method_suffix = name.replace('.', '_') 1154 method_suffix = name.replace('.', '_')
1152 get_name = 'get_' + method_suffix 1155 get_name = 'get_' + method_suffix
1153 restore_name = 'restore_' + method_suffix 1156 restore_name = 'restore_' + method_suffix
1154 yield name, getattr(self, get_name), getattr(self, restore_name) 1157 yield name, getattr(self, get_name), getattr(self, restore_name)
1155 1158
1156 def __enter__(self): 1159 def __enter__(self):
1157 self.saved_values = dict((name, get()) for name, get, restore 1160 self.saved_values = dict((name, get()) for name, get, restore
(...skipping 28 matching lines...) Expand all
1186 test_time = 0.0 1189 test_time = 0.0
1187 refleak = False # True if the test leaked references. 1190 refleak = False # True if the test leaked references.
1188 try: 1191 try:
1189 if test.startswith('test.'): 1192 if test.startswith('test.'):
1190 abstest = test 1193 abstest = test
1191 else: 1194 else:
1192 # Always import it from the test package 1195 # Always import it from the test package
1193 abstest = 'test.' + test 1196 abstest = 'test.' + test
1194 with saved_test_environment(test, verbose, quiet) as environment: 1197 with saved_test_environment(test, verbose, quiet) as environment:
1195 start_time = time.time() 1198 start_time = time.time()
1196 the_package = __import__(abstest, globals(), locals(), []) 1199 the_module = importlib.import_module(abstest)
1197 the_module = getattr(the_package, test) 1200 # If the test has a test_main, that will run the appropriate
1198 # Old tests run to completion simply as a side-effect of 1201 # tests. If not, use normal unittest test loading.
1199 # being imported. For tests based on unittest or doctest, 1202 test_runner = getattr(the_module, "test_main", None)
1200 # explicitly invoke their test_main() function (if it exists). 1203 if test_runner is None:
1201 indirect_test = getattr(the_module, "test_main", None) 1204 tests = unittest.TestLoader().loadTestsFromModule(the_module)
1202 if indirect_test is not None: 1205 test_runner = lambda: support.run_unittest(tests)
1203 indirect_test() 1206 test_runner()
1204 if huntrleaks: 1207 if huntrleaks:
1205 refleak = dash_R(the_module, test, indirect_test, 1208 refleak = dash_R(the_module, test, test_runner,
1206 huntrleaks) 1209 huntrleaks)
1207 test_time = time.time() - start_time 1210 test_time = time.time() - start_time
1208 except support.ResourceDenied as msg: 1211 except support.ResourceDenied as msg:
1209 if not quiet: 1212 if not quiet:
1210 print(test, "skipped --", msg) 1213 print(test, "skipped --", msg)
1211 sys.stdout.flush() 1214 sys.stdout.flush()
1212 return RESOURCE_DENIED, test_time 1215 return RESOURCE_DENIED, test_time
1213 except unittest.SkipTest as msg: 1216 except unittest.SkipTest as msg:
1214 if not quiet: 1217 if not quiet:
1215 print(test, "skipped --", msg) 1218 print(test, "skipped --", msg)
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 nwarmup, ntracked, fname = huntrleaks 1323 nwarmup, ntracked, fname = huntrleaks
1321 fname = os.path.join(support.SAVEDCWD, fname) 1324 fname = os.path.join(support.SAVEDCWD, fname)
1322 repcount = nwarmup + ntracked 1325 repcount = nwarmup + ntracked
1323 rc_deltas = [0] * repcount 1326 rc_deltas = [0] * repcount
1324 alloc_deltas = [0] * repcount 1327 alloc_deltas = [0] * repcount
1325 1328
1326 print("beginning", repcount, "repetitions", file=sys.stderr) 1329 print("beginning", repcount, "repetitions", file=sys.stderr)
1327 print(("1234567890"*(repcount//10 + 1))[:repcount], file=sys.stderr) 1330 print(("1234567890"*(repcount//10 + 1))[:repcount], file=sys.stderr)
1328 sys.stderr.flush() 1331 sys.stderr.flush()
1329 for i in range(repcount): 1332 for i in range(repcount):
1330 alloc_before, rc_before = dash_R_cleanup(fs, ps, pic, zdc, abcs)
1331 run_the_test() 1333 run_the_test()
1332 alloc_after, rc_after = dash_R_cleanup(fs, ps, pic, zdc, abcs) 1334 alloc_after, rc_after = dash_R_cleanup(fs, ps, pic, zdc, abcs)
1333 sys.stderr.write('.') 1335 sys.stderr.write('.')
1334 sys.stderr.flush() 1336 sys.stderr.flush()
1335 if i >= nwarmup: 1337 if i >= nwarmup:
1336 rc_deltas[i] = rc_after - rc_before 1338 rc_deltas[i] = rc_after - rc_before
1337 alloc_deltas[i] = alloc_after - alloc_before 1339 alloc_deltas[i] = alloc_after - alloc_before
1340 alloc_before, rc_before = alloc_after, rc_after
1338 print(file=sys.stderr) 1341 print(file=sys.stderr)
1339 ret = False 1342 # These checkers return False on success, True on failure
1340 for deltas, item_name in [ 1343 def check_rc_deltas(deltas):
1341 (rc_deltas, 'references'), (alloc_deltas, 'memory blocks')]: 1344 return any(deltas)
1342 if any(deltas): 1345 def check_alloc_deltas(deltas):
1346 # At least 1/3rd of 0s
1347 if 3 * deltas.count(0) < len(deltas):
1348 return True
1349 # Nothing else than 1s, 0s and -1s
1350 if not set(deltas) <= {1,0,-1}:
1351 return True
1352 return False
1353 failed = False
1354 for deltas, item_name, checker in [
1355 (rc_deltas, 'references', check_rc_deltas),
1356 (alloc_deltas, 'memory blocks', check_alloc_deltas)]:
1357 if checker(deltas):
1343 msg = '%s leaked %s %s, sum=%s' % ( 1358 msg = '%s leaked %s %s, sum=%s' % (
1344 test, deltas[nwarmup:], item_name, sum(deltas)) 1359 test, deltas[nwarmup:], item_name, sum(deltas))
1345 print(msg, file=sys.stderr) 1360 print(msg, file=sys.stderr)
1346 sys.stderr.flush() 1361 sys.stderr.flush()
1347 with open(fname, "a") as refrep: 1362 with open(fname, "a") as refrep:
1348 print(msg, file=refrep) 1363 print(msg, file=refrep)
1349 refrep.flush() 1364 refrep.flush()
1350 ret = True 1365 failed = True
1351 return ret 1366 return failed
1352 1367
1353 def dash_R_cleanup(fs, ps, pic, zdc, abcs): 1368 def dash_R_cleanup(fs, ps, pic, zdc, abcs):
1354 import gc, copyreg 1369 import gc, copyreg
1355 import _strptime, linecache 1370 import _strptime, linecache
1356 import urllib.parse, urllib.request, mimetypes, doctest 1371 import urllib.parse, urllib.request, mimetypes, doctest
1357 import struct, filecmp, collections.abc 1372 import struct, filecmp, collections.abc
1358 from distutils.dir_util import _path_created 1373 from distutils.dir_util import _path_created
1359 from weakref import WeakSet 1374 from weakref import WeakSet
1360 1375
1361 # Clear the warnings registry, so they can be displayed again 1376 # Clear the warnings registry, so they can be displayed again
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 _path_created.clear() 1414 _path_created.clear()
1400 re.purge() 1415 re.purge()
1401 _strptime._regex_cache.clear() 1416 _strptime._regex_cache.clear()
1402 urllib.parse.clear_cache() 1417 urllib.parse.clear_cache()
1403 urllib.request.urlcleanup() 1418 urllib.request.urlcleanup()
1404 linecache.clearcache() 1419 linecache.clearcache()
1405 mimetypes._default_mime_types() 1420 mimetypes._default_mime_types()
1406 filecmp._cache.clear() 1421 filecmp._cache.clear()
1407 struct._clearcache() 1422 struct._clearcache()
1408 doctest.master = None 1423 doctest.master = None
1424 try:
1425 import ctypes
1426 except ImportError:
1427 # Don't worry about resetting the cache if ctypes is not supported
1428 pass
1429 else:
1430 ctypes._reset_cache()
1409 1431
1410 # Collect cyclic trash and read memory statistics immediately after. 1432 # Collect cyclic trash and read memory statistics immediately after.
1411 func1 = sys.getallocatedblocks 1433 func1 = sys.getallocatedblocks
1412 func2 = sys.gettotalrefcount 1434 func2 = sys.gettotalrefcount
1413 gc.collect() 1435 gc.collect()
1414 return func1(), func2() 1436 return func1(), func2()
1415 1437
1416 def warm_char_cache(): 1438 def warm_caches():
1439 # char cache
1417 s = bytes(range(256)) 1440 s = bytes(range(256))
1418 for i in range(256): 1441 for i in range(256):
1419 s[i:i+1] 1442 s[i:i+1]
1443 # unicode cache
1444 x = [chr(i) for i in range(256)]
1445 # int cache
1446 x = list(range(-5, 257))
1420 1447
1421 def findtestdir(path=None): 1448 def findtestdir(path=None):
1422 return path or os.path.dirname(__file__) or os.curdir 1449 return path or os.path.dirname(__file__) or os.curdir
1423 1450
1424 def removepy(names): 1451 def removepy(names):
1425 if not names: 1452 if not names:
1426 return 1453 return
1427 for idx, name in enumerate(names): 1454 for idx, name in enumerate(names):
1428 basename, ext = os.path.splitext(name) 1455 basename, ext = os.path.splitext(name)
1429 if ext == '.py': 1456 if ext == '.py':
(...skipping 12 matching lines...) Expand all
1442 Optional arg indent (default 4) is the number of blanks with which to 1469 Optional arg indent (default 4) is the number of blanks with which to
1443 begin each line. 1470 begin each line.
1444 """ 1471 """
1445 1472
1446 from textwrap import fill 1473 from textwrap import fill
1447 blanks = ' ' * indent 1474 blanks = ' ' * indent
1448 # Print the sorted list: 'x' may be a '--random' list or a set() 1475 # Print the sorted list: 'x' may be a '--random' list or a set()
1449 print(fill(' '.join(str(elt) for elt in sorted(x)), width, 1476 print(fill(' '.join(str(elt) for elt in sorted(x)), width,
1450 initial_indent=blanks, subsequent_indent=blanks)) 1477 initial_indent=blanks, subsequent_indent=blanks))
1451 1478
1452 # Map sys.platform to a string containing the basenames of tests
1453 # expected to be skipped on that platform.
1454 #
1455 # Special cases:
1456 # test_pep277
1457 # The _ExpectedSkips constructor adds this to the set of expected
1458 # skips if not os.path.supports_unicode_filenames.
1459 # test_timeout
1460 # Controlled by test_timeout.skip_expected. Requires the network
1461 # resource and a socket module.
1462 #
1463 # Tests that are expected to be skipped everywhere except on one platform
1464 # are also handled separately.
1465
1466 _expectations = (
1467 ('win32',
1468 """
1469 test__locale
1470 test_crypt
1471 test_curses
1472 test_dbm
1473 test_fcntl
1474 test_fork1
1475 test_epoll
1476 test_dbm_gnu
1477 test_dbm_ndbm
1478 test_grp
1479 test_ioctl
1480 test_largefile
1481 test_kqueue
1482 test_openpty
1483 test_ossaudiodev
1484 test_pipes
1485 test_poll
1486 test_posix
1487 test_pty
1488 test_pwd
1489 test_resource
1490 test_signal
1491 test_syslog
1492 test_threadsignals
1493 test_wait3
1494 test_wait4
1495 """),
1496 ('linux',
1497 """
1498 test_curses
1499 test_largefile
1500 test_kqueue
1501 test_ossaudiodev
1502 """),
1503 ('unixware',
1504 """
1505 test_epoll
1506 test_largefile
1507 test_kqueue
1508 test_minidom
1509 test_openpty
1510 test_pyexpat
1511 test_sax
1512 test_sundry
1513 """),
1514 ('openunix',
1515 """
1516 test_epoll
1517 test_largefile
1518 test_kqueue
1519 test_minidom
1520 test_openpty
1521 test_pyexpat
1522 test_sax
1523 test_sundry
1524 """),
1525 ('sco_sv',
1526 """
1527 test_asynchat
1528 test_fork1
1529 test_epoll
1530 test_gettext
1531 test_largefile
1532 test_locale
1533 test_kqueue
1534 test_minidom
1535 test_openpty
1536 test_pyexpat
1537 test_queue
1538 test_sax
1539 test_sundry
1540 test_thread
1541 test_threaded_import
1542 test_threadedtempfile
1543 test_threading
1544 """),
1545 ('darwin',
1546 """
1547 test__locale
1548 test_curses
1549 test_epoll
1550 test_dbm_gnu
1551 test_gdb
1552 test_largefile
1553 test_locale
1554 test_minidom
1555 test_ossaudiodev
1556 test_poll
1557 """),
1558 ('sunos',
1559 """
1560 test_curses
1561 test_dbm
1562 test_epoll
1563 test_kqueue
1564 test_dbm_gnu
1565 test_gzip
1566 test_openpty
1567 test_zipfile
1568 test_zlib
1569 """),
1570 ('hp-ux',
1571 """
1572 test_curses
1573 test_epoll
1574 test_dbm_gnu
1575 test_gzip
1576 test_largefile
1577 test_locale
1578 test_kqueue
1579 test_minidom
1580 test_openpty
1581 test_pyexpat
1582 test_sax
1583 test_zipfile
1584 test_zlib
1585 """),
1586 ('cygwin',
1587 """
1588 test_curses
1589 test_dbm
1590 test_epoll
1591 test_ioctl
1592 test_kqueue
1593 test_largefile
1594 test_locale
1595 test_ossaudiodev
1596 test_socketserver
1597 """),
1598 ('os2emx',
1599 """
1600 test_audioop
1601 test_curses
1602 test_epoll
1603 test_kqueue
1604 test_largefile
1605 test_mmap
1606 test_openpty
1607 test_ossaudiodev
1608 test_pty
1609 test_resource
1610 test_signal
1611 """),
1612 ('freebsd',
1613 """
1614 test_epoll
1615 test_dbm_gnu
1616 test_locale
1617 test_ossaudiodev
1618 test_pep277
1619 test_pty
1620 test_socketserver
1621 test_tcl
1622 test_tk
1623 test_ttk_guionly
1624 test_ttk_textonly
1625 test_timeout
1626 test_urllibnet
1627 test_multiprocessing
1628 """),
1629 ('aix',
1630 """
1631 test_bz2
1632 test_epoll
1633 test_dbm_gnu
1634 test_gzip
1635 test_kqueue
1636 test_ossaudiodev
1637 test_tcl
1638 test_tk
1639 test_ttk_guionly
1640 test_ttk_textonly
1641 test_zipimport
1642 test_zlib
1643 """),
1644 ('openbsd',
1645 """
1646 test_ctypes
1647 test_epoll
1648 test_dbm_gnu
1649 test_locale
1650 test_normalization
1651 test_ossaudiodev
1652 test_pep277
1653 test_tcl
1654 test_tk
1655 test_ttk_guionly
1656 test_ttk_textonly
1657 test_multiprocessing
1658 """),
1659 ('netbsd',
1660 """
1661 test_ctypes
1662 test_curses
1663 test_epoll
1664 test_dbm_gnu
1665 test_locale
1666 test_ossaudiodev
1667 test_pep277
1668 test_tcl
1669 test_tk
1670 test_ttk_guionly
1671 test_ttk_textonly
1672 test_multiprocessing
1673 """),
1674 )
1675
1676 class _ExpectedSkips:
1677 def __init__(self):
1678 import os.path
1679 from test import test_timeout
1680
1681 self.valid = False
1682 expected = None
1683 for item in _expectations:
1684 if sys.platform.startswith(item[0]):
1685 expected = item[1]
1686 break
1687 if expected is not None:
1688 self.expected = set(expected.split())
1689
1690 # These are broken tests, for now skipped on every platform.
1691 # XXX Fix these!
1692 self.expected.add('test_nis')
1693
1694 # expected to be skipped on every platform, even Linux
1695 if not os.path.supports_unicode_filenames:
1696 self.expected.add('test_pep277')
1697
1698 # doctest, profile and cProfile tests fail when the codec for the
1699 # fs encoding isn't built in because PyUnicode_Decode() adds two
1700 # calls into Python.
1701 encs = ("utf-8", "latin-1", "ascii", "mbcs", "utf-16", "utf-32")
1702 if sys.getfilesystemencoding().lower() not in encs:
1703 self.expected.add('test_profile')
1704 self.expected.add('test_cProfile')
1705 self.expected.add('test_doctest')
1706
1707 if test_timeout.skip_expected:
1708 self.expected.add('test_timeout')
1709
1710 if sys.platform != "win32":
1711 # test_sqlite is only reliable on Windows where the library
1712 # is distributed with Python
1713 WIN_ONLY = {"test_unicode_file", "test_winreg",
1714 "test_winsound", "test_startfile",
1715 "test_sqlite", "test_msilib"}
1716 self.expected |= WIN_ONLY
1717
1718 if sys.platform != 'sunos5':
1719 self.expected.add('test_nis')
1720
1721 if support.python_is_optimized():
1722 self.expected.add("test_gdb")
1723
1724 self.valid = True
1725
1726 def isvalid(self):
1727 "Return true iff _ExpectedSkips knows about the current platform."
1728 return self.valid
1729
1730 def getexpected(self):
1731 """Return set of test names we expect to skip on current platform.
1732
1733 self.isvalid() must be true.
1734 """
1735
1736 assert self.isvalid()
1737 return self.expected
1738 1479
1739 def _make_temp_dir_for_build(TEMPDIR): 1480 def _make_temp_dir_for_build(TEMPDIR):
1740 # When tests are run from the Python build directory, it is best practice 1481 # When tests are run from the Python build directory, it is best practice
1741 # to keep the test files in a subfolder. It eases the cleanup of leftover 1482 # to keep the test files in a subfolder. It eases the cleanup of leftover
1742 # files using command "make distclean". 1483 # files using command "make distclean".
1743 if sysconfig.is_python_build(): 1484 if sysconfig.is_python_build():
1744 TEMPDIR = os.path.join(sysconfig.get_config_var('srcdir'), 'build') 1485 TEMPDIR = os.path.join(sysconfig.get_config_var('srcdir'), 'build')
1745 TEMPDIR = os.path.abspath(TEMPDIR) 1486 TEMPDIR = os.path.abspath(TEMPDIR)
1746 try: 1487 try:
1747 os.mkdir(TEMPDIR) 1488 os.mkdir(TEMPDIR)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1779 assert __file__ == os.path.abspath(sys.argv[0]) 1520 assert __file__ == os.path.abspath(sys.argv[0])
1780 1521
1781 TEMPDIR, TESTCWD = _make_temp_dir_for_build(TEMPDIR) 1522 TEMPDIR, TESTCWD = _make_temp_dir_for_build(TEMPDIR)
1782 1523
1783 # Run the tests in a context manager that temporary changes the CWD to a 1524 # Run the tests in a context manager that temporary changes the CWD to a
1784 # temporary and writable directory. If it's not possible to create or 1525 # temporary and writable directory. If it's not possible to create or
1785 # change the CWD, the original CWD will be used. The original CWD is 1526 # change the CWD, the original CWD will be used. The original CWD is
1786 # available from support.SAVEDCWD. 1527 # available from support.SAVEDCWD.
1787 with support.temp_cwd(TESTCWD, quiet=True): 1528 with support.temp_cwd(TESTCWD, quiet=True):
1788 main() 1529 main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+