Beispiel #1
0
def build_index(journal_list, output_dir):
    """Create an index.html file for HTML output from journal list.

  Args:
    journal_list: [array of path] Path to the journal files to put in the index.
       Assumes that there is a corresponding .html file for each to link to.
  """
    document_manager = HtmlDocumentManager(title='Journal Summary')
    document_manager.has_key = False
    document_manager.has_global_expand = False

    processor = HtmlIndexRenderer(document_manager)
    for journal in journal_list:
        processor.process(StreamJournalNavigator.new_from_path(journal))
    processor.terminate()

    tr_tag = document_manager.make_tag_container('tr', [
        document_manager.make_tag_text('th', name)
        for name in processor.output_column_names
    ])
    table = document_manager.make_tag_container('table', [tr_tag],
                                                style='font-size:12pt')
    document_manager.wrap_tag(table)

    document_manager.build_to_path(os.path.join(output_dir, 'index.html'))
Beispiel #2
0
def extract_times(input_path, config_tags):
  """Extract time from path."""
  print('Processing %s' % input_path)
  journal_name = os.path.splitext(os.path.basename(input_path))[0]
  navigator = StreamJournalNavigator.new_from_path(input_path)
  processor = JournalTimeExtractor()
  processor.process(navigator)

  return {
      'config': config_tags,
      'suite': journal_name,
      'tests': [test.to_dict() for test in processor.tests]
  }
Beispiel #3
0
def extract_times(input_path, config_tags):
  """Extract time from path."""
  print('Processing %s' % input_path)
  journal_name = os.path.splitext(os.path.basename(input_path))[0]
  navigator = StreamJournalNavigator.new_from_path(input_path)
  processor = JournalTimeExtractor()
  processor.process(navigator)

  return {
      'config': config_tags,
      'suite': journal_name,
      'tests': [test.to_dict() for test in processor.tests]
  }
  def test_iterator(self):
    journal = Journal()
    path = os.path.join(self.temp_dir, 'test_iterator.journal')
    expect = []

    journal.open_with_path(path, TestString='TestValue', TestNum=123)
    expect.append({'_type': 'JournalMessage',
                   '_value': 'Starting journal.',
                   'TestString': 'TestValue',
                   'TestNum': 123})

    journal.write_message('Initial Message')
    expect.append({'_type': 'JournalMessage', '_value': 'Initial Message'})
                   
    journal.begin_context('OUTER', TestProperty='BeginOuter')
    expect.append({'_type': 'JournalContextControl',
                   'control': 'BEGIN',
                   '_title': 'OUTER',
                   'TestProperty': 'BeginOuter'})

    journal.write_message('Context Message', format='pre')
    expect.append({'_type': 'JournalMessage', '_value': 'Context Message',
                   'format': 'pre'})
    
    journal.end_context(TestProperty='END OUTER')
    expect.append({'_type': 'JournalContextControl',
                   'control': 'END',
                   'TestProperty': 'END OUTER'})

    journal.terminate(EndProperty='xyz')
    expect.append({'_type': 'JournalMessage',
                   '_value': 'Finished journal.',
                   'EndProperty': 'xyz'})

    # We're going to pop off expect, so reverse it
    # so that we can check in order.
    expect.reverse()
    navigator = StreamJournalNavigator.new_from_path(path)
    for record in navigator:
        del(record['_thread'])
        del(record['_timestamp'])
        self.assertEquals(record, expect.pop())
    self.assertEquals([], expect)
Beispiel #5
0
def journal_to_html(input_path, prune=False):
    """Main program for converting a journal JSON file into HTML.

  This will write a file using in the input_path directory with the
  same basename as the JSON file, but with 'html' extension instead.

  Args:
    input_path: [string] Path the journal file.
  """
    output_path = os.path.basename(os.path.splitext(input_path)[0]) + '.html'

    document_manager = HtmlDocumentManager(
        title='Report for {0}'.format(os.path.basename(input_path)))

    processor = HtmlRenderer(document_manager, prune=prune)
    processor.process(StreamJournalNavigator.new_from_path(input_path))
    processor.terminate()
    document_manager.wrap_tag(document_manager.new_tag('table'))
    document_manager.build_to_path(output_path)
Beispiel #6
0
 def __call__(self, options):
     """Process command."""
     navigator = StreamJournalNavigator.new_from_path(options.path)
     processor = DumpRenderer(vars(options))
     processor.process(navigator)
     processor.terminate()
Beispiel #7
0
  def process_all(document_manager, journal_list, output_dir):
    """Process all the journals and write out summary tables.

    Args:
      journal_list: [list of paths] Paths to journal files to tabulate.
      output_dir: [path] Directory for table html files.
    """
    dirs = set([os.path.dirname(path) for path in journal_list])
    file_names = set([os.path.basename(path) for path in journal_list])
    dir_to_column_name = make_directory_shortname_map(dirs)
    journal_to_cell = {}
    journal_to_stats = {}
    journal_to_details = {}

    column_keys = sorted(dir_to_column_name.keys())
    column_stats = {key: TestStats.new() for key in column_keys}
    row_stats = {key: TestStats.new() for key in file_names}

    processor = HtmlIndexTableRenderer(document_manager)

    # Process all the journals to get the stats that we're going
    # to render into the table cells.
    for journal in sorted(journal_list):
      summary, stats, details = processor.process(
          StreamJournalNavigator.new_from_path(journal))
      journal_to_cell[journal] = summary
      journal_to_stats[journal] = stats
      journal_to_details[journal] = details
      row_stats[os.path.basename(journal)].aggregate(stats)
      column_stats[os.path.dirname(journal)].aggregate(stats)
    processor.terminate()

    HtmlIndexTableRenderer.write_test_summary_tables(
        journal_to_details, dir_to_column_name, output_dir)

    header_cols = [document_manager.make_tag_text('th', '')]
    header_cols.extend(
        [document_manager.make_tag_container(
            'th',
            [document_manager.make_tag_text(
                'a', dir_to_column_name[path],
                href=os.path.join(path, 'index.html'))],
            class_='toggle')
         for path in column_keys])
    header_cols.append(document_manager.make_tag_text('th', 'Summary'))
    header_tr_tag = document_manager.make_tag_container('tr', header_cols)

    # Write a row into the table for a given test case.
    table_rows = [header_tr_tag]
    for test_name in sorted(file_names):
      test_basename = os.path.splitext(test_name)[0]
      test_summary_path = test_basename + '_index.html'
      row = [
          document_manager.make_tag_container(
              'th',
              [document_manager.make_tag_text(
                  'a', test_basename,
                  href=test_summary_path,
                  class_='toggle')])]

      for path in column_keys:
        source = os.path.join(path, test_name)
        if source in journal_list:
          source_dir = os.path.dirname(source)
          journal_file = os.path.join(source_dir, test_basename + '.journal')
          cell_html = journal_to_cell[journal_file]
          row.append(document_manager.make_tag_container('td', [cell_html]))
        else:
          row.append(document_manager.make_tag_container('td', []))

      # Write summary column at the end that summarizes the row
      row_summary = processor.make_summary_cell(
          test_summary_path, row_stats[test_name], suffix='I')
      row.append(document_manager.make_tag_container('td', [row_summary]))
      table_rows.append(document_manager.make_tag_container('tr', row))

    # Write summary row at the bottom that sumarizes each column.
    row = [document_manager.make_tag_text('th', 'Summary')]
    total_stats = TestStats.new()
    for path in column_keys:
      stats = column_stats[path]
      total_stats.aggregate(stats)
      column_index_path = os.path.join(path, 'index.html')
      column_summary = processor.make_summary_cell(
          column_index_path, stats, 'I')
      row.append(
          document_manager.make_tag_container('td', [column_summary]))

    column_summary = processor.make_summary_cell(None, total_stats, 'I')
    row.append(document_manager.make_tag_container('td', [column_summary]))
    table_rows.append(document_manager.make_tag_container('tr', row))

    table = document_manager.make_tag_container(
        'table', table_rows, style='font-size:10pt')
    document_manager.append_tag(table)