Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """A Module for the history of the test expectation file.""" | |
| 7 | |
| 8 import re | |
| 9 import time | |
| 10 import pysvn | |
| 11 | |
| 12 from datetime import datetime | |
| 13 from datetime import timedelta | |
| 14 | |
| 15 # Default Webkit SVN location for chromium test expectation file. | |
| 16 # TODO(imasaki): support multiple test expectation files. | |
| 17 DEFAULT_TEST_EXPECTATION_LOCATION = ( | |
| 18 'http://svn.webkit.org/repository/webkit/trunk/' | |
| 19 'LayoutTests/platform/chromium/test_expectations.txt') | |
| 20 | |
| 21 | |
| 22 class TestExpectationsHistory: | |
| 23 """A class to represent history of the test expectation file. | |
| 24 | |
| 25 The history is obtained by calling PySVN.log()/diff() APIs. | |
| 26 | |
| 27 TODO(imasaki): Add more functionalities here like getting some statistics | |
| 28 about the test expectation file. | |
| 29 """ | |
| 30 | |
| 31 @staticmethod | |
| 32 def GetDiffBetweenTimes(start, end, testname_list, | |
| 33 te_location=DEFAULT_TEST_EXPECTATION_LOCATION): | |
| 34 """Get difference between time period for the specified test names. | |
| 35 | |
| 36 Given the time period, this method first gets the revision number. Then, | |
| 37 it gets the diff for each revision. Finally, it keeps the diff relating to | |
| 38 the test names and returns them along with other information about | |
| 39 revision. | |
| 40 | |
| 41 Args: | |
| 42 start: A timestamp specifying start of the time period to be | |
| 43 looked at. | |
| 44 end: A timestamp object specifying end of the time period to be | |
| 45 looked at. | |
| 46 testname_list: A list of strings representing test names of interest. | |
| 47 te_location: A location of the test expectation file. | |
| 48 | |
| 49 Returns: | |
| 50 A list of tuples (old_rev, new_rev, author, date, message, lines). The | |
| 51 |lines| contains the diff of the tests of interest. | |
| 52 """ | |
| 53 # Get directory name which is necesary to call PySVN.checkout(). | |
| 54 te_location_dir = te_location[0:te_location.rindex('/')] | |
| 55 client = pysvn.Client() | |
| 56 client.checkout(te_location_dir, 'tmp', recurse=False) | |
| 57 logs = client.log('tmp/test_expectations.txt', | |
| 58 revision_start=pysvn.Revision( | |
| 59 pysvn.opt_revision_kind.date, start), | |
| 60 revision_end=pysvn.Revision( | |
| 61 pysvn.opt_revision_kind.date, end)) | |
| 62 result_list = [] | |
| 63 # Find the last revision outside of time period and | |
| 64 # append it to preserve the last change before entering the time period. | |
| 65 gobackdays = 1 | |
| 66 while True: | |
| 67 start2 = time.mktime( | |
| 68 (datetime.fromtimestamp(start) - ( | |
| 69 timedelta(days=gobackdays))).timetuple()) | |
| 70 logs2 = client.log('tmp/test_expectations.txt', | |
| 71 revision_start=pysvn.Revision( | |
| 72 pysvn.opt_revision_kind.date, start2), | |
| 73 revision_end=pysvn.Revision( | |
| 74 pysvn.opt_revision_kind.date, start)) | |
| 75 if logs2: | |
| 76 logs.append(logs2[len(logs2) - 2]) | |
| 77 break | |
| 78 gobackdays *= 2 | |
|
dennis_jeffrey
2011/08/27 00:04:50
(optional) Maybe have some maximum value for 'goba
imasaki1
2011/08/29 21:32:49
Done.
| |
| 79 | |
| 80 for i in xrange(len(logs) - 1): | |
| 81 # PySVN.log() returns logs in reverse chronological order. | |
| 82 new_rev = logs[i].revision.number | |
| 83 old_rev = logs[i + 1].revision.number | |
| 84 # Parsing the actual diff. | |
| 85 text = client.diff('/tmp', 'tmp/test_expectations.txt', | |
| 86 revision1=pysvn.Revision( | |
| 87 pysvn.opt_revision_kind.number, old_rev), | |
| 88 revision2=pysvn.Revision( | |
| 89 pysvn.opt_revision_kind.number, new_rev)) | |
| 90 lines = text.split('\n') | |
| 91 target_lines = [] | |
| 92 for line in lines: | |
| 93 for testname in testname_list: | |
| 94 matches = re.findall(testname, line) | |
| 95 if matches: | |
| 96 if line[0] == '+' or line[0] == '-': | |
| 97 target_lines.append(line) | |
| 98 if target_lines: | |
| 99 # Needs to convert to normal date string for presentation. | |
| 100 result_list.append(( | |
| 101 old_rev, new_rev, logs[i].author, | |
| 102 datetime.fromtimestamp(logs[i].date).strftime('%Y-%m-%d %H:%M:%S'), | |
| 103 logs[i].message, target_lines)) | |
| 104 return result_list | |
| OLD | NEW |