pygame is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this againpygame / run_tests.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | #################################### IMPORTS ###################################
# TODO: clean up imports
import test.unittest as unittest
import sys, os, re, subprocess, time, optparse
import pygame.threads, pygame
from test_runner import prepare_test_env, run_test, combine_results, \
test_failures, get_test_results, from_namespace, \
TEST_RESULTS_START
from pprint import pformat
main_dir, test_subdir, fake_test_subdir = prepare_test_env()
test_runner_py = os.path.join(main_dir, "test_runner.py")
import test_utils, unittest_patch
################################### CONSTANTS ##################################
# Defaults:
# See optparse options below for more options (test_runner.py)
#
# If an xxxx_test.py takes longer than TIME_OUT seconds it will be killed
# This is only the default, can be over-ridden on command line
TIME_OUT = 30
# Any tests in IGNORE will not be ran
IGNORE = set ([
"scrap_test",
])
# Subprocess has less of a need to worry about interference between tests
SUBPROCESS_IGNORE = set ([
"scrap_test",
])
INTERACTIVE = set ([
'cdrom_test'
])
################################################################################
# Set the command line options
#
# Defined in test_runner.py as it shares options, added to here
from test_runner import opt_parser
opt_parser.set_usage("""
Runs all or some of the test/xxxx_test.py tests.
$ run_tests.py sprite threads -sd
Runs the sprite and threads module tests isolated in subprocesses, dumping all
failing tests info in the form of a dict.
""")
opt_parser.set_defaults (
python = sys.executable,
time_out = TIME_OUT,
)
options, args = opt_parser.parse_args()
################################################################################
# Change to working directory and compile a list of test modules
# If options.fake, then compile list of fake xxxx_test.py from run_tests__tests
TEST_MODULE_RE = re.compile('^(.+_test)\.py$')
if options.fake:
test_subdir = os.path.join(fake_test_subdir, options.fake )
sys.path.append(test_subdir)
working_dir = test_subdir
else:
working_dir = main_dir
test_env = {"PYTHONPATH": test_subdir} #TODO: append to PYTHONPATH
try:
# Required by Python 2.6 on Windows.
test_env["SystemRoot"] = os.environ["SystemRoot"]
except KeyError:
pass
os.chdir(working_dir)
if args:
test_modules = [
m.endswith('_test') and m or ('%s_test' % m) for m in args
]
else:
if options.subprocess: ignore = SUBPROCESS_IGNORE
else: ignore = IGNORE
# TODO: add option to run only INTERACTIVE, or include them, etc
ignore = ignore | INTERACTIVE
test_modules = []
for f in sorted(os.listdir(test_subdir)):
for match in TEST_MODULE_RE.findall(f):
if match not in ignore:
test_modules.append(match)
################################################################################
# Single process mode
if not options.subprocess:
results = {}
unittest_patch.patch(options)
t = time.time()
for module in test_modules:
results.update(run_test(module, options = options))
t = time.time() - t
################################################################################
# Subprocess mode
#
if options.subprocess:
from async_sub import proc_in_time_or_kill
def sub_test(module):
print 'loading', module
pass_on_args = [a for a in sys.argv[1:] if a not in args]
cmd = [options.python, test_runner_py, module ] + pass_on_args
return module, (cmd, test_env, working_dir), proc_in_time_or_kill (
cmd, options.time_out, env = test_env, wd = working_dir,
)
if options.multi_thread:
def tmap(f, args):
return pygame.threads.tmap (
f, args, stop_on_error = False,
num_workers = options.multi_thread
)
else: tmap = map
results = {}
t = time.time()
for module, cmd, (return_code, raw_return) in tmap(sub_test, test_modules):
test_file = '%s.py' % os.path.join(test_subdir, module)
cmd, test_env, working_dir = cmd
test_results = get_test_results(raw_return)
if test_results: results.update(test_results)
else: results[module] = {}
add_to_results = [
'return_code', 'raw_return', 'cmd', 'test_file',
'test_env', 'working_dir', 'module',
]
results[module].update(from_namespace(locals(), add_to_results))
t = time.time() -t
################################################################################
# Output Results
#
untrusty_total, combined = combine_results(results, t)
total, fails = test_failures(results)
if not options.subprocess: assert total == untrusty_total
if not options.dump or (options.human and untrusty_total == total):
print combined
else:
print TEST_RESULTS_START
print pformat(options.all and results or fails)
################################################################################
|