| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """A module for the history of the test expectation file.""" | 5 """A module for the history of the test expectation file.""" |
| 6 | 6 |
| 7 from datetime import datetime | 7 from datetime import datetime |
| 8 from datetime import timedelta | 8 from datetime import timedelta |
| 9 | 9 |
| 10 import re | 10 import re |
| 11 import sys | 11 import sys |
| 12 import time | 12 import time |
| 13 import pysvn | 13 import pysvn |
| 14 | 14 |
| 15 # Default Webkit SVN location for chromium test expectation file. | 15 # Default Webkit SVN location for chromium test expectation file. |
| 16 # TODO(imasaki): support multiple test expectation files. | 16 # TODO(imasaki): support multiple test expectation files. |
| 17 DEFAULT_TEST_EXPECTATION_LOCATION = ( | 17 DEFAULT_TEST_EXPECTATION_LOCATION = ( |
| 18 'http://svn.webkit.org/repository/webkit/trunk/' | 18 'http://svn.webkit.org/repository/webkit/trunk/' |
| 19 'LayoutTests/platform/chromium/TestExpectations') |
| 20 LEGACY_TEST_EXPECTATION_LOCATION = ( |
| 21 'http://svn.webkit.org/repository/webkit/trunk/' |
| 19 'LayoutTests/platform/chromium/test_expectations.txt') | 22 'LayoutTests/platform/chromium/test_expectations.txt') |
| 20 | 23 |
| 21 | |
| 22 class TestExpectationsHistory(object): | 24 class TestExpectationsHistory(object): |
| 23 """A class to represent history of the test expectation file. | 25 """A class to represent history of the test expectation file. |
| 24 | 26 |
| 25 The history is obtained by calling PySVN.log()/diff() APIs. | 27 The history is obtained by calling PySVN.log()/diff() APIs. |
| 26 | 28 |
| 27 TODO(imasaki): Add more functionalities here like getting some statistics | 29 TODO(imasaki): Add more functionalities here like getting some statistics |
| 28 about the test expectation file. | 30 about the test expectation file. |
| 29 """ | 31 """ |
| 30 | 32 |
| 31 @staticmethod | 33 @staticmethod |
| (...skipping 18 matching lines...) Expand all Loading... |
| 50 A list of tuples (old_rev, new_rev, author, date, message, lines). The | 52 A list of tuples (old_rev, new_rev, author, date, message, lines). The |
| 51 |lines| contains the diff of the tests of interest. | 53 |lines| contains the diff of the tests of interest. |
| 52 """ | 54 """ |
| 53 # Get directory name which is necesary to call PySVN.checkout(). | 55 # Get directory name which is necesary to call PySVN.checkout(). |
| 54 te_location_dir = te_location[0:te_location.rindex('/')] | 56 te_location_dir = te_location[0:te_location.rindex('/')] |
| 55 client = pysvn.Client() | 57 client = pysvn.Client() |
| 56 client.checkout(te_location_dir, 'tmp', recurse=False) | 58 client.checkout(te_location_dir, 'tmp', recurse=False) |
| 57 # PySVN.log() (http://pysvn.tigris.org/docs/pysvn_prog_ref.html | 59 # PySVN.log() (http://pysvn.tigris.org/docs/pysvn_prog_ref.html |
| 58 # #pysvn_client_log) returns the log messages (including revision | 60 # #pysvn_client_log) returns the log messages (including revision |
| 59 # number in chronological order). | 61 # number in chronological order). |
| 60 logs = client.log('tmp/test_expectations.txt', | 62 logs = client.log('tmp/TestExpectations', |
| 61 revision_start=pysvn.Revision( | 63 revision_start=pysvn.Revision( |
| 62 pysvn.opt_revision_kind.date, start), | 64 pysvn.opt_revision_kind.date, start), |
| 63 revision_end=pysvn.Revision( | 65 revision_end=pysvn.Revision( |
| 64 pysvn.opt_revision_kind.date, end)) | 66 pysvn.opt_revision_kind.date, end)) |
| 65 result_list = [] | 67 result_list = [] |
| 66 gobackdays = 1 | 68 gobackdays = 1 |
| 67 while gobackdays < sys.maxint: | 69 while gobackdays < sys.maxint: |
| 68 goback_start = time.mktime( | 70 goback_start = time.mktime( |
| 69 (datetime.fromtimestamp(start) - ( | 71 (datetime.fromtimestamp(start) - ( |
| 70 timedelta(days=gobackdays))).timetuple()) | 72 timedelta(days=gobackdays))).timetuple()) |
| 71 logs_before_time_period = ( | 73 logs_before_time_period = ( |
| 72 client.log('tmp/test_expectations.txt', | 74 client.log('tmp/TestExpectations', |
| 73 revision_start=pysvn.Revision( | 75 revision_start=pysvn.Revision( |
| 74 pysvn.opt_revision_kind.date, goback_start), | 76 pysvn.opt_revision_kind.date, goback_start), |
| 75 revision_end=pysvn.Revision( | 77 revision_end=pysvn.Revision( |
| 76 pysvn.opt_revision_kind.date, start))) | 78 pysvn.opt_revision_kind.date, start))) |
| 77 if logs_before_time_period: | 79 if logs_before_time_period: |
| 78 # Prepend at the beginning of logs. | 80 # Prepend at the beginning of logs. |
| 79 logs.insert(0, logs_before_time_period[len(logs_before_time_period)-1]) | 81 logs.insert(0, logs_before_time_period[len(logs_before_time_period)-1]) |
| 80 break | 82 break |
| 81 gobackdays *= 2 | 83 gobackdays *= 2 |
| 82 | 84 |
| 83 for i in xrange(len(logs) - 1): | 85 for i in xrange(len(logs) - 1): |
| 84 old_rev = logs[i].revision.number | 86 old_rev = logs[i].revision.number |
| 85 new_rev = logs[i + 1].revision.number | 87 new_rev = logs[i + 1].revision.number |
| 86 # Parsing the actual diff. | 88 # Parsing the actual diff. |
| 87 text = client.diff('/tmp', 'tmp/test_expectations.txt', | 89 |
| 90 # test_expectations.txt was renamed to TestExpectations at r119317. |
| 91 new_path = DEFAULT_TEST_EXPECTATION_LOCATION |
| 92 if new_rev < 119317: |
| 93 new_path = LEGACY_TEST_EXPECTATION_LOCATION |
| 94 old_path = DEFAULT_TEST_EXPECTATION_LOCATION |
| 95 if old_rev < 119317: |
| 96 old_path = LEGACY_TEST_EXPECTATION_LOCATION |
| 97 |
| 98 text = client.diff('/tmp', |
| 99 url_or_path=old_path, |
| 88 revision1=pysvn.Revision( | 100 revision1=pysvn.Revision( |
| 89 pysvn.opt_revision_kind.number, old_rev), | 101 pysvn.opt_revision_kind.number, old_rev), |
| 102 url_or_path2=new_path, |
| 90 revision2=pysvn.Revision( | 103 revision2=pysvn.Revision( |
| 91 pysvn.opt_revision_kind.number, new_rev)) | 104 pysvn.opt_revision_kind.number, new_rev)) |
| 92 lines = text.split('\n') | 105 lines = text.split('\n') |
| 93 target_lines = [] | 106 target_lines = [] |
| 94 for line in lines: | 107 for line in lines: |
| 95 for testname in testname_list: | 108 for testname in testname_list: |
| 96 matches = re.findall(testname, line) | 109 matches = re.findall(testname, line) |
| 97 if matches: | 110 if matches: |
| 98 if line[0] == '+' or line[0] == '-': | 111 if line[0] == '+' or line[0] == '-': |
| 99 target_lines.append(line) | 112 target_lines.append(line) |
| 100 if target_lines: | 113 if target_lines: |
| 101 # Needs to convert to normal date string for presentation. | 114 # Needs to convert to normal date string for presentation. |
| 102 result_list.append(( | 115 result_list.append(( |
| 103 old_rev, new_rev, logs[i + 1].author, | 116 old_rev, new_rev, logs[i + 1].author, |
| 104 datetime.fromtimestamp( | 117 datetime.fromtimestamp( |
| 105 logs[i + 1].date).strftime('%Y-%m-%d %H:%M:%S'), | 118 logs[i + 1].date).strftime('%Y-%m-%d %H:%M:%S'), |
| 106 logs[i + 1].message, target_lines)) | 119 logs[i + 1].message, target_lines)) |
| 107 return result_list | 120 return result_list |
| OLD | NEW |