Convert PRESUBMIT.py to use check_output() instead of Popen().

Fix execution on windows.

Remove more code.

R=dpranke@chromium.org
BUG=
TEST=

Review URL: http://codereview.chromium.org/6792054

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@80617 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
maruel@chromium.org 14 years ago
parent 0e766050d2
commit ccbb781aa7

@ -26,6 +26,8 @@ def CommonChecks(input_api, output_api):
results.extend(input_api.canned_checks.CheckOwners(input_api, output_api)) results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
black_list = list(input_api.DEFAULT_BLACK_LIST) + [ black_list = list(input_api.DEFAULT_BLACK_LIST) + [
r'^cpplint\.py$', r'^cpplint\.py$',
r'^python_bin[\/\\].+',
r'^svn_bin[\/\\].+',
r'^tests[\/\\]\w+?[\/\\].+'] r'^tests[\/\\]\w+?[\/\\].+']
results.extend(input_api.canned_checks.RunPylint( results.extend(input_api.canned_checks.RunPylint(
input_api, input_api,
@ -42,16 +44,13 @@ def CommonChecks(input_api, output_api):
'tests', 'tests',
whitelist=[r'.*test\.py$'], whitelist=[r'.*test\.py$'],
verbose=verbose)) verbose=verbose))
results.extend(RunGitClTests(input_api, output_api)) results.extend(RunGitClTests(input_api, output_api, verbose=verbose))
return results return results
def RunGitClTests(input_api, output_api): def RunGitClTests(input_api, output_api, verbose):
"""Run all the shells scripts in the directory test. """Run all the shells scripts in the directory test.
""" """
# Not exposed from InputApi.
from os import listdir
# First loads a local Rietveld instance. # First loads a local Rietveld instance.
import sys import sys
old_sys_path = sys.path old_sys_path = sys.path
@ -62,21 +61,13 @@ def RunGitClTests(input_api, output_api):
finally: finally:
sys.path = old_sys_path sys.path = old_sys_path
# Set to True for testing. results = []
verbose = False
if verbose:
stdout = None
stderr = None
else:
stdout = input_api.subprocess.PIPE
stderr = input_api.subprocess.STDOUT
output = []
try: try:
# Start a local rietveld instance to test against. # Start a local rietveld instance to test against.
server.start_server() server.start_server()
test_path = input_api.os_path.abspath( test_path = input_api.os_path.abspath(
input_api.os_path.join(input_api.PresubmitLocalPath(), 'tests')) input_api.os_path.join(input_api.PresubmitLocalPath(), 'tests'))
for test in listdir(test_path): for test in input_api.os_listdir(test_path):
# test-lib.sh is not an actual test so it should not be run. The other # test-lib.sh is not an actual test so it should not be run. The other
# tests are tests known to fail. # tests are tests known to fail.
DISABLED_TESTS = ( DISABLED_TESTS = (
@ -85,19 +76,20 @@ def RunGitClTests(input_api, output_api):
continue continue
print('Running %s' % test) print('Running %s' % test)
proc = input_api.subprocess.Popen( try:
[input_api.os_path.join(test_path, test)], if verbose:
cwd=test_path, input_api.subprocess.check_call(
stdout=stdout, [input_api.os_path.join(test_path, test)], cwd=test_path)
stderr=stderr) else:
proc.communicate() input_api.subprocess.check_output(
if proc.returncode != 0: [input_api.os_path.join(test_path, test)], cwd=test_path)
output.append(output_api.PresubmitError('%s failed' % test)) except (OSError, input_api.subprocess.CalledProcessError), e:
results.append(output_api.PresubmitError('%s failed\n%s' % (test, e)))
except local_rietveld.Failure, e: except local_rietveld.Failure, e:
output.append(output_api.PresubmitError('\n'.join(str(i) for i in e.args))) results.append(output_api.PresubmitError('\n'.join(str(i) for i in e.args)))
finally: finally:
server.stop_server() server.stop_server()
return output return results
def CheckChangeOnUpload(input_api, output_api): def CheckChangeOnUpload(input_api, output_api):

Loading…
Cancel
Save