Skip to content

Commit

Permalink
Run format-webkit on webkitpy code (without string conversion).
Browse files Browse the repository at this point in the history
This is a follow-up to http://crrev.com/1839193004; the auto-formatting done
by this CL is similar to that done in that CL, except ./format-webkitpy calls
autopep8 with --aggressive.

Specifically:

  ./format-webkitpy --leave-strings-alone --no-backups $(find . -name '*.py' | grep -v thirdparty)

Also ran the same command on the Python files in Tools/Scripts.

BUG=598897

Review-Url: https://codereview.chromium.org/2014063002
Cr-Commit-Position: refs/heads/master@{#397453}
  • Loading branch information
qyearsley authored and Commit bot committed Jun 2, 2016
1 parent cdf3504 commit 32c236f
Show file tree
Hide file tree
Showing 87 changed files with 473 additions and 288 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ paths = []
for path in sys.argv[1:]:
content = open(path, 'r').read()
if (testharness_results.is_testharness_output(content) and
testharness_results.is_testharness_output_passing(content) and
not testharness_results.is_testharness_output_with_console_errors_or_warnings(content)):
testharness_results.is_testharness_output_passing(content) and
not testharness_results.is_testharness_output_with_console_errors_or_warnings(content)):
paths.append(path)

if len(paths) > 0:
sys.stderr.write('* The following files are passing testharness results without console error messages, they should be removed:\n ')
sys.stderr.write(
'* The following files are passing testharness results without console error messages, they should be removed:\n ')
sys.stderr.write('\n '.join(paths))
sys.stderr.write('\n')
sys.exit("ERROR: found passing testharness results without console error messages.")
1 change: 0 additions & 1 deletion third_party/WebKit/Tools/Scripts/lint-test-expectations
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ from webkitpy.layout_tests import lint_test_expectations


sys.exit(lint_test_expectations.main(sys.argv[1:], sys.stdout, sys.stderr))

8 changes: 6 additions & 2 deletions third_party/WebKit/Tools/Scripts/print-json-test-results
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ def main(argv):
print >> sys.stderr, "file not found: %s" % args[0]
sys.exit(1)
else:
txt = host.filesystem.read_text_file(host.filesystem.join(host.port_factory.get(options=options).results_directory(), 'full_results.json'))
txt = host.filesystem.read_text_file(
host.filesystem.join(
host.port_factory.get(
options=options).results_directory(),
'full_results.json'))

if txt.startswith('ADD_RESULTS(') and txt.endswith(');'):
txt = txt[12:-2] # ignore optional JSONP wrapper
Expand Down Expand Up @@ -112,5 +116,5 @@ def convert_trie_to_flat_paths(trie, prefix=None):
return result


if __name__ == '__main__':
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ from webkitpy.layout_tests.models.test_expectations import TestExpectationParser
google_code_url = 'https://www.googleapis.com/projecthosting/v2/projects/chromium/issues/%s?key=AIzaSyDgCqT1Dt5AZWLHo4QJjyMHaCjhnFacGF0'
crbug_prefix = 'crbug.com/'


class StaleTestPrinter(object):

def __init__(self, options):
self.days = options.days
self.create_csv = options.create_csv
Expand All @@ -57,7 +59,7 @@ class StaleTestPrinter(object):
response = urllib2.urlopen(url)
parsed = json.loads(response.read())
last_updated = parsed['updated']
parsed_time = datetime.datetime.strptime(last_updated.split(".")[0]+"UTC", "%Y-%m-%dT%H:%M:%S%Z")
parsed_time = datetime.datetime.strptime(last_updated.split(".")[0] + "UTC", "%Y-%m-%dT%H:%M:%S%Z")
time_delta = datetime.datetime.now() - parsed_time
return time_delta.days > self.days

Expand All @@ -84,10 +86,15 @@ class StaleTestPrinter(object):
if self.create_csv:
host.filesystem.write_text_file(self.create_csv, csv_contents)


def main(argv):
option_parser = optparse.OptionParser()
option_parser.add_option('--days', type='int', default=90, help='Number of days to consider a bug stale.'),
option_parser.add_option('--create-csv', type='string', default=0, help='Generate a CSV of the stale entries as well. Followed by the filename.'),
option_parser.add_option(
'--create-csv',
type='string',
default=0,
help='Generate a CSV of the stale entries as well. Followed by the filename.'),
options, args = option_parser.parse_args(argv)

printer = StaleTestPrinter(options)
Expand Down
8 changes: 5 additions & 3 deletions third_party/WebKit/Tools/Scripts/print-test-ordering
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import sys

from webkitpy.common.host import Host


def main(argv):
parser = optparse.OptionParser(usage='%prog [stats.json]')
parser.description = "Prints out lists of tests run on each worker as per the stats.json file."
Expand All @@ -46,7 +47,7 @@ def main(argv):
stats_path = host.filesystem.join(host.port_factory.get().results_directory(), 'stats.json')

with open(stats_path, 'r') as fp:
stats_trie = json.load(fp)
stats_trie = json.load(fp)

stats = convert_trie_to_flat_paths(stats_trie)
stats_by_worker = {}
Expand All @@ -62,10 +63,11 @@ def main(argv):

for worker in sorted(stats_by_worker.keys()):
print worker + ':'
for test in sorted(stats_by_worker[worker], key=lambda test:test["number"]):
for test in sorted(stats_by_worker[worker], key=lambda test: test["number"]):
print test["name"]
print


def convert_trie_to_flat_paths(trie, prefix=None):
# Cloned from webkitpy.layout_tests.layout_package.json_results_generator
# so that this code can stand alone.
Expand All @@ -81,5 +83,5 @@ def convert_trie_to_flat_paths(trie, prefix=None):
return result


if __name__ == '__main__':
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
1 change: 1 addition & 0 deletions third_party/WebKit/Tools/Scripts/run-bindings-tests
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import sys

from webkitpy.bindings.main import run_bindings_tests


def main(argv):
"""Runs Blink bindings IDL compiler on test IDL files and compares the
results with reference files.
Expand Down
4 changes: 4 additions & 0 deletions third_party/WebKit/Tools/Scripts/webkit-patch
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ from webkitpy.tool.webkit_patch import WebKitPatch
# the default behaviour of writing to sys.stdout, so we intercept
# the case of writing raw strings and make sure StreamWriter gets
# input that it can handle.


class ForgivingUTF8Writer(codecs.lookup('utf-8')[-1]):

def write(self, object):
if isinstance(object, str):
# Assume raw strings are utf-8 encoded. If this line
Expand All @@ -67,6 +70,7 @@ sys.stdout = ForgivingUTF8Writer(sys.stdout)

_log = logging.getLogger("webkit-patch")


def main():
# This is a hack to let us enable DEBUG logging as early as possible.
# Note this can't be ternary as versioning.check_version()
Expand Down
6 changes: 3 additions & 3 deletions third_party/WebKit/Tools/Scripts/webkitpy/bindings/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ def generate_union_type_containers(output_directory, component):
input_directory = os.path.join(test_input_directory, component)
for filename in os.listdir(input_directory):
if (filename.endswith('.idl') and
# Dependencies aren't built
# (they are used by the dependent)
filename not in DEPENDENCY_IDL_FILES):
# Dependencies aren't built
# (they are used by the dependent)
filename not in DEPENDENCY_IDL_FILES):
idl_filenames.append(
os.path.realpath(
os.path.join(input_directory, filename)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import logging

from webkitpy.common.memoized import memoized
from functools import reduce

_log = logging.getLogger(__name__)

Expand Down Expand Up @@ -292,7 +293,8 @@ def _optimize_subtree(self, baseline_name):
self.new_results_by_directory.append(results_by_directory)
return True

if self._results_by_port_name(results_by_directory, baseline_name) != self._results_by_port_name(new_results_by_directory, baseline_name):
if self._results_by_port_name(results_by_directory, baseline_name) != self._results_by_port_name(
new_results_by_directory, baseline_name):
# This really should never happen. Just a sanity check to make sure the script fails in the case of bugs
# instead of committing incorrect baselines.
_log.error(" %s: optimization failed" % basename)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def test_move_baselines_skip_scm_commands(self):
'/mock-checkout/third_party/WebKit/LayoutTests/platform/linux/another/test-expected.txt',
])

def _assertOptimization(self, results_by_directory, expected_new_results_by_directory, baseline_dirname='', expected_files_to_delete=None, host=None):
def _assertOptimization(self, results_by_directory, expected_new_results_by_directory,
baseline_dirname='', expected_files_to_delete=None, host=None):
if not host:
host = MockHost()
fs = host.filesystem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ def _run_git(self, command_args, **kwargs):
def in_working_directory(cls, path, executive=None):
try:
executive = executive or Executive()
return executive.run_command([cls.executable_name, 'rev-parse', '--is-inside-work-tree'], cwd=path, error_handler=Executive.ignore_error).rstrip() == "true"
except OSError, e:
return executive.run_command([cls.executable_name, 'rev-parse', '--is-inside-work-tree'],
cwd=path, error_handler=Executive.ignore_error).rstrip() == "true"
except OSError as e:
# The Windows bots seem to through a WindowsError when git isn't installed.
return False

Expand All @@ -89,7 +90,8 @@ def read_git_config(cls, key, cwd=None, executive=None):
# Pass the cwd if provided so that we can handle the case of running webkit-patch outside of the working directory.
# FIXME: This should use an Executive.
executive = executive or Executive()
return executive.run_command([cls.executable_name, "config", "--get-all", key], error_handler=Executive.ignore_error, cwd=cwd).rstrip('\n')
return executive.run_command(
[cls.executable_name, "config", "--get-all", key], error_handler=Executive.ignore_error, cwd=cwd).rstrip('\n')

def _discard_local_commits(self):
self._run_git(['reset', '--hard', self._remote_branch_ref()])
Expand Down Expand Up @@ -152,7 +154,8 @@ def current_branch_or_ref(self):

def _upstream_branch(self):
current_branch = self.current_branch()
return self._branch_from_ref(self.read_git_config('branch.%s.merge' % current_branch, cwd=self.checkout_root, executive=self._executive).strip())
return self._branch_from_ref(self.read_git_config(
'branch.%s.merge' % current_branch, cwd=self.checkout_root, executive=self._executive).strip())

def _merge_base(self, git_commit=None):
if git_commit:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def find(filesystem, base_dir, paths=None, skipped_directories=None, file_filter

paths = paths or ['*']
skipped_directories = skipped_directories or set(['.svn', '_svn'])
return _normalized_find(filesystem, _normalize(filesystem, base_dir, paths), skipped_directories, file_filter, directory_sort_key)
return _normalized_find(filesystem, _normalize(
filesystem, base_dir, paths), skipped_directories, file_filter, directory_sort_key)


def _normalize(filesystem, base_dir, paths):
Expand Down
4 changes: 2 additions & 2 deletions third_party/WebKit/Tools/Scripts/webkitpy/common/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _engage_awesome_locale_hacks(self):
def _engage_awesome_windows_hacks(self):
try:
self.executive.run_command(['git', 'help'])
except OSError, e:
except OSError as e:
try:
self.executive.run_command(['git.bat', 'help'])
# The Win port uses the depot_tools package, which contains a number
Expand All @@ -102,7 +102,7 @@ def _engage_awesome_windows_hacks(self):
_log.debug('Engaging git.bat Windows hack.')
from webkitpy.common.checkout.scm.git import Git
Git.executable_name = 'git.bat'
except OSError, e:
except OSError as e:
_log.debug('Failed to engage git.bat Windows hack.')

def initialize_scm(self, patch_directories=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@

class MockHost(MockSystemHost):

def __init__(self, log_executive=False, executive_throws_when_run=None, initialize_scm_by_default=True, web=None, scm=None, os_name=None, os_version=None):
def __init__(self, log_executive=False, executive_throws_when_run=None,
initialize_scm_by_default=True, web=None, scm=None, os_name=None, os_version=None):
MockSystemHost.__init__(self, log_executive, executive_throws_when_run, os_name=os_name, os_version=os_version)
add_unit_tests_to_mock_filesystem(self.filesystem)
self.web = web or MockWeb()
Expand Down
10 changes: 6 additions & 4 deletions third_party/WebKit/Tools/Scripts/webkitpy/common/message_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,14 @@ def __init__(self, src, message_name, message_args, from_user, logs):
self.logs = logs

def __repr__(self):
return '_Message(src=%s, name=%s, args=%s, from_user=%s, logs=%s)' % (self.src, self.name, self.args, self.from_user, self.logs)
return '_Message(src=%s, name=%s, args=%s, from_user=%s, logs=%s)' % (
self.src, self.name, self.args, self.from_user, self.logs)


class _Worker(multiprocessing.Process):

def __init__(self, host, messages_to_manager, messages_to_worker, worker_factory, worker_number, running_inline, manager, log_level):
def __init__(self, host, messages_to_manager, messages_to_worker,
worker_factory, worker_number, running_inline, manager, log_level):
super(_Worker, self).__init__()
self.host = host
self.worker_number = worker_number
Expand Down Expand Up @@ -263,9 +265,9 @@ def run(self):
_log.debug("%s exiting" % self.name)
except Queue.Empty:
assert False, '%s: ran out of messages in worker queue.' % self.name
except KeyboardInterrupt, e:
except KeyboardInterrupt as e:
self._raise(sys.exc_info())
except Exception, e:
except Exception as e:
self._raise(sys.exc_info())
finally:
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _fetch_revision_to_build_map(self):
_log.info("Loading revision/build list from %s." % self.results_url())
_log.info("This may take a while...")
result_files = self._buildbot._fetch_twisted_directory_listing(self.results_url())
except urllib2.HTTPError, error:
except urllib2.HTTPError as error:
if error.code != 404:
raise
_log.debug("Revision/build list failed to load.")
Expand Down Expand Up @@ -289,12 +289,12 @@ def _fetch_build_dictionary(self, builder, build_number):
json_url = "%s/json/builders/%s/builds/%s?filter=1" % (buildbot_url, urllib.quote(builder.name()), build_number)
try:
return json.load(urllib2.urlopen(json_url))
except urllib2.URLError, err:
except urllib2.URLError as err:
build_url = Build.build_url(builder, build_number)
_log.error("Error fetching data for %s build %s (%s, json: %s): %s" %
(builder.name(), build_number, build_url, json_url, err))
return None
except ValueError, err:
except ValueError as err:
build_url = Build.build_url(builder, build_number)
_log.error("Error decoding json data from %s: %s" % (build_url, err))
return None
Expand Down Expand Up @@ -405,6 +405,7 @@ def _find_green_revision(self, builder_revisions):
break
builders_succeeded_in_past = builders_succeeded_in_past.union(revision_statuses[past_revision])

if len(builders_succeeded_in_future) == len(builder_revisions) and len(builders_succeeded_in_past) == len(builder_revisions):
if len(builders_succeeded_in_future) == len(builder_revisions) and len(
builders_succeeded_in_past) == len(builder_revisions):
return revision
return None
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,18 @@ def mock_fetch_build_dictionary(self, build_number):
build = builder.build(10)
self.assertEqual(build.builder(), builder)
self.assertEqual(build.url(), "http://build.chromium.org/p/chromium.webkit/builders/Test%20Builder/builds/10")
self.assertEqual(build.results_url(), "https://storage.googleapis.com/chromium-layout-test-archives/Test_Builder/r20%20%2810%29")
self.assertEqual(
build.results_url(),
"https://storage.googleapis.com/chromium-layout-test-archives/Test_Builder/r20%20%2810%29")
self.assertEqual(build.revision(), 20)
self.assertTrue(build.is_green())

build = build.previous_build()
self.assertEqual(build.builder(), builder)
self.assertEqual(build.url(), "http://build.chromium.org/p/chromium.webkit/builders/Test%20Builder/builds/9")
self.assertEqual(build.results_url(), "https://storage.googleapis.com/chromium-layout-test-archives/Test_Builder/r18%20%289%29")
self.assertEqual(
build.results_url(),
"https://storage.googleapis.com/chromium-layout-test-archives/Test_Builder/r18%20%289%29")
self.assertEqual(build.revision(), 18)
self.assertFalse(build.is_green())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def run(self, request):
while True:
try:
return request()
except urllib2.HTTPError, e:
except urllib2.HTTPError as e:
if self._convert_404_to_None and e.code == 404:
return None
self._check_for_timeout()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_exception(self):
try:
transaction.run(lambda: self._raise_exception())
did_throw_exception = False
except Exception, e:
except Exception as e:
did_process_exception = True
self.assertEqual(e, self.exception)
self.assertTrue(did_throw_exception)
Expand Down Expand Up @@ -86,7 +86,7 @@ def test_timeout(self):
try:
transaction.run(lambda: self._raise_500_error())
did_throw_exception = False
except NetworkTimeout, e:
except NetworkTimeout as e:
did_process_exception = True
self.assertTrue(did_throw_exception)
self.assertTrue(did_process_exception)
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ def is_crash_log(fs, dirpath, basename):
match = first_line_regex.match(f[0:f.find('\n')])
if match and match.group('process_name') == process_name and (pid is None or int(match.group('pid')) == pid):
return errors + f
except IOError, e:
except IOError as e:
if include_errors:
errors += "ERROR: Failed to read '%s': %s\n" % (path, str(e))
except OSError, e:
except OSError as e:
if include_errors:
errors += "ERROR: Failed to read '%s': %s\n" % (path, str(e))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def test_find_log_darwin(self):
files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150719_quadzen.crash'] = mock_crash_report
files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150720_quadzen.crash'] = newer_mock_crash_report
files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150721_quadzen.crash'] = None
files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150722_quadzen.crash'] = other_process_mock_crash_report
files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150723_quadzen.crash'] = misformatted_mock_crash_report
files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150722_quadzen.crash'] = other_process_mock_crash_report # noqa
files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150723_quadzen.crash'] = misformatted_mock_crash_report # noqa
filesystem = MockFileSystem(files)
crash_logs = CrashLogs(MockSystemHost(filesystem=filesystem))
log = crash_logs.find_newest_log("DumpRenderTree")
Expand Down
Loading

0 comments on commit 32c236f

Please sign in to comment.