Exemplo n.º 1
0
 def testReplaceLineInFile(self):
     file_path = os.path.join('test_data', 'inplace.txt')
     f = open(file_path, 'w')
     f.write('Hello')
     f.close()
     layouttest_analyzer_helpers.ReplaceLineInFile(file_path, 'Hello',
                                                   'Goodbye')
     f = open(file_path, 'r')
     self.assertEquals(f.readline(), 'Goodbye')
     f.close()
     layouttest_analyzer_helpers.ReplaceLineInFile(file_path, 'Bye',
                                                   'Hello')
     f = open(file_path, 'r')
     self.assertEquals(f.readline(), 'Goodbye')
     f.close()
Exemplo n.º 2
0
    def Update(self, datetime_string, data_map):
        """Update trend graphs using |datetime_string| and |data_map|.

    There are two kinds of graphs to be updated (one is for numbers and the
    other is for passing rates).

    Args:
        datetime_string: a datetime string delimited by ','
          (e.g., '2008,1,1,13,45,00)'. For example, in the case of the year
          2008, this ranges from '2008,1,1,0,0,00' to '2008,12,31,23,59,99'.
        data_map: a dictionary containing 'whole', 'skip' , 'nonskip',
          'passingrate' as its keys and (number, tile, text) string tuples
          as values for graph annotation.
    """
        joined_str = ''
        # For a date format in GViz, month is shifted (e.g., '2008,2,1' means
        # March 1, 2008). So, the input parameter |datetime_string| (before this
        # conversion) must be shifted in order to show the date properly on GViz.
        # After the below conversion, for example, in the case of the year 2008,
        # |datetime_string| ranges from '2008,0,1,0,0,00' to '2008,11,31,23,59,99'.
        str_list = datetime_string.split(',')
        str_list[1] = str(int(str_list[1]) - 1)  # Month
        datetime_string = ','.join(str_list)
        for key in ['whole', 'skip', 'nonskip']:
            joined_str += str(len(data_map[key][0])) + ','
            joined_str += ','.join(data_map[key][1:]) + ','
        new_line_for_numbers = '         [new Date(%s),%s],\n' % (
            datetime_string, joined_str)
        new_line_for_numbers += '         %s\n' % (
            LINE_INSERT_POINT_FOR_NUMBERS)
        layouttest_analyzer_helpers.ReplaceLineInFile(
            self._location, LINE_INSERT_POINT_FOR_NUMBERS,
            new_line_for_numbers)

        joined_str = '%s,%s,%s' % (str(
            data_map['passingrate'][0]), data_map['nonskip'][1],
                                   data_map['nonskip'][2])
        new_line_for_passingrate = '         [new Date(%s),%s],\n' % (
            datetime_string, joined_str)
        new_line_for_passingrate += '         %s\n' % (
            LINE_INSERT_POINT_FOR_PASSING_RATE)
        layouttest_analyzer_helpers.ReplaceLineInFile(
            self._location, LINE_INSERT_POINT_FOR_PASSING_RATE,
            new_line_for_passingrate)
Exemplo n.º 3
0
def UpdateDashboard(dashboard_file_location, test_group_name, data_map,
                    layouttest_root_path, rev, rev_date, email, email_content):
    """Update dashboard HTML file.

  Args:
    dashboard_file_location: the file location for the dashboard file.
    test_group_name: please refer to |options|.
    data_map: a dictionary that maps result data category ('whole', 'skip',
        'nonskip', 'passingrate') to information tuple (a dictionary that maps
        test name to its description, annotation, simple_rev_string) of the
        given result data category. These tuples are used for trend graph
        update.
    layouttest_root_path: A location string where Webkit layout tests are
        stored.
    rev: the latest revision number for the given test group.
    rev_date: the latest revision date for the given test group.
    email: email address of the owner for the given test group.
    email_content:  email content string (without |appended_text_to_email|)
        that will be shown on the dashboard.
  """
    # Generate a HTML file that contains all test names for each test group.
    escaped_tg_name = test_group_name.replace('/', '_')
    for tg in ['whole', 'skip', 'nonskip']:
        file_name = os.path.join(os.path.dirname(dashboard_file_location),
                                 escaped_tg_name + '_' + tg + '.html')
        file_object = open(file_name, 'wb')
        file_object.write('<table border="1">')
        sorted_testnames = data_map[tg][0].keys()
        sorted_testnames.sort()
        for testname in sorted_testnames:
            file_object.write((
                '<tr><td><a href="%s">%s</a></td><td><a href="%s">dashboard</a>'
                '</td><td>%s</td></tr>') %
                              (layouttest_root_path + testname, testname,
                               ('http://test-results.appspot.com/dashboards/'
                                'flakiness_dashboard.html#tests=%s') %
                               testname, data_map[tg][0][testname]))
        file_object.write('</table>')
        file_object.close()
    email_content_with_link = ''
    if email_content:
        file_name = os.path.join(os.path.dirname(dashboard_file_location),
                                 escaped_tg_name + '_email.html')
        file_object = open(file_name, 'wb')
        file_object.write(email_content)
        file_object.close()
        email_content_with_link = '<a href="%s_email.html">info</a>' % (
            escaped_tg_name)
    new_str = (
        '<td><a href="%s">%s</a></td><td><a href="%s">%s</a></td>'
        '<td><a href="%s">%s</a></td><td><a href="%s">%s</a></td>'
        '<td><a href="%s">%s</a></td><td>%d%%</td><td>%s%%</td>'
        '<td><a href="http://trac.webkit.org/changeset/%s">%s</a></td>'
        '<td>%s</td><td><a href="mailto:%s">%s</a></td>'
        '<td>%s</td>\n'
    ) % (
        # Dashboard file and graph must be in the same directory
        # to make the following link work.
        layouttest_root_path + '/' + test_group_name,
        test_group_name,
        escaped_tg_name + '.html',
        'graph',
        escaped_tg_name + '_whole.html',
        len(data_map['whole'][0]),
        escaped_tg_name + '_skip.html',
        len(data_map['skip'][0]),
        escaped_tg_name + '_nonskip.html',
        len(data_map['nonskip'][0]),
        100 - int(data_map['passingrate'][0]),
        data_map['passingrate'][0],
        rev,
        rev,
        rev_date,
        email,
        email,
        email_content_with_link)
    layouttest_analyzer_helpers.ReplaceLineInFile(
        dashboard_file_location, '<td>' + test_group_name + '</td>', new_str)