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

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: Minor modifications. 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
dennis_jeffrey 2011/08/25 00:36:46 If this is not a standard python library but is in
imasaki1 2011/08/25 23:57:03 Done.
9 import re
10 import time
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 expectations files.
dennis_jeffrey 2011/08/25 00:36:46 'expectations' --> 'expectation'
imasaki1 2011/08/25 23:57:03 Done.
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 perios for the specified test names.
dennis_jeffrey 2011/08/25 00:36:46 'perios' --> 'periods'
imasaki1 2011/08/25 23:57:03 Done.
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 revision.
39
40 Args:
41 start: A float time specifying start of the time period to be
42 looked at.
43 end: A float time object specifying end of the time period to be
dennis_jeffrey 2011/08/25 00:36:46 is it really a "float time object", or just a floa
imasaki1 2011/08/25 23:57:03 Actually it is timestamp. change here.
44 looked at.
45 testname_list : A list of the test name string that you are interested
dennis_jeffrey 2011/08/25 00:36:46 'A list of strings representing test names of inte
imasaki1 2011/08/25 23:57:03 Done.
46 in.
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 that I am interested in.
dennis_jeffrey 2011/08/25 00:36:46 'that I am interested in' --> 'of interest'
imasaki1 2011/08/25 23:57:03 Done.
52 """
53 # Get directory name which is necesary to call PySVN.checout().
dennis_jeffrey 2011/08/25 00:36:46 'checout' --> 'checkout'
imasaki1 2011/08/25 23:57:03 Done.
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 # I am using 1 day back as |start2| (called start2) from original |start|.
dennis_jeffrey 2011/08/25 00:36:46 'I am using' --> 'This uses'. Also, you may want
imasaki1 2011/08/25 23:57:03 Done.
66 start2 = time.mktime(
67 (datetime.fromtimestamp(start) - timedelta(days=1)).timetuple())
68 logs2 = client.log('tmp/test_expectations.txt',
69 revision_start=pysvn.Revision(
70 pysvn.opt_revision_kind.date, start2),
71 revision_end=pysvn.Revision(
72 pysvn.opt_revision_kind.date, start))
dennis_jeffrey 2011/08/25 00:36:46 nit: indent the above 4 lines by 1 more space each
imasaki1 2011/08/25 23:57:03 Done.
73 if len(logs2) > 0:
dennis_jeffrey 2011/08/25 00:36:46 if logs2:
imasaki1 2011/08/25 23:57:03 Done.
74 logs.append(logs2[len(logs2)-2])
dennis_jeffrey 2011/08/25 00:36:46 only indent this line by 2 spaces, not 4
dennis_jeffrey 2011/08/25 00:36:46 put spaces around the '-'
imasaki1 2011/08/25 23:57:03 Done.
imasaki1 2011/08/25 23:57:03 Done.
75 for i in xrange(len(logs)-1):
dennis_jeffrey 2011/08/25 00:36:46 put spaces around the '-'
imasaki1 2011/08/25 23:57:03 Done.
76 # PySVN.log() returns logs in reverse chronological order.
dennis_jeffrey 2011/08/25 00:36:46 Indent this line and the lines below by only 2 spa
imasaki1 2011/08/25 23:57:03 Done.
77 new_rev = logs[i].revision.number
78 old_rev = logs[i + 1].revision.number
79 # Getting information about new revision.
dennis_jeffrey 2011/08/25 00:36:46 '# Get information about the new revision.'
imasaki1 2011/08/25 23:57:03 Done.
80 author = logs[i].author
81 date = logs[i].date
82 message = logs[i].message
dennis_jeffrey 2011/08/25 00:36:46 I think the above 3 variables probably don't need
imasaki1 2011/08/25 23:57:03 Done.
83 # Parsing the actual diff.
84 text = client.diff('/tmp', 'tmp/test_expectations.txt',
85 revision1=pysvn.Revision(
86 pysvn.opt_revision_kind.number, old_rev),
87 revision2=pysvn.Revision(
88 pysvn.opt_revision_kind.number, new_rev))
89 lines = text.split('\n')
90 target_lines = []
91 for line in lines:
92 for testname in testname_list:
93 matches = re.findall(testname, line)
94 if matches:
95 if line[0] == '+' or line[0] == '-':
96 target_lines.append(line)
97 if len(target_lines) > 0:
dennis_jeffrey 2011/08/25 00:36:46 if target_lines:
imasaki1 2011/08/25 23:57:03 Done.
98 result_list.append((
99 old_rev, new_rev, author,
100 # Needs to convert to normal date string for presentation.
dennis_jeffrey 2011/08/25 00:36:46 I think we probably don't need this comment. If y
imasaki1 2011/08/25 23:57:03 Done.
101 datetime.fromtimestamp(date).strftime('%Y-%m-%d %H:%M:%S'),
102 message, target_lines))
103 return result_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698