diff --git a/bash_completion.sh b/bash_completion.sh index 67814b1e5..fc9617bd0 100644 --- a/bash_completion.sh +++ b/bash_completion.sh @@ -162,7 +162,7 @@ _buildtest () local opts="--end --failure --filter --format --help --helpfilter --helpformat --latest --no-header --oldest --pager --passed --start --terse -e -f -h -n -p -s -t clear list summary" COMPREPLY=( $( compgen -W "$opts" -- $cur ) ) case "${COMP_WORDS[2]}" in summary) - local opts="-h --help --pager" + local opts="-d -h --detailed --help --pager" COMPREPLY=( $( compgen -W "${opts}" -- $cur ) ) ;; esac @@ -250,7 +250,7 @@ _buildtest () case ${COMP_WORDS[3]} in # completion for rest of arguments *) - local longopts=" --pager" + local longopts="--pager" local shortopts="-p" local allopts="${longopts} ${shortopts}" COMPREPLY=( $( compgen -W "${allopts}" -- $cur ) );; diff --git a/buildtest/cli/__init__.py b/buildtest/cli/__init__.py index 2803dded4..68ce275d1 100644 --- a/buildtest/cli/__init__.py +++ b/buildtest/cli/__init__.py @@ -960,6 +960,9 @@ def report_menu(subparsers): parser_report_summary.add_argument( "--pager", action="store_true", help="Enable PAGING when viewing result" ) + parser_report_summary.add_argument( + "--detailed", "-d", action="store_true", help="Enable a more detailed report" + ) def inspect_menu(subparsers): diff --git a/buildtest/cli/report.py b/buildtest/cli/report.py index 2b2f60245..b8cc3a9f0 100644 --- a/buildtest/cli/report.py +++ b/buildtest/cli/report.py @@ -90,6 +90,7 @@ def __init__( oldest=None, count=None, pager=None, + detailed=None, ): """ Args: @@ -503,7 +504,7 @@ def print_filter_fields(self): console.print(table) def print_report( - self, terse=None, noheader=None, title=None, count=None, color=None + self, terse=None, noheader=None, title=None, count=None, pager=None, color=None ): """This method will print report table after processing report file. By default we print output in table format but this can be changed to terse format which will print output in parseable format. @@ -511,6 +512,7 @@ def print_report( Args: terse (bool, optional): Print output int terse format noheader (bool, optional): Determine whether to print header in terse format + pager (bool, optional): Paginate output of report table color (str, optional): An instance of a string class that tells print_report what color the output should be printed in. In this example, we display output in tabular format which works with ``--filter`` and ``--format`` option. @@ -573,12 +575,7 @@ def print_report( join_list = [] title = title or f"Report File: {self.reportfile()}" table = Table(title=title, show_lines=True, expand=True) - consoleColor = Color.default().name - if color is not None: - try: - consoleColor = Color.parse(color).name - except ColorParseError: - consoleColor = Color.default().name + consoleColor = checkColor(color=color) for field in self.display_table.keys(): table.add_column( @@ -595,7 +592,7 @@ def print_report( for row in transpose_list: table.add_row(*row) - if self.pager: + if pager or self.pager: with console.pager(): console.print(table) @@ -792,10 +789,9 @@ def report_cmd(args, report_file=None): oldest=args.oldest, report_file=report_file, count=args.count, - pager=args.pager, ) if args.report_subcommand == "summary": - report_summary(results, args.pager) + report_summary(results, pager=args.pager, detailed=args.detailed) return if args.helpfilter: @@ -809,21 +805,23 @@ def report_cmd(args, report_file=None): results.print_report(terse=args.terse, noheader=args.no_header, count=args.count) -def report_summary(report, pager=None, color=None): - """This method will print summary for report file which can be retrieved via ``buildtest report summary`` command""" +def report_summary(report, pager=None, detailed=None, color=None): + """This method will print summary for report file which can be retrieved via ``buildtest report summary`` command + Args: + pager (bool): An instance of bool, flag for turning on pagination. + detailed (bool): An instance of bool, flag for printing a detailed report. + color (str): An instance of str, color that the report should be printed in + """ test_breakdown = report.breakdown_by_test_names() - if color is None: + if not color: table = Table(title="Breakdown by test", header_style="blue") table.add_column("Name", style="cyan") table.add_column("Total Pass", style="green") table.add_column("Total Fail", style="red") table.add_column("Total Runs", style="blue") else: - try: - consoleColor = Color.parse(color).name - except ColorParseError: - consoleColor = Color.default().name + consoleColor = checkColor(color=color) table = Table(title="Breakdown by test", header_style=consoleColor) table.add_column("Name", style=consoleColor) table.add_column("Total Pass", style=consoleColor) @@ -837,7 +835,6 @@ def report_summary(report, pager=None, color=None): str(test_breakdown[k]["fail"]), str(test_breakdown[k]["runs"]), ) - pass_results = Report( filter_args={"state": "PASS"}, format_args="name,id,executor,state,returncode,runtime", @@ -849,18 +846,28 @@ def report_summary(report, pager=None, color=None): format_args="name,id,executor,state,returncode,runtime", report_file=report.reportfile(), ) + if pager: with console.pager(): print_report_summary_output( - report, table, pass_results, fail_results, color=color + report, + table, + pass_results, + fail_results, + color=color, + detailed=detailed, ) return - print_report_summary_output(report, table, pass_results, fail_results, color=color) + print_report_summary_output( + report, table, pass_results, fail_results, color=color, detailed=detailed + ) -def print_report_summary_output(report, table, pass_results, fail_results, color=None): +def print_report_summary_output( + report, table, pass_results, fail_results, color=None, detailed=None +): """Print output of ``buildtest report summary``. Args: @@ -869,15 +876,31 @@ def print_report_summary_output(report, table, pass_results, fail_results, color pass_results (buildtest.cli.report.Report): An instance of Report class with filtered output by ``state=PASS`` fail_results (buildtest.cli.report.Report): An instance of Report class with filtered output by ``state=FAIL`` color (str): An instance of a string class that tells print_report_summary what color the output should be printed in. + detailed (bool, optional): Print detailed output of the report summary if ``buildtest report summary --detailed`` is specified """ + console.print("Report File: ", report.reportfile()) console.print("Total Tests:", len(report.get_testids())) console.print("Total Tests by Names: ", len(report.get_names())) console.print("Number of buildspecs in report: ", len(report.get_buildspecs())) + + if not detailed: + return + console.print(table) - if color is None: - pass_results.print_report(title="PASS Tests", color="green") - fail_results.print_report(title="FAIL Tests", color="red") - else: - pass_results.print_report(title="PASS Tests", color=color) - fail_results.print_report(title="FAIL Tests", color=color) + + pass_color = color or "green" + fail_color = color or "red" + + pass_results.print_report(title="PASS Tests", color=pass_color) + fail_results.print_report(title="FAIL Tests", color=fail_color) + + +def checkColor(color): + checkedColor = Color.default().name + if color: + try: + checkedColor = Color.parse(color).name + except ColorParseError: + checkedColor = Color.default().name + return checkedColor diff --git a/docs/gettingstarted/query_test_report.rst b/docs/gettingstarted/query_test_report.rst index 3e263b9a3..01a7b7d06 100644 --- a/docs/gettingstarted/query_test_report.rst +++ b/docs/gettingstarted/query_test_report.rst @@ -283,14 +283,21 @@ output, if you want to disable output of header you can use ``--no-header`` opti Report Summary (``buildtest report summary``) ---------------------------------------------- -The ``buildtest report summary`` command can be used to provide a summary of the test report -with breakdown statistics of tests including all fail tests, number of tests by name, test runs -and buildspecs in report file. +The ``buildtest report summary`` command can be used to provide a short summary of the test report. Shown below is an example output from the report summary. .. command-output:: buildtest report summary +The ``buildtest report summary --detailed`` command can be used to provide a summary of the test report +with breakdown statistics of tests including all fail tests, number of tests by name, test runs +and buildspecs in report file. To see a short report use + +Shown below is an example output from the report summary --detailed. + +.. command-output:: buildtest report summary --detailed + + .. _inspect_test: Inspect Tests Records via ``buildtest inspect`` diff --git a/tests/cli/test_report.py b/tests/cli/test_report.py index bc0347a2d..5ec9bc71e 100644 --- a/tests/cli/test_report.py +++ b/tests/cli/test_report.py @@ -195,11 +195,35 @@ def test_report_summary(): report = Report(pager=True) report_summary(report) + report = Report(detailed=True) + report_summary(report) + + report = Report(pager=True, detailed=True) + report_summary(report) + report = Report() report_summary(report, color="light_pink1") + report = Report(pager=True, detailed=True) + report_summary(report, color="light_pink1") + + report = Report(detailed=True) + report_summary(report, color="light_pink1") + + report = Report(pager=True) + report_summary(report, color="light_pink1") + report = Report() - report_summary(report, color="BAD_COLOR") # For system to use default color + report_summary(report, color="BAD_COLOR") + + report = Report(pager=True, detailed=True) + report_summary(report, color="BAD_COLOR") + + report = Report(detailed=True) + report_summary(report, color="BAD_COLOR") + + report = Report(pager=True) + report_summary(report, color="BAD_COLOR") @pytest.mark.cli