Skip to content

Commit

Permalink
Merge pull request #1567 from szuananwar/add_detailed_option
Browse files Browse the repository at this point in the history
Add --detailed option for buildtest report
  • Loading branch information
shahzebsiddiqui authored Aug 1, 2023
2 parents cdd05a4 + eedb821 commit 6ee4a47
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ _buildtest ()
;;

report|rt)
local opts="--end --fail --filter --filterfields --format --formatfields --help --helpfilter --helpformat --latest --no-header --oldest --pager --pass --row-count --start --terse -e -f -h -n -p -s -t c clear l list p path sm summary"
local opts="--detailed --end --fail --filter --filterfields --format --formatfields --help --helpfilter --helpformat --latest --no-header --oldest --pager --pass --row-count --start --terse -d -e -f -h -n -p -s -t c clear l list p path sm summary"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
case "${prev}" in --filter)
COMPREPLY=( $( compgen -W "$(_avail_report_filterfields)" -- $cur ) )
Expand Down
34 changes: 25 additions & 9 deletions buildtest/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ def build_menu(subparsers):
action="store_true",
help="Rerun last successful buildtest build command.",
)

filter_group.add_argument(
"-f",
"--filter",
Expand Down Expand Up @@ -1109,7 +1110,7 @@ def report_menu(subparsers, parent_parser):
help="Summarize test report",
parents=[parent_parser["pager"]],
)
filter_group = parser_report.add_argument_group("filter", "Filter and Format table")
filter_group = parser_report.add_argument_group("filter", "Filter options")

# buildtest report
filter_group.add_argument(
Expand All @@ -1118,28 +1119,43 @@ def report_menu(subparsers, parent_parser):
help="Filter report by filter fields. The filter fields must be a key=value pair and multiple fields can be comma separated in the following format: --filter key1=val1,key2=val2 . For list of filter fields run: --helpfilter.",
)

filter_group.add_argument(
"--format",
help="format field for printing purposes. For more details see --helpformat for list of available fields. Fields must be separated by comma (usage: --format <field1>,<field2>,...)",
)
filter_group.add_argument(
"--helpfilter",
action="store_true",
help="List available filter fields to be used with --filter option",
)
filter_group.add_argument(
"--helpformat", action="store_true", help="List of available format fields"
)

filter_group.add_argument(
"--filterfields",
action="store_true",
help="Print raw filter fields for --filter option to filter the report",
)
filter_group.add_argument(

format_group = parser_report.add_argument_group("format", "Format options")

format_group.add_argument(
"--helpformat", action="store_true", help="List of available format fields"
)

format_group.add_argument(
"--formatfields",
action="store_true",
help="Print raw format fields for --format option to format the report",
)

format_detailed_group = parser_report.add_mutually_exclusive_group()
format_detailed_group.add_argument(
"--format",
help="format field for printing purposes. For more details see --helpformat for list of available fields. Fields must be separated by comma (usage: --format <field1>,<field2>,...)",
)

format_detailed_group.add_argument(
"-d",
"--detailed",
help="Print a detailed summary of the test results",
action="store_true",
)

pass_fail = parser_report.add_mutually_exclusive_group()

pass_fail.add_argument(
Expand Down
17 changes: 17 additions & 0 deletions buildtest/cli/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ class Report:
"buildspec": [],
}

format_fields_detailed = (
"name,id,user,state,returncode,runtime,outfile,errfile,buildspec"
)

def __init__(
self,
configuration,
Expand All @@ -91,6 +95,7 @@ def __init__(
oldest=None,
count=None,
pager=None,
format_detailed=None,
detailed=None,
color=None,
):
Expand All @@ -108,6 +113,7 @@ def __init__(
oldest (bool, optional): Fetch oldest run for all tests discovered. This is specified via ``buildtest report --oldest``
count (int, optional): Fetch limited number of rows get printed for all tests discovered. This is specified via ``buildtest report --count``
pager (bool, optional): Enabling PAGING output for ``buildtest report``. This can be specified via ``buildtest report --pager``
format_detailed(bool, optional): Print a detailed summary of the test results. This can be specified via ``buildtest report --detailed``
color (str, optional): An instance of a string class that tells print_report what color the output should be printed in.
"""
Expand All @@ -126,6 +132,16 @@ def __init__(
self.color = color
self.input_report = report_file

# if detailed option is specified
if format_detailed:
self.format = self.format_fields_detailed

# if both format and detailed options are specified
if format_detailed and format_args:
raise BuildTestError(
"Argument -d/--detailed is not allowed with argument --format"
)

# if no report specified use default report
if not self.input_report:
self._reportfile = BUILD_REPORT
Expand Down Expand Up @@ -828,6 +844,7 @@ def report_cmd(args, configuration, report_file=None):
oldest=args.oldest,
report_file=report_file,
count=args.count,
format_detailed=args.detailed,
)

if args.report_subcommand in ["path", "p"]:
Expand Down
24 changes: 24 additions & 0 deletions docs/gettingstarted/query_test_report.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,30 @@ You may find it useful to fetch all failed records and determine pass/fail crite

.. _report_format_fields:

Detailed Reports (``buildtest report --detailed``)
---------------------------------------------------

The **buildtest report --detailed** option can be used to show a detailed test report that may be of interest when
examining a test. This option is synonymous to running ``buildtest report --format name,id,user,state,returncode,
runtime,outfile,errfile,buildspec``.
Shown below is an example output.

.. dropdown:: ``buildtest report --detailed``

.. command-output:: buildtest report --detailed

.. note::
The ``--detailed`` and ``--format`` options are mutually exclusive options because both options
will alter the format fields when displaying test results.

You will get the following error if you specify both options as shown below

.. dropdown:: ``buildtest report --detailed --format name``
:color: warning

.. command-output:: buildtest report --detailed --format name
:returncode: 2

Format Reports (``buildtest report --format``)
-----------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ docs = [
]
[tool.black]
required-version = '23.3.0'
target-version = ['py38', 'py39', 'py310']
target-version = ['py38', 'py39', 'py310', 'py311']
skip_magic_trailing_comma = true
line-length = 88
verbose = true
Expand Down
10 changes: 10 additions & 0 deletions tests/cli/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ def test_report():
result.print_report()


def test_report_detailed():
# buildtest report --detailed
Report(configuration=configuration, format_detailed=True)

# buildtest report --detailed --format name
with pytest.raises(BuildTestError):
Report(configuration=configuration, format_detailed=True, format_args="name")


@pytest.mark.cli
def test_report_format():
# buildtest report --helpformat
Expand Down Expand Up @@ -344,5 +353,6 @@ class args:
count = None
color = None
pager = None
detailed = None

report_cmd(args, configuration=configuration)

0 comments on commit 6ee4a47

Please sign in to comment.