Chromium Code Reviews| Index: media/tools/layout_tests/test_expectations_history.py |
| diff --git a/media/tools/layout_tests/test_expectations_history.py b/media/tools/layout_tests/test_expectations_history.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cbe3b4c5ea163f12bc287a0b5c2bf3e0828683d0 |
| --- /dev/null |
| +++ b/media/tools/layout_tests/test_expectations_history.py |
| @@ -0,0 +1,103 @@ |
| +#!/usr/bin/python |
| +# Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""A Module for the history of the test expectation file.""" |
| + |
| +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.
|
| +import re |
| +import time |
| + |
| +from datetime import datetime |
| +from datetime import timedelta |
| + |
| +# Default Webkit SVN location for chromium test expectation file. |
| +# 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.
|
| +DEFAULT_TEST_EXPECTATION_LOCATION = ( |
| + 'http://svn.webkit.org/repository/webkit/trunk/' |
| + 'LayoutTests/platform/chromium/test_expectations.txt') |
| + |
| + |
| +class TestExpectationsHistory: |
| + """A class to represent history of the test expectation file. |
| + |
| + The history is obtained by calling PySVN.log()/diff() APIs. |
| + |
| + TODO(imasaki): Add more functionalities here like getting some statistics |
| + about the test expectation file. |
| + """ |
| + |
| + @staticmethod |
| + def GetDiffBetweenTimes(start, end, testname_list, |
| + te_location=DEFAULT_TEST_EXPECTATION_LOCATION): |
| + """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.
|
| + |
| + Given the time period, this method first gets the revision number. Then, |
| + it gets the diff for each revision. Finally, it keeps the diff relating to |
| + the test names and returns them along with other information about revision. |
| + |
| + Args: |
| + start: A float time specifying start of the time period to be |
| + looked at. |
| + 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.
|
| + looked at. |
| + 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.
|
| + in. |
| + te_location: A location of the test expectation file. |
| + |
| + Returns: |
| + A list of tuples (old_rev, new_rev, author, date, message, lines). The |
| + |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.
|
| + """ |
| + # 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.
|
| + te_location_dir = te_location[0:te_location.rindex('/')] |
| + client = pysvn.Client() |
| + client.checkout(te_location_dir, 'tmp', recurse=False) |
| + logs = client.log('tmp/test_expectations.txt', |
| + revision_start=pysvn.Revision( |
| + pysvn.opt_revision_kind.date, start), |
| + revision_end=pysvn.Revision( |
| + pysvn.opt_revision_kind.date, end)) |
| + result_list = [] |
| + # Find the last revision outside of time period and |
| + # append it to preserve the last change before entering the time period. |
| + # 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.
|
| + start2 = time.mktime( |
| + (datetime.fromtimestamp(start) - timedelta(days=1)).timetuple()) |
| + logs2 = client.log('tmp/test_expectations.txt', |
| + revision_start=pysvn.Revision( |
| + pysvn.opt_revision_kind.date, start2), |
| + revision_end=pysvn.Revision( |
| + 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.
|
| + if len(logs2) > 0: |
|
dennis_jeffrey
2011/08/25 00:36:46
if logs2:
imasaki1
2011/08/25 23:57:03
Done.
|
| + 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.
|
| + 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.
|
| + # 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.
|
| + new_rev = logs[i].revision.number |
| + old_rev = logs[i + 1].revision.number |
| + # 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.
|
| + author = logs[i].author |
| + date = logs[i].date |
| + 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.
|
| + # Parsing the actual diff. |
| + text = client.diff('/tmp', 'tmp/test_expectations.txt', |
| + revision1=pysvn.Revision( |
| + pysvn.opt_revision_kind.number, old_rev), |
| + revision2=pysvn.Revision( |
| + pysvn.opt_revision_kind.number, new_rev)) |
| + lines = text.split('\n') |
| + target_lines = [] |
| + for line in lines: |
| + for testname in testname_list: |
| + matches = re.findall(testname, line) |
| + if matches: |
| + if line[0] == '+' or line[0] == '-': |
| + target_lines.append(line) |
| + if len(target_lines) > 0: |
|
dennis_jeffrey
2011/08/25 00:36:46
if target_lines:
imasaki1
2011/08/25 23:57:03
Done.
|
| + result_list.append(( |
| + old_rev, new_rev, author, |
| + # 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.
|
| + datetime.fromtimestamp(date).strftime('%Y-%m-%d %H:%M:%S'), |
| + message, target_lines)) |
| + return result_list |