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

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: Created 9 years, 4 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 pysvn
9 import re
10 import time
11
12 from datetime import datetime
13 from datetime import timedelta
14 # Default Webkit SVN location for chromium test expectation file.
15 # TODO(imasaki): support multiple test expectations files.
16 DEFAULT_TEST_EXPECTATION_LOCATION = (
17 'http://svn.webkit.org/repository/webkit/trunk/'
18 'LayoutTests/platform/chromium/test_expectations.txt')
19
20
21 class TestExpectationsHistory:
22 """A class to represent history of the test expectation file.
23
24 The history is obtained by calling PySVN.log()/diff() APIs.
25
26 TODO(imasaki): Add more functionalities here like getting some statistics
27 about the test expectation file.
28 """
29
30 @staticmethod
31 def GetDiffBetweenTimes(start, end, testname_list,
32 te_location=DEFAULT_TEST_EXPECTATION_LOCATION):
33 """Get difference between time peroid for the specified testnames.
34
35 Given the time period, this method first gets the revision number. Then,
36 it gets the diff for each revision. Finally, it keeps the diff relating to
37 the testnames and returns them along with other information about revision.
38
39 Args:
40 start: A float time specifying start of the time period to be
41 looked at.
42 end: A float time object specifying end of the time period to be
43 looked at.
44 testname_list : A list of the test name string that you are interested
45 in.
46 te_location: A location of the test expectation file.
47
48 Returns:
49 A list of tuples (old_rev, new_rev, author, date, message, lines). The
50 |lines| contains the diff of the tests that I am interested in.
51 """
52 # Get directory name which is necesary to call PySVN.checout().
53 te_location_dir = te_location[0:te_location.rindex('/')]
54 client = pysvn.Client()
55 client.checkout(te_location_dir, 'tmp', recurse=False)
56 logs = client.log('tmp/test_expectations.txt',
57 revision_start=pysvn.Revision(
58 pysvn.opt_revision_kind.date, start),
59 revision_end=pysvn.Revision(
60 pysvn.opt_revision_kind.date, end))
61 result_list = []
62 # Find the last revision (outside of time time period) and
63 # append it to preserve the last change before entering the time period.
64 # I am using 1 day back as start (called start2)
65 start2 = time.mktime(
66 (datetime.fromtimestamp(start) - timedelta(days=1)).timetuple())
67 logs2 = client.log('tmp/test_expectations.txt',
68 revision_start=pysvn.Revision(
69 pysvn.opt_revision_kind.date, start2),
70 revision_end=pysvn.Revision(
71 pysvn.opt_revision_kind.date, start))
72 if len(logs2) > 0:
73 logs.append(logs2[len(logs2)-2])
74 for i in xrange(len(logs)-1):
75 # PySVN.log() returns logs in reverse chronological order.
76 new_rev = logs[i].revision.number
77 old_rev = logs[i + 1].revision.number
78 # Getting information about new revision.
79 author = logs[i].author
80 date = logs[i].date
81 message = logs[i].message
82 # Parsing the actual diff.
83 text = client.diff('/tmp', 'tmp/test_expectations.txt',
84 revision1=pysvn.Revision(
85 pysvn.opt_revision_kind.number, old_rev),
86 revision2=pysvn.Revision(
87 pysvn.opt_revision_kind.number, new_rev))
88 lines = text.split('\n')
89 target_lines = []
90 for line in lines:
91 for testname in testname_list:
92 matches = re.findall(testname, line)
93 if matches:
94 if line[0] == '+' or line[0] == '-':
95 target_lines.append(line)
96 if len(target_lines) > 0:
97 result_list.append((
98 old_rev, new_rev, author,
99 # Needs to convert to normal date string for presentation.
100 datetime.fromtimestamp(date).strftime("%Y-%m-%d %H:%M:%S"),
101 message, target_lines))
102 return result_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698