# Copyright 2021 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Module for outputting results in a human-readable format.""" import tempfile from typing import Dict, IO, List, Optional, Union from flake_suppressor_common import common_typing as ct UrlListType = List[str] StringTagsToUrlsType = Dict[str, UrlListType] TestToStringTagsType = Dict[str, StringTagsToUrlsType] StringMapType = Dict[str, TestToStringTagsType] TestToUrlListType = Dict[str, UrlListType] SuiteToTestsType = Dict[str, TestToUrlListType] ConfigGroupedStringMapType = Dict[str, SuiteToTestsType] NodeType = Union[UrlListType, StringTagsToUrlsType, TestToStringTagsType, StringMapType, TestToUrlListType, SuiteToTestsType, ConfigGroupedStringMapType] def GenerateHtmlOutputFile(aggregated_results: ct.AggregatedResultsType, outfile: Optional[IO] = None) -> None: """Generates an HTML results file. Args: aggregated_results: A map containing the aggregated test results. outfile: A file-like object to output to. Will create one if not provided. """ outfile = outfile or tempfile.NamedTemporaryFile( mode='w', delete=False, suffix='.html') try: outfile.write('\n\n') string_map = _ConvertAggregatedResultsToStringMap(aggregated_results) _OutputMapToHtmlFile(string_map, 'Grouped By Test', outfile) config_map = _ConvertFromTestGroupingToConfigGrouping(string_map) _OutputMapToHtmlFile(config_map, 'Grouped By Config', outfile) outfile.write('\n\n') finally: outfile.close() print('HTML results: %s' % outfile.name) def _OutputMapToHtmlFile(string_map: StringMapType, result_header: str, output_file: IO) -> None: """Outputs a map to a file as a nested list. Args: string_map: The string map to output. result_header: A string containing the header contents placed before the nested list. output_file: A file-like object to output the map to. """ output_file.write('

%s

\n' % result_header) output_file.write('\n') def _RecursiveHtmlToFile(node: NodeType, output_file: IO) -> None: """Recursively outputs a string map to an output file as HTML. Specifically, contents are output as an unordered list (