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

Side by Side Diff: Lib/test/regrtest.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 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:
View unified diff | Download patch
« no previous file with comments | « Lib/test/data/README ('k') | Lib/test/support.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 matching lines...) Expand all
23 --timeout TIMEOUT 23 --timeout TIMEOUT
24 -- dump the traceback and exit if a test takes more 24 -- dump the traceback and exit if a test takes more
25 than TIMEOUT seconds; disabled if TIMEOUT is negative 25 than TIMEOUT seconds; disabled if TIMEOUT is negative
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 -- re-run failed tests in verbose mode immediately
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 -S/--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 -G/--failfast -- fail as soon as a test fails (only with -v or -W)
47 -u/--use RES1,RES2,... 46 -u/--use RES1,RES2,...
48 -- specify which special resource intensive tests to run 47 -- specify which special resource intensive tests to run
49 -M/--memlimit LIMIT 48 -M/--memlimit LIMIT
50 -- run very large memory-consuming tests 49 -- run very large memory-consuming tests
51 --testdir DIR 50 --testdir DIR
52 -- execute test files in the specified directory (instead 51 -- execute test files in the specified directory (instead
53 of the Python stdlib test suite) 52 of the Python stdlib test suite)
54 53
55 Special runs 54 Special runs
56 55
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 urlfetch - It is okay to download files required on testing. 155 urlfetch - It is okay to download files required on testing.
157 156
158 gui - Run tests that require a running GUI. 157 gui - Run tests that require a running GUI.
159 158
160 To enable all resources except one, use '-uall,-<resource>'. For 159 To enable all resources except one, use '-uall,-<resource>'. For
161 example, to run all the tests except for the gui tests, give the 160 example, to run all the tests except for the gui tests, give the
162 option '-uall,-gui'. 161 option '-uall,-gui'.
163 """ 162 """
164 163
165 import builtins 164 import builtins
166 import errno
167 import faulthandler 165 import faulthandler
168 import getopt 166 import getopt
169 import io
170 import json 167 import json
171 import logging
172 import os 168 import os
173 import platform
174 import random 169 import random
175 import re 170 import re
176 import signal 171 import io
177 import sys 172 import sys
173 import time
174 import errno
175 import traceback
176 import warnings
177 import unittest
178 from inspect import isabstract
179 import tempfile
180 import platform
178 import sysconfig 181 import sysconfig
179 import tempfile 182 import logging
180 import time
181 import traceback
182 import unittest
183 import warnings
184 from inspect import isabstract
185
186 try:
187 import threading
188 except ImportError:
189 threading = None
190 try:
191 import multiprocessing.process
192 except ImportError:
193 multiprocessing = None
194 183
195 184
196 # Some times __path__ and __file__ are not absolute (e.g. while running from 185 # Some times __path__ and __file__ are not absolute (e.g. while running from
197 # Lib/) and, if we change the CWD to run the tests in a temporary dir, some 186 # Lib/) and, if we change the CWD to run the tests in a temporary dir, some
198 # imports might fail. This affects only the modules imported before os.chdir(). 187 # imports might fail. This affects only the modules imported before os.chdir().
199 # These modules are searched first in sys.path[0] (so '' -- the CWD) and if 188 # These modules are searched first in sys.path[0] (so '' -- the CWD) and if
200 # they are found in the CWD their __file__ and __path__ will be relative (this 189 # they are found in the CWD their __file__ and __path__ will be relative (this
201 # happens before the chdir). All the modules imported after the chdir, are 190 # happens before the chdir). All the modules imported after the chdir, are
202 # not found in the CWD, and since the other paths in sys.path[1:] are absolute 191 # not found in the CWD, and since the other paths in sys.path[1:] are absolute
203 # (site.py absolutize them), the __file__ and __path__ will be absolute too. 192 # (site.py absolutize them), the __file__ and __path__ will be absolute too.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 print(msg, file=sys.stderr) 235 print(msg, file=sys.stderr)
247 print("Use --help for usage", file=sys.stderr) 236 print("Use --help for usage", file=sys.stderr)
248 sys.exit(2) 237 sys.exit(2)
249 238
250 239
251 def main(tests=None, testdir=None, verbose=0, quiet=False, 240 def main(tests=None, testdir=None, verbose=0, quiet=False,
252 exclude=False, single=False, randomize=False, fromfile=None, 241 exclude=False, single=False, randomize=False, fromfile=None,
253 findleaks=False, use_resources=None, trace=False, coverdir='coverage', 242 findleaks=False, use_resources=None, trace=False, coverdir='coverage',
254 runleaks=False, huntrleaks=False, verbose2=False, print_slow=False, 243 runleaks=False, huntrleaks=False, verbose2=False, print_slow=False,
255 random_seed=None, use_mp=None, verbose3=False, forever=False, 244 random_seed=None, use_mp=None, verbose3=False, forever=False,
256 header=False, failfast=False): 245 header=False):
257 """Execute a test suite. 246 """Execute a test suite.
258 247
259 This also parses command-line options and modifies its behavior 248 This also parses command-line options and modifies its behavior
260 accordingly. 249 accordingly.
261 250
262 tests -- a list of strings containing test names (optional) 251 tests -- a list of strings containing test names (optional)
263 testdir -- the directory in which to look for tests (optional) 252 testdir -- the directory in which to look for tests (optional)
264 253
265 Users other than the Python test suite will certainly want to 254 Users other than the Python test suite will certainly want to
266 specify testdir; if it's omitted, the directory containing the 255 specify testdir; if it's omitted, the directory containing the
267 Python test suite is searched for. 256 Python test suite is searched for.
268 257
269 If the tests argument is omitted, the tests listed on the 258 If the tests argument is omitted, the tests listed on the
270 command-line will be used. If that's empty, too, then all *.py 259 command-line will be used. If that's empty, too, then all *.py
271 files beginning with test_ will be used. 260 files beginning with test_ will be used.
272 261
273 The other default arguments (verbose, quiet, exclude, 262 The other default arguments (verbose, quiet, exclude,
274 single, randomize, findleaks, use_resources, trace, coverdir, 263 single, randomize, findleaks, use_resources, trace, coverdir,
275 print_slow, and random_seed) allow programmers calling main() 264 print_slow, and random_seed) allow programmers calling main()
276 directly to set the values that would normally be set by flags 265 directly to set the values that would normally be set by flags
277 on the command line. 266 on the command line.
278 """ 267 """
279 268
280 # Display the Python traceback on fatal errors (e.g. segfault) 269 # Display the Python traceback fatal errors (e.g. segfault)
281 faulthandler.enable(all_threads=True) 270 faulthandler.enable(all_threads=True)
282
283 # Display the Python traceback on SIGALRM or SIGUSR1 signal
284 signals = []
285 if hasattr(signal, 'SIGALRM'):
286 signals.append(signal.SIGALRM)
287 if hasattr(signal, 'SIGUSR1'):
288 signals.append(signal.SIGUSR1)
289 for signum in signals:
290 faulthandler.register(signum, chain=True)
291 271
292 replace_stdout() 272 replace_stdout()
293 273
294 support.record_original_stdout(sys.stdout) 274 support.record_original_stdout(sys.stdout)
295 try: 275 try:
296 opts, args = getopt.getopt(sys.argv[1:], 'hvqxsSrf:lu:t:TD:NLR:FwWM:nj:G ', 276 opts, args = getopt.getopt(sys.argv[1:], 'hvqxsSrf:lu:t:TD:NLR:FwWM:nj:' ,
297 ['help', 'verbose', 'verbose2', 'verbose3', 'quiet', 277 ['help', 'verbose', 'verbose2', 'verbose3', 'quiet',
298 'exclude', 'single', 'slow', 'random', 'fromfile', 'findleaks', 278 'exclude', 'single', 'slow', 'random', 'fromfile', 'findleaks',
299 'use=', 'threshold=', 'trace', 'coverdir=', 'nocoverdir', 279 'use=', 'threshold=', 'trace', 'coverdir=', 'nocoverdir',
300 'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=', 280 'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=',
301 'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug', 281 'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug',
302 'start=', 'nowindows', 'header', 'testdir=', 'timeout=', 'wait', 282 'start=', 'nowindows', 'header', 'testdir=', 'timeout=', 'wait'])
303 'failfast'])
304 except getopt.error as msg: 283 except getopt.error as msg:
305 usage(msg) 284 usage(msg)
306 285
307 # Defaults 286 # Defaults
308 if random_seed is None: 287 if random_seed is None:
309 random_seed = random.randrange(10000000) 288 random_seed = random.randrange(10000000)
310 if use_resources is None: 289 if use_resources is None:
311 use_resources = [] 290 use_resources = []
312 debug = False 291 debug = False
313 start = None 292 start = None
314 timeout = None 293 timeout = None
315 for o, a in opts: 294 for o, a in opts:
316 if o in ('-h', '--help'): 295 if o in ('-h', '--help'):
317 print(__doc__) 296 print(__doc__)
318 return 297 return
319 elif o in ('-v', '--verbose'): 298 elif o in ('-v', '--verbose'):
320 verbose += 1 299 verbose += 1
321 elif o in ('-w', '--verbose2'): 300 elif o in ('-w', '--verbose2'):
322 verbose2 = True 301 verbose2 = True
323 elif o in ('-d', '--debug'): 302 elif o in ('-d', '--debug'):
324 debug = True 303 debug = True
325 elif o in ('-W', '--verbose3'): 304 elif o in ('-W', '--verbose3'):
326 verbose3 = True 305 verbose3 = True
327 elif o in ('-G', '--failfast'):
328 failfast = True
329 elif o in ('-q', '--quiet'): 306 elif o in ('-q', '--quiet'):
330 quiet = True; 307 quiet = True;
331 verbose = 0 308 verbose = 0
332 elif o in ('-x', '--exclude'): 309 elif o in ('-x', '--exclude'):
333 exclude = True 310 exclude = True
334 elif o in ('-S', '--start'): 311 elif o in ('-S', '--start'):
335 start = a 312 start = a
336 elif o in ('-s', '--single'): 313 elif o in ('-s', '--single'):
337 single = True 314 single = True
338 elif o in ('-S', '--slow'): 315 elif o in ('-S', '--slow'):
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 else: 428 else:
452 print(("No handler for option {}. Please report this as a bug " 429 print(("No handler for option {}. Please report this as a bug "
453 "at http://bugs.python.org.").format(o), file=sys.stderr) 430 "at http://bugs.python.org.").format(o), file=sys.stderr)
454 sys.exit(1) 431 sys.exit(1)
455 if single and fromfile: 432 if single and fromfile:
456 usage("-s and -f don't go together!") 433 usage("-s and -f don't go together!")
457 if use_mp and trace: 434 if use_mp and trace:
458 usage("-T and -j don't go together!") 435 usage("-T and -j don't go together!")
459 if use_mp and findleaks: 436 if use_mp and findleaks:
460 usage("-l and -j don't go together!") 437 usage("-l and -j don't go together!")
461 if failfast and not (verbose or verbose3):
462 usage("-G/--failfast needs either -v or -W")
463 438
464 good = [] 439 good = []
465 bad = [] 440 bad = []
466 skipped = [] 441 skipped = []
467 resource_denieds = [] 442 resource_denieds = []
468 environment_changed = [] 443 environment_changed = []
469 interrupted = False 444 interrupted = False
470 445
471 if findleaks: 446 if findleaks:
472 try: 447 try:
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 sys.exit(2) 573 sys.exit(2)
599 from queue import Queue 574 from queue import Queue
600 from subprocess import Popen, PIPE 575 from subprocess import Popen, PIPE
601 debug_output_pat = re.compile(r"\[\d+ refs\]$") 576 debug_output_pat = re.compile(r"\[\d+ refs\]$")
602 output = Queue() 577 output = Queue()
603 def tests_and_args(): 578 def tests_and_args():
604 for test in tests: 579 for test in tests:
605 args_tuple = ( 580 args_tuple = (
606 (test, verbose, quiet), 581 (test, verbose, quiet),
607 dict(huntrleaks=huntrleaks, use_resources=use_resources, 582 dict(huntrleaks=huntrleaks, use_resources=use_resources,
608 debug=debug, output_on_failure=verbose3, 583 debug=debug, rerun_failed=verbose3, timeout=timeout)
609 timeout=timeout, failfast=failfast)
610 ) 584 )
611 yield (test, args_tuple) 585 yield (test, args_tuple)
612 pending = tests_and_args() 586 pending = tests_and_args()
613 opt_args = support.args_from_interpreter_flags() 587 opt_args = support.args_from_interpreter_flags()
614 base_cmd = [sys.executable] + opt_args + ['-m', 'test.regrtest'] 588 base_cmd = [sys.executable] + opt_args + ['-m', 'test.regrtest']
615 def work(): 589 def work():
616 # A worker thread. 590 # A worker thread.
617 try: 591 try:
618 while True: 592 while True:
619 try: 593 try:
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 test_count_width, test_index, test_count, len(bad), test)) 658 test_count_width, test_index, test_count, len(bad), test))
685 sys.stdout.flush() 659 sys.stdout.flush()
686 if trace: 660 if trace:
687 # If we're tracing code coverage, then we don't exit with status 661 # If we're tracing code coverage, then we don't exit with status
688 # if on a false return value from main. 662 # if on a false return value from main.
689 tracer.runctx('runtest(test, verbose, quiet, timeout=timeout)', 663 tracer.runctx('runtest(test, verbose, quiet, timeout=timeout)',
690 globals=globals(), locals=vars()) 664 globals=globals(), locals=vars())
691 else: 665 else:
692 try: 666 try:
693 result = runtest(test, verbose, quiet, huntrleaks, debug, 667 result = runtest(test, verbose, quiet, huntrleaks, debug,
694 output_on_failure=verbose3, 668 rerun_failed=verbose3, timeout=timeout)
695 timeout=timeout, failfast=failfast)
696 accumulate_result(test, result) 669 accumulate_result(test, result)
697 except KeyboardInterrupt: 670 except KeyboardInterrupt:
698 interrupted = True 671 interrupted = True
699 break 672 break
700 except: 673 except:
701 raise 674 raise
702 if findleaks: 675 if findleaks:
703 gc.collect() 676 gc.collect()
704 if gc.garbage: 677 if gc.garbage:
705 print("Warning: test created", len(gc.garbage), end=' ') 678 print("Warning: test created", len(gc.garbage), end=' ')
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 closefd=False, 802 closefd=False,
830 newline='\n') 803 newline='\n')
831 804
832 def restore_stdout(): 805 def restore_stdout():
833 sys.stdout.close() 806 sys.stdout.close()
834 sys.stdout = stdout 807 sys.stdout = stdout
835 atexit.register(restore_stdout) 808 atexit.register(restore_stdout)
836 809
837 def runtest(test, verbose, quiet, 810 def runtest(test, verbose, quiet,
838 huntrleaks=False, debug=False, use_resources=None, 811 huntrleaks=False, debug=False, use_resources=None,
839 output_on_failure=False, failfast=False, timeout=None): 812 rerun_failed=False, timeout=None):
840 """Run a single test. 813 """Run a single test.
841 814
842 test -- the name of the test 815 test -- the name of the test
843 verbose -- if true, print more messages 816 verbose -- if true, print more messages
844 quiet -- if true, don't print 'skipped' messages (probably redundant) 817 quiet -- if true, don't print 'skipped' messages (probably redundant)
845 test_times -- a list of (time, test_name) pairs 818 test_times -- a list of (time, test_name) pairs
846 huntrleaks -- run multiple times to test for leaks; requires a debug 819 huntrleaks -- run multiple times to test for leaks; requires a debug
847 build; a triple corresponding to -R's three arguments 820 build; a triple corresponding to -R's three arguments
848 output_on_failure -- if true, display test output on failure 821 rerun_failed -- if true, re-run in verbose mode when failed
849 timeout -- dump the traceback and exit if a test takes more than 822 timeout -- dump the traceback and exit if a test takes more than
850 timeout seconds 823 timeout seconds
851 824
852 Returns one of the test result constants: 825 Returns one of the test result constants:
853 INTERRUPTED KeyboardInterrupt when run under -j 826 INTERRUPTED KeyboardInterrupt when run under -j
854 RESOURCE_DENIED test skipped because resource denied 827 RESOURCE_DENIED test skipped because resource denied
855 SKIPPED test skipped for some other reason 828 SKIPPED test skipped for some other reason
856 ENV_CHANGED test failed because it changed the execution environmen t 829 ENV_CHANGED test failed because it changed the execution environmen t
857 FAILED test failed 830 FAILED test failed
858 PASSED test passed 831 PASSED test passed
859 """ 832 """
860 833
834 support.verbose = verbose # Tell tests to be moderately quiet
861 if use_resources is not None: 835 if use_resources is not None:
862 support.use_resources = use_resources 836 support.use_resources = use_resources
863 use_timeout = (timeout is not None) 837 use_timeout = (timeout is not None)
864 if use_timeout: 838 if use_timeout:
865 faulthandler.dump_tracebacks_later(timeout, exit=True) 839 faulthandler.dump_tracebacks_later(timeout, exit=True)
866 try: 840 try:
867 if failfast: 841 result = runtest_inner(test, verbose, quiet, huntrleaks, debug)
868 support.failfast = True 842 if result[0] == FAILED and rerun_failed:
869 if output_on_failure: 843 cleanup_test_droppings(test, verbose)
870 support.verbose = True 844 sys.stdout.flush()
871 845 sys.stderr.flush()
872 # Reuse the same instance to all calls to runtest(). Some 846 print("Re-running test {} in verbose mode".format(test))
873 # tests keep a reference to sys.stdout or sys.stderr 847 runtest(test, True, quiet, huntrleaks, debug, timeout=timeout)
874 # (eg. test_argparse).
875 if runtest.stringio is None:
876 stream = io.StringIO()
877 runtest.stringio = stream
878 else:
879 stream = runtest.stringio
880 stream.seek(0)
881 stream.truncate()
882
883 orig_stdout = sys.stdout
884 orig_stderr = sys.stderr
885 try:
886 sys.stdout = stream
887 sys.stderr = stream
888 result = runtest_inner(test, verbose, quiet, huntrleaks,
889 debug, display_failure=False)
890 if result[0] == FAILED:
891 output = stream.getvalue()
892 orig_stderr.write(output)
893 orig_stderr.flush()
894 finally:
895 sys.stdout = orig_stdout
896 sys.stderr = orig_stderr
897 else:
898 support.verbose = verbose # Tell tests to be moderately quiet
899 result = runtest_inner(test, verbose, quiet, huntrleaks, debug,
900 display_failure=not verbose)
901 return result 848 return result
902 finally: 849 finally:
903 if use_timeout: 850 if use_timeout:
904 faulthandler.cancel_dump_tracebacks_later() 851 faulthandler.cancel_dump_tracebacks_later()
905 cleanup_test_droppings(test, verbose) 852 cleanup_test_droppings(test, verbose)
906 runtest.stringio = None
907 853
908 # Unit tests are supposed to leave the execution environment unchanged 854 # Unit tests are supposed to leave the execution environment unchanged
909 # once they complete. But sometimes tests have bugs, especially when 855 # once they complete. But sometimes tests have bugs, especially when
910 # tests fail, and the changes to environment go on to mess up other 856 # tests fail, and the changes to environment go on to mess up other
911 # tests. This can cause issues with buildbot stability, since tests 857 # tests. This can cause issues with buildbot stability, since tests
912 # are run in random order and so problems may appear to come and go. 858 # are run in random order and so problems may appear to come and go.
913 # There are a few things we can save and restore to mitigate this, and 859 # There are a few things we can save and restore to mitigate this, and
914 # the following context manager handles this task. 860 # the following context manager handles this task.
915 861
916 class saved_test_environment: 862 class saved_test_environment:
(...skipping 24 matching lines...) Expand all
941 # the saved value and restore the resource using it. It will be called if 887 # the saved value and restore the resource using it. It will be called if
942 # and only if a change in the value is detected. 888 # and only if a change in the value is detected.
943 # 889 #
944 # Note: XXX will have any '.' replaced with '_' characters when determining 890 # Note: XXX will have any '.' replaced with '_' characters when determining
945 # the corresponding method names. 891 # the corresponding method names.
946 892
947 resources = ('sys.argv', 'cwd', 'sys.stdin', 'sys.stdout', 'sys.stderr', 893 resources = ('sys.argv', 'cwd', 'sys.stdin', 'sys.stdout', 'sys.stderr',
948 'os.environ', 'sys.path', 'sys.path_hooks', '__import__', 894 'os.environ', 'sys.path', 'sys.path_hooks', '__import__',
949 'warnings.filters', 'asyncore.socket_map', 895 'warnings.filters', 'asyncore.socket_map',
950 'logging._handlers', 'logging._handlerList', 'sys.gettrace', 896 'logging._handlers', 'logging._handlerList', 'sys.gettrace',
951 'sys.warnoptions', 'threading._dangling', 897 'sys.warnoptions')
952 'multiprocessing.process._dangling')
953 898
954 def get_sys_argv(self): 899 def get_sys_argv(self):
955 return id(sys.argv), sys.argv, sys.argv[:] 900 return id(sys.argv), sys.argv, sys.argv[:]
956 def restore_sys_argv(self, saved_argv): 901 def restore_sys_argv(self, saved_argv):
957 sys.argv = saved_argv[1] 902 sys.argv = saved_argv[1]
958 sys.argv[:] = saved_argv[2] 903 sys.argv[:] = saved_argv[2]
959 904
960 def get_cwd(self): 905 def get_cwd(self):
961 return os.getcwd() 906 return os.getcwd()
962 def restore_cwd(self, saved_cwd): 907 def restore_cwd(self, saved_cwd):
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 return id(logging._handlerList), logging._handlerList, logging._handlerL ist[:] 979 return id(logging._handlerList), logging._handlerList, logging._handlerL ist[:]
1035 def restore_logging__handlerList(self, saved_handlerList): 980 def restore_logging__handlerList(self, saved_handlerList):
1036 # Can't easily revert the logging state 981 # Can't easily revert the logging state
1037 pass 982 pass
1038 983
1039 def get_sys_warnoptions(self): 984 def get_sys_warnoptions(self):
1040 return id(sys.warnoptions), sys.warnoptions, sys.warnoptions[:] 985 return id(sys.warnoptions), sys.warnoptions, sys.warnoptions[:]
1041 def restore_sys_warnoptions(self, saved_options): 986 def restore_sys_warnoptions(self, saved_options):
1042 sys.warnoptions = saved_options[1] 987 sys.warnoptions = saved_options[1]
1043 sys.warnoptions[:] = saved_options[2] 988 sys.warnoptions[:] = saved_options[2]
1044
1045 # Controlling dangling references to Thread objects can make it easier
1046 # to track reference leaks.
1047 def get_threading__dangling(self):
1048 if not threading:
1049 return None
1050 # This copies the weakrefs without making any strong reference
1051 return threading._dangling.copy()
1052 def restore_threading__dangling(self, saved):
1053 if not threading:
1054 return
1055 threading._dangling.clear()
1056 threading._dangling.update(saved)
1057
1058 # Same for Process objects
1059 def get_multiprocessing_process__dangling(self):
1060 if not multiprocessing:
1061 return None
1062 # This copies the weakrefs without making any strong reference
1063 return multiprocessing.process._dangling.copy()
1064 def restore_multiprocessing_process__dangling(self, saved):
1065 if not multiprocessing:
1066 return
1067 multiprocessing.process._dangling.clear()
1068 multiprocessing.process._dangling.update(saved)
1069 989
1070 def resource_info(self): 990 def resource_info(self):
1071 for name in self.resources: 991 for name in self.resources:
1072 method_suffix = name.replace('.', '_') 992 method_suffix = name.replace('.', '_')
1073 get_name = 'get_' + method_suffix 993 get_name = 'get_' + method_suffix
1074 restore_name = 'restore_' + method_suffix 994 restore_name = 'restore_' + method_suffix
1075 yield name, getattr(self, get_name), getattr(self, restore_name) 995 yield name, getattr(self, get_name), getattr(self, restore_name)
1076 996
1077 def __enter__(self): 997 def __enter__(self):
1078 self.saved_values = dict((name, get()) for name, get, restore 998 self.saved_values = dict((name, get()) for name, get, restore
(...skipping 14 matching lines...) Expand all
1093 print("Warning -- {} was modified by {}".format( 1013 print("Warning -- {} was modified by {}".format(
1094 name, self.testname), 1014 name, self.testname),
1095 file=sys.stderr) 1015 file=sys.stderr)
1096 if self.verbose > 1: 1016 if self.verbose > 1:
1097 print(" Before: {}\n After: {} ".format( 1017 print(" Before: {}\n After: {} ".format(
1098 original, current), 1018 original, current),
1099 file=sys.stderr) 1019 file=sys.stderr)
1100 return False 1020 return False
1101 1021
1102 1022
1103 def runtest_inner(test, verbose, quiet, 1023 def runtest_inner(test, verbose, quiet, huntrleaks=False, debug=False):
1104 huntrleaks=False, debug=False, display_failure=True):
1105 support.unload(test) 1024 support.unload(test)
1106 1025
1107 test_time = 0.0 1026 test_time = 0.0
1108 refleak = False # True if the test leaked references. 1027 refleak = False # True if the test leaked references.
1109 try: 1028 try:
1110 if test.startswith('test.'): 1029 if test.startswith('test.'):
1111 abstest = test 1030 abstest = test
1112 else: 1031 else:
1113 # Always import it from the test package 1032 # Always import it from the test package
1114 abstest = 'test.' + test 1033 abstest = 'test.' + test
(...skipping 17 matching lines...) Expand all
1132 sys.stdout.flush() 1051 sys.stdout.flush()
1133 return RESOURCE_DENIED, test_time 1052 return RESOURCE_DENIED, test_time
1134 except unittest.SkipTest as msg: 1053 except unittest.SkipTest as msg:
1135 if not quiet: 1054 if not quiet:
1136 print(test, "skipped --", msg) 1055 print(test, "skipped --", msg)
1137 sys.stdout.flush() 1056 sys.stdout.flush()
1138 return SKIPPED, test_time 1057 return SKIPPED, test_time
1139 except KeyboardInterrupt: 1058 except KeyboardInterrupt:
1140 raise 1059 raise
1141 except support.TestFailed as msg: 1060 except support.TestFailed as msg:
1142 if display_failure: 1061 print("test", test, "failed --", msg, file=sys.stderr)
1143 print("test", test, "failed --", msg, file=sys.stderr)
1144 else:
1145 print("test", test, "failed", file=sys.stderr)
1146 sys.stderr.flush() 1062 sys.stderr.flush()
1147 return FAILED, test_time 1063 return FAILED, test_time
1148 except: 1064 except:
1149 msg = traceback.format_exc() 1065 msg = traceback.format_exc()
1150 print("test", test, "crashed --", msg, file=sys.stderr) 1066 print("test", test, "crashed --", msg, file=sys.stderr)
1151 sys.stderr.flush() 1067 sys.stderr.flush()
1152 return FAILED, test_time 1068 return FAILED, test_time
1153 else: 1069 else:
1154 if refleak: 1070 if refleak:
1155 return FAILED, test_time 1071 return FAILED, test_time
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
1693 assert __file__ == os.path.abspath(sys.argv[0]) 1609 assert __file__ == os.path.abspath(sys.argv[0])
1694 1610
1695 TEMPDIR, TESTCWD = _make_temp_dir_for_build(TEMPDIR) 1611 TEMPDIR, TESTCWD = _make_temp_dir_for_build(TEMPDIR)
1696 1612
1697 # Run the tests in a context manager that temporary changes the CWD to a 1613 # Run the tests in a context manager that temporary changes the CWD to a
1698 # temporary and writable directory. If it's not possible to create or 1614 # temporary and writable directory. If it's not possible to create or
1699 # change the CWD, the original CWD will be used. The original CWD is 1615 # change the CWD, the original CWD will be used. The original CWD is
1700 # available from support.SAVEDCWD. 1616 # available from support.SAVEDCWD.
1701 with support.temp_cwd(TESTCWD, quiet=True): 1617 with support.temp_cwd(TESTCWD, quiet=True):
1702 main() 1618 main()
OLDNEW
« no previous file with comments | « Lib/test/data/README ('k') | Lib/test/support.py » ('j') | no next file with comments »

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