Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: media/tools/layout_tests/test_expectations_history.py

Issue 7693018: Intial checkin of layout test analyzer. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Modified based on CR comments. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 sys
10 import time
11 import pysvn
12
13 from datetime import datetime
14 from datetime import timedelta
15
16 # Default Webkit SVN location for chromium test expectation file.
17 # TODO(imasaki): support multiple test expectation files.
18 DEFAULT_TEST_EXPECTATION_LOCATION = (
19 'http://svn.webkit.org/repository/webkit/trunk/'
20 'LayoutTests/platform/chromium/test_expectations.txt')
21
22
23 class TestExpectationsHistory:
24 """A class to represent history of the test expectation file.
25
26 The history is obtained by calling PySVN.log()/diff() APIs.
27
28 TODO(imasaki): Add more functionalities here like getting some statistics
29 about the test expectation file.
30 """
31
32 @staticmethod
33 def GetDiffBetweenTimes(start, end, testname_list,
34 te_location=DEFAULT_TEST_EXPECTATION_LOCATION):
35 """Get difference between time period for the specified test names.
36
37 Given the time period, this method first gets the revision number. Then,
38 it gets the diff for each revision. Finally, it keeps the diff relating to
39 the test names and returns them along with other information about
40 revision.
41
42 Args:
43 start: A timestamp specifying start of the time period to be
44 looked at.
45 end: A timestamp object specifying end of the time period to be
46 looked at.
47 testname_list: A list of strings representing test names of interest.
48 te_location: A location of the test expectation file.
49
50 Returns:
51 A list of tuples (old_rev, new_rev, author, date, message, lines). The
52 |lines| contains the diff of the tests of interest.
53 """
54 # Get directory name which is necesary to call PySVN.checkout().
55 te_location_dir = te_location[0:te_location.rindex('/')]
56 client = pysvn.Client()
57 client.checkout(te_location_dir, 'tmp', recurse=False)
58 logs = client.log('tmp/test_expectations.txt',
59 revision_start=pysvn.Revision(
60 pysvn.opt_revision_kind.date, start),
61 revision_end=pysvn.Revision(
62 pysvn.opt_revision_kind.date, end))
63 result_list = []
64 # Find the last revision outside of time period and
65 # append it to preserve the last change before entering the time period.
66 gobackdays = 1
67 while gobackdays < sys.maxint:
68 start2 = time.mktime(
69 (datetime.fromtimestamp(start) - (
70 timedelta(days=gobackdays))).timetuple())
71 logs2 = client.log('tmp/test_expectations.txt',
72 revision_start=pysvn.Revision(
73 pysvn.opt_revision_kind.date, start2),
74 revision_end=pysvn.Revision(
75 pysvn.opt_revision_kind.date, start))
76 if logs2:
77 logs.append(logs2[len(logs2) - 2])
78 break
79 gobackdays *= 2
80
81 for i in xrange(len(logs) - 1):
82 # PySVN.log() returns logs in reverse chronological order.
83 new_rev = logs[i].revision.number
84 old_rev = logs[i + 1].revision.number
85 # Parsing the actual diff.
86 text = client.diff('/tmp', 'tmp/test_expectations.txt',
87 revision1=pysvn.Revision(
88 pysvn.opt_revision_kind.number, old_rev),
89 revision2=pysvn.Revision(
90 pysvn.opt_revision_kind.number, new_rev))
91 lines = text.split('\n')
92 target_lines = []
93 for line in lines:
94 for testname in testname_list:
95 matches = re.findall(testname, line)
96 if matches:
97 if line[0] == '+' or line[0] == '-':
98 target_lines.append(line)
99 if target_lines:
100 # Needs to convert to normal date string for presentation.
101 result_list.append((
102 old_rev, new_rev, logs[i].author,
103 datetime.fromtimestamp(logs[i].date).strftime('%Y-%m-%d %H:%M:%S'),
104 logs[i].message, target_lines))
105 return result_list
OLDNEW
« no previous file with comments | « media/tools/layout_tests/test_data/more_te_info ('k') | media/tools/layout_tests/test_expectations_history_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698