Chromium Code Reviews| Index: third_party/WebKit/Tools/Scripts/print-stale-test-expectations-entries |
| diff --git a/third_party/WebKit/Tools/Scripts/print-stale-test-expectations-entries b/third_party/WebKit/Tools/Scripts/print-stale-test-expectations-entries |
| index d868e01981929b21a353ed37fa8c4e021251e385..b3d419b74df4143af83dd82bea339721b599e7c9 100755 |
| --- a/third_party/WebKit/Tools/Scripts/print-stale-test-expectations-entries |
| +++ b/third_party/WebKit/Tools/Scripts/print-stale-test-expectations-entries |
| @@ -30,9 +30,11 @@ |
| """Prints a list of test expectations for tests whose bugs haven't been modified recently.""" |
| +import csv |
| import datetime |
| import json |
| import optparse |
| +import StringIO |
| import sys |
| import urllib2 |
| @@ -42,7 +44,16 @@ from webkitpy.layout_tests.models.test_expectations import TestExpectationParser |
| # FIXME: Make this a direct request to Monorail. |
| GOOGLE_CODE_URL = 'https://www.googleapis.com/projecthosting/v2/projects/chromium/issues/%s?key=AIzaSyDgCqT1Dt5AZWLHo4QJjyMHaCjhnFacGF0' |
| CRBUG_PREFIX = 'crbug.com/' |
| +CSV_ROW_HEADERS = ['crbug link', 'test file', 'days since last update', 'owner', 'status'] |
| +class Bug_Info(): |
|
qyearsley
2016/08/22 23:21:00
For consistency, this should be `class BugInfo(obj
nainar
2016/08/23 00:21:24
Done.
|
| + def __init__(self, bug_link, filename, days_since_last_update, owner, status): |
| + self.bug_link = bug_link |
| + self.filename = filename |
| + self.filename = filename |
|
qyearsley
2016/08/22 23:21:00
Duplicate line
nainar
2016/08/23 00:21:24
Done.
|
| + self.days_since_last_update = days_since_last_update |
| + self.owner = owner |
| + self.status = status |
| class StaleTestPrinter(object): |
| @@ -50,7 +61,7 @@ class StaleTestPrinter(object): |
| self.days = options.days |
| self.csv_filename = options.create_csv |
| self.host = Host() |
| - self.is_stale_results = {} |
| + self.bug_info = {} |
| def print_stale_tests(self): |
| port = self.host.port_factory.get() |
| @@ -67,9 +78,12 @@ class StaleTestPrinter(object): |
| self.write_csv(csv_rows) |
| def write_csv(self, rows): |
| - row_strings = [', '.join(r) for r in rows] |
| - contents = '\n'.join(row_strings) + '\n' |
| - self.host.filesystem.write_text_file(self.csv_filename, contents) |
| + out = StringIO.StringIO() |
| + writer = csv.writer(out) |
| + writer.writerow(CSV_ROW_HEADERS) |
| + for row in rows: |
| + writer.writerow(row) |
| + self.host.filesystem.write_text_file(self.csv_filename, out.getvalue()) |
| def check_expectations_line(self, line): |
| """Checks the bugs in one test expectations line to see if they're stale. |
| @@ -82,9 +96,14 @@ class StaleTestPrinter(object): |
| """ |
| bug_links, test_name = line.bugs, line.name |
| try: |
| - if bug_links and all(self.is_stale(bug_link) for bug_link in bug_links): |
| - print line.original_string.strip() |
| - return [bug_links[0], test_name] |
| + if bug_links: |
| + # prepopulate bug info |
| + for bug_link in bug_links: |
| + self.populate_bug_info(bug_link, test_name); |
| + # return the stale bug's information |
|
qyearsley
2016/08/22 23:21:00
Comments should generally start with a capital let
nainar
2016/08/23 00:21:24
Done.
|
| + if all(self.is_stale(bug_link) for bug_link in bug_links): |
| + print line.original_string.strip() |
| + return [bug_links[0], self.bug_info[bug_links[0]].filename, self.bug_info[bug_links[0]].days_since_last_update, self.bug_info[bug_links[0]].owner, self.bug_info[bug_links[0]].status] |
|
qyearsley
2016/08/22 23:21:00
This line could be broken up to improve readabilit
nainar
2016/08/23 00:21:24
Done.
|
| except urllib2.HTTPError as error: |
| if error.code == 404: |
| message = 'got 404, bug does not exist.' |
| @@ -95,20 +114,23 @@ class StaleTestPrinter(object): |
| print >> sys.stderr, 'Error when checking %s: %s' % (','.join(bug_links), message) |
| return None |
| - def is_stale(self, bug_link): |
| - if bug_link in self.is_stale_results: |
| - return self.is_stale_results[bug_link] |
| + def populate_bug_info(self, bug_link, test_name): |
| + if bug_link in self.bug_info: |
| + return; |
|
qyearsley
2016/08/22 23:21:00
Unnecessary semicolon
nainar
2016/08/23 00:21:24
Done.
|
| # In case there's an error in the request, don't make the same request again. |
| - self.is_stale_results[bug_link] = False |
| bug_number = bug_link.strip(CRBUG_PREFIX) |
| url = GOOGLE_CODE_URL % bug_number |
| 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(parsed['updated'].split(".")[0] + "UTC", "%Y-%m-%dT%H:%M:%S%Z") |
| time_delta = datetime.datetime.now() - parsed_time |
| - self.is_stale_results[bug_link] = time_delta.days > self.days |
| - return self.is_stale_results[bug_link] |
| + owner = 'none' |
| + if 'owner' in parsed.keys(): |
| + owner = parsed['owner']['name'] |
| + self.bug_info[bug_link] = Bug_Info(bug_link, test_name, time_delta.days, owner, parsed['state']) |
| + |
| + def is_stale(self, bug_link): |
| + return self.bug_info[bug_link].days_since_last_update > self.days |
| def main(argv): |