Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for global pager option #1392

Merged
merged 6 commits into from
Feb 21, 2023
Merged
14 changes: 7 additions & 7 deletions bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,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="--end --fail --filter --filterfields --format --formatfields --help --helpfilter --helpformat --latest --no-header --oldest --pass --row-count --start --terse -e -f -h -n -p -s -t c clear l list p path sm summary"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )
case ${prev} in --color)
COMPREPLY=( $( compgen -W "$(_supported_colors)" -- $cur ) )
Expand Down Expand Up @@ -241,7 +241,7 @@ _buildtest ()
local opts="-h --help"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) );;
view|v)
local opts="--help --pager --theme -h -p -t"
local opts="--help --theme -h -p -t"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )

case "${prev}" in --theme|-t)
Expand Down Expand Up @@ -305,7 +305,7 @@ _buildtest ()
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) );;
# completion for rest of arguments
*)
local longopts="--buildspec --count --executors --filter --filterfields --format --formatfields --group-by-executor --group-by-tags --help --helpfilter --helpformat --no-header --pager --paths --quiet --rebuild --row-count --tags --root --terse"
local longopts="--buildspec --count --executors --filter --filterfields --format --formatfields --group-by-executor --group-by-tags --help --helpfilter --helpformat --no-header --paths --quiet --rebuild --row-count --tags --root --terse"
local shortopts="-b -e -h -n -p -q -r -t"
local subcmds="invalid"
local allopts="${longopts} ${shortopts} ${subcmds}"
Expand All @@ -329,8 +329,8 @@ _buildtest ()
case ${COMP_WORDS[3]} in
# completion for rest of arguments
*)
local longopts="--pager"
local shortopts="-p"
local longopts="--help"
local shortopts="-h"
local allopts="${longopts} ${shortopts}"
COMPREPLY=( $( compgen -W "${allopts}" -- $cur ) );;
esac
Expand Down Expand Up @@ -393,7 +393,7 @@ _buildtest ()

case ${COMP_WORDS[2]} in
list)
local opts="--help --no-header --pager --terse -h -n -t"
local opts="--help --no-header --terse -h -n -t"
COMPREPLY=( $( compgen -W "${opts}" -- $cur ) )

if [[ "${prev}" == "--color" ]]; then
Expand Down Expand Up @@ -446,7 +446,7 @@ _buildtest ()
*)
local cmds="build buildspec cd cdash clean config debugreport docs help info inspect history path report schema schemadocs stats stylecheck tutorial-examples unittests"
local alias_cmds="bd bc cg debug it h hy rt style test"
local opts="--color --config --debug --editor --help --helpcolor --logpath --loglevel --print-log --no-color --report --version --view-log -c -d -h -l -r -V"
local opts="--color --config --debug --editor --help --helpcolor --logpath --loglevel --print-log --no-color --pager --report --version --view-log -c -d -h -l -p -r -V"

case "${cur}" in
# print main options to buildtest
Expand Down
21 changes: 4 additions & 17 deletions buildtest/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ def get_parser():
action="store_true",
help="Print available color options in a table format.",
)
parser.add_argument(
"-p", "--pager", action="store_true", help="Enable PAGING when viewing result"
)
parser.add_argument("-r", "--report", help="Specify path to test report file")

subparsers = parser.add_subparsers(title="COMMANDS", dest="subcommands", metavar="")
Expand Down Expand Up @@ -415,9 +418,6 @@ def history_menu(subparsers):
action="store_true",
help="Print output in machine readable format",
)
list_parser.add_argument(
"--pager", action="store_true", help="Enabling PAGING when viewing result"
)

query = history_subparser.add_parser(
"query", help="Query information for a particular build"
Expand Down Expand Up @@ -767,9 +767,6 @@ def buildspec_menu(subparsers):
action="store_true",
help="Print total count of records from the table.",
)
buildspec_find.add_argument(
"--pager", action="store_true", help="Enable PAGING when viewing result"
)
buildspec_find.add_argument(
"-r",
"--rebuild",
Expand Down Expand Up @@ -825,13 +822,9 @@ def buildspec_menu(subparsers):
)

# buildtest buildspec summary
buildspec_summary = subparsers_buildspec.add_parser(
subparsers_buildspec.add_parser(
"summary", aliases=["sm"], help="Print summary of buildspec cache"
)
# buildtest buildspec summary options
buildspec_summary.add_argument(
"-p", "--pager", action="store_true", help="Enable PAGING when viewing result"
)
# buildtest buildspec validate
buildspec_validate = subparsers_buildspec.add_parser(
"validate", aliases=["val"], help="Validate buildspecs with JSON Schema"
Expand Down Expand Up @@ -913,9 +906,6 @@ def config_menu(subparsers):
help="Specify a color theme, Pygments style to use when displaying output. See https://pygments.org/docs/styles/#getting-a-list-of-available-styles for available themes",
choices=list(STYLE_MAP.keys()),
)
view_parser.add_argument(
"-p", "--pager", action="store_true", help="Enable PAGING when viewing result"
)
executor_group = executors.add_mutually_exclusive_group()

# buildtest config executors
Expand Down Expand Up @@ -1095,9 +1085,6 @@ def report_menu(subparsers):
action="store_true",
help="Print total count of records from the table.",
)
parser_report.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"
)
Expand Down
13 changes: 12 additions & 1 deletion buildtest/cli/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def print_buildspec_help():
"Discover and validate all buildspecs and load all validated buildspecs in cache",
)
table.add_row("buildtest buildspec find --rebuild", "Rebuild cache file")
table.add_row(
"buildtest --pager buildspec find", "Paginate output of buildspec cache"
)
table.add_row(
"buildtest buildspec find --root /tmp --rebuild",
"Discover buildspecs in /tmp and rebuild buildspec cache",
Expand Down Expand Up @@ -183,7 +186,8 @@ def print_buildspec_help():

table.add_row("buildtest buildspec summary", "Show summary of buildspec cache file")
table.add_row(
"buildtest buildspec summary --pager", "Pageants the output of summary"
"buildtest --pager buildspec summary",
"Paginate the output of summary for buildspec cache",
)
table.add_row(
"buildtest buildspec show python_hello",
Expand Down Expand Up @@ -237,6 +241,9 @@ def print_config_help():
table.add_column("Description", justify="left", style="magenta")

table.add_row("buildtest config view", "View content of configuration file")
table.add_row(
"buildtest --pager config view", "Paginate output of configuration file"
)
table.add_row(
"buildtest config validate", "Validate configuration file with JSON schema"
)
Expand Down Expand Up @@ -336,6 +343,7 @@ def print_report_help():
table.add_column("Description", justify="left", style="magenta")

table.add_row("buildtest report", "Display all test results")
table.add_row("buildtest --pager report", "Paginate output of test results")
table.add_row(
"buildtest report --filter returncode=0", "Filter test results by returncode=0"
)
Expand Down Expand Up @@ -378,6 +386,9 @@ def print_report_help():
table.add_row(
"buildtest report summary --detailed", "Show detailed summary of test report"
)
table.add_row(
"buildtest --pager report summary", "Paginate output of report summary"
)
console.print(table)


Expand Down
4 changes: 2 additions & 2 deletions docs/command_line_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ The ``buildtest rt summary`` can be useful if you want to summary of report file
Buildtest supports paging support with ``buildtest rt`` which can be useful when you
have lots of tests. To enable pagination you can run::

buildtest rt --pager
buildtest --pager rt

Finally we can filter test records and format table columns via ``--filter`` and ``--format`` option. Let's try
running the following command
Expand Down Expand Up @@ -257,7 +257,7 @@ We have an alias ``buildtest cg`` for **buildtest config** command. If you want

.. command-output:: buildtest cg view

We also support color themes (``buildtest cg view --theme <theme>``) and paging ``buildtest cg view --pager``.
We also support color themes (``buildtest cg view --theme <theme>``) when showing content of buildtest configuration.

Buildtest configuration file defines one or more :ref:`executors <configuring_executors>` that are used when
writing test. Every test must be run by an executor. To retrieve all executors in a flat-listing you can run::
Expand Down
48 changes: 30 additions & 18 deletions tests/cli/test_buildspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,19 @@ def test_func_buildspec_find():
# buildtest buildspec find --group-by-tags
cache.print_by_tags()

# implements buildtest buildspec find --helpfilter
# buildtest buildspec find --helpfilter
cache.print_filter_fields()

# implements buildtest buildspec find --helpformat
# buildtest buildspec find --helpformat
cache.print_format_fields()

# implements buildtest buildspec find --filterfields
# buildtest buildspec find --filterfields
cache.print_raw_filter_fields()

# implements buildtest buildspec find --formatfields
# buildtest buildspec find --formatfields
cache.print_raw_format_fields()

# buildtest buildspec find --pager
# buildtest --pager buildspec find
cache = BuildspecCache(configuration=configuration, pager=True)
cache.print_tags()
cache.print_buildspecfiles()
Expand All @@ -134,17 +134,28 @@ def test_func_buildspec_find():
# buildtest buildspec find --row-count --executors
cache.print_executors(row_count=True)

# test buildspec cache with color 'blue'
# test all commands with color 'blue'
# buildtest --color blue buildspec find --rebuild
cache = BuildspecCache(rebuild=True, configuration=configuration, color="blue")
# buildtest --color blue buildspec find
cache.print_buildspecs()
# buildtest --color blue buildspec find -b
cache.print_buildspecfiles()
# buildtest --color blue buildspec find -e
cache.print_executors()
# buildtest --color blue buildspec find -t
cache.print_tags()
# buildtest --color blue buildspec find --group-by-executor
cache.print_by_executors()
# buildtest --color blue buildspec find --group-by-tags
cache.print_by_tags()
# buildtest --color blue buildspec find --helpfilter
cache.print_filter_fields()
# buildtest --color blue buildspec find --helpformat
cache.print_format_fields()
# buildtest --color blue buildspec find --filterfields
cache.print_raw_filter_fields()
# buildtest --color blue buildspec find --formatfields
cache.print_raw_format_fields()


Expand Down Expand Up @@ -239,11 +250,11 @@ def test_edit_file():

@pytest.mark.cli
def test_buildspec_find_filter():
# testing buildtest buildspec find --filter tags=fail
# buildtest buildspec find --filter tags=fail
cache = BuildspecCache(filterfields={"tags": "fail"}, configuration=configuration)
cache.print_buildspecs()

# testing buildtest buildspec find --filter buildspec=$BUILDTEST_ROOT/tutorials/hello_world.yml
# buildtest buildspec find --filter buildspec=$BUILDTEST_ROOT/tutorials/hello_world.yml
cache = BuildspecCache(
filterfields={
"buildspec": os.path.join(BUILDTEST_ROOT, "tutorials", "hello_world.yml")
Expand All @@ -252,7 +263,7 @@ def test_buildspec_find_filter():
)
cache.print_buildspecs()

# testing buildtest buildspec find --filter type=script,executor=generic.local.sh,tags=fail
# buildtest buildspec find --filter type=script,executor=generic.local.sh,tags=fail
cache = BuildspecCache(
filterfields={
"type": "script",
Expand Down Expand Up @@ -280,7 +291,7 @@ def test_buildspec_find_filter():
# if we specify a directory path for buildspec filter this will raise an exception.
BuildspecCache(filterfields={"buildspec": tf.name}, configuration=configuration)

# testing buildtest buildspec find --filter key1=val1,key2=val2
# buildtest buildspec find --filter key1=val1,key2=val2
with pytest.raises(BuildTestError):
cache = BuildspecCache(
filterfields={"key1": "val1", "key2": "val2"}, configuration=configuration
Expand All @@ -290,7 +301,7 @@ def test_buildspec_find_filter():

@pytest.mark.cli
def test_buildspec_find_format():
# testing buildtest buildspec find --format name,type,tags,executor,description,buildspec
# buildtest buildspec find --format name,type,tags,executor,description,buildspec
cache = BuildspecCache(
formatfields="name,type,tags,executor,description,buildspec",
configuration=configuration,
Expand All @@ -299,7 +310,7 @@ def test_buildspec_find_format():

# Any invalid format fields will raise an exception of type BuildTestError
with pytest.raises(BuildTestError):
# testing buildtest buildspec find --format field1
# buildtest buildspec find --format field1
cache = BuildspecCache(formatfields="field1", configuration=configuration)
cache.print_buildspecs()

Expand All @@ -310,10 +321,10 @@ def test_buildspec_find_roots():
os.path.join(BUILDTEST_ROOT, "tests", "buildsystem"),
os.path.join(BUILDTEST_ROOT, "tutorials"),
]
# testing buildtest buildspec find --root $BUILDTEST_ROOT/tests/buildsystem --root $BUILDTEST_ROOT/tutorials
# buildtest buildspec find --root $BUILDTEST_ROOT/tests/buildsystem --root $BUILDTEST_ROOT/tutorials
BuildspecCache(roots=root_buildspecs, configuration=configuration)

# running buildtest buildspec find --root $BUILDTEST_ROOT/README.rst --root $BUILDTEST_ROOT/environment.yml
# buildtest buildspec find --root $BUILDTEST_ROOT/README.rst --root $BUILDTEST_ROOT/environment.yml
BuildspecCache(
roots=[
os.path.join(BUILDTEST_ROOT, "README.rst"),
Expand All @@ -325,10 +336,11 @@ def test_buildspec_find_roots():

@pytest.mark.cli
def test_buildspec_summary():
# test buildtest buildspec summary
# buildtest buildspec summary
summarize_buildspec_cache(
configuration=configuration, pager=False, color=Color.default().name
)
# buildtest --pager buildspec summary
summarize_buildspec_cache(configuration=configuration, pager=True)


Expand All @@ -338,10 +350,10 @@ def test_buildspec_show():

test_name = cache.get_random_tests(num_items=1)

# run buildtest buildspec show <test>
# buildtest buildspec show <test>
show_buildspecs(test_name, configuration)

# run buildtest buildspec <test> show --theme monokai
# buildtest buildspec <test> show --theme monokai
show_buildspecs(test_name, configuration, theme="monokai")

# testing invalid buildspec name, it should not raise exception
Expand All @@ -365,7 +377,7 @@ def test_buildspec_show_fail():
report = Report()
# get a random failed test from report file to be used for showing content of buildspec file
fail_tests = random.sample(report.get_test_by_state(state="FAIL"), 1)
# running buildtest buildspec show-fail <test> --theme monokai
# buildtest buildspec show-fail <test> --theme monokai
show_failed_buildspecs(
configuration=configuration, test_names=fail_tests, theme="monokai"
)
Loading