Skip to content

Commit

Permalink
Merge pull request #1176 from buildtesters/Issue-1156-detailed-report…
Browse files Browse the repository at this point in the history
…-summary

add support for detailed summary via 'buildtest report summary --detailed'
  • Loading branch information
shahzebsiddiqui authored Aug 11, 2022
2 parents 3ead042 + 3fec0d1 commit 7c18b68
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 33 deletions.
4 changes: 2 additions & 2 deletions bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ) );;
Expand Down
3 changes: 3 additions & 0 deletions buildtest/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
77 changes: 50 additions & 27 deletions buildtest/cli/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def __init__(
oldest=None,
count=None,
pager=None,
detailed=None,
):
"""
Args:
Expand Down Expand Up @@ -503,14 +504,15 @@ 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.
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.
Expand Down Expand Up @@ -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(
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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",
Expand All @@ -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:
Expand All @@ -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
13 changes: 10 additions & 3 deletions docs/gettingstarted/query_test_report.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand Down
26 changes: 25 additions & 1 deletion tests/cli/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7c18b68

Please sign in to comment.