Skip to content

Commit

Permalink
Honor verbosity options in tmt * show commands (#3445)
Browse files Browse the repository at this point in the history
The patch fixes it, but it's not perfect, e.g. verbosity inheritance may
be incorrect in some cases.
  • Loading branch information
happz authored Jan 23, 2025
1 parent c58edf2 commit cc72da8
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
14 changes: 14 additions & 0 deletions tests/plan/show/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@ rlJournalStart
rlAssertEquals "script shall be an replaced" "$(grep ' script ' $rlRun_LOG | awk '{print $2}')" "dummy-script"
rlPhaseEnd

rlPhaseStartTest "Test whether 'tmt', 'plans' and 'show' accept verbosity option"
rlRun -s "tmt plans show /plans/full"
rlAssertNotGrep "fmf-id url" $rlRun_LOG

rlRun -s "tmt plans show -v /plans/full"
rlAssertGrep "fmf-id url" $rlRun_LOG

rlRun -s "tmt plans -v show /plans/full"
rlAssertGrep "fmf-id url" $rlRun_LOG

rlRun -s "tmt -v plans show /plans/full"
rlAssertGrep "fmf-id url" $rlRun_LOG
rlPhaseEnd

rlPhaseStartCleanup
rlRun "popd"
rlRun "rm $output"
Expand Down
14 changes: 14 additions & 0 deletions tests/story/show/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ rlJournalStart
rlAssertGrep "Invalid name.*$story_name" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Test whether 'tmt', 'stories' and 'show' accept verbosity option"
rlRun -s "tmt stories show /stories/full"
rlAssertNotGrep "fmf-id url" $rlRun_LOG

rlRun -s "tmt stories show -v /stories/full"
rlAssertGrep "fmf-id url" $rlRun_LOG

rlRun -s "tmt stories -v show /stories/full"
rlAssertGrep "fmf-id url" $rlRun_LOG

rlRun -s "tmt -v stories show /stories/full"
rlAssertGrep "fmf-id url" $rlRun_LOG
rlPhaseEnd

rlPhaseStartCleanup
rlRun "popd"
rlPhaseEnd
Expand Down
14 changes: 14 additions & 0 deletions tests/test/show/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,20 @@ rlJournalStart
rlAssertGrep "/tests/disabled02" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Test whether 'tmt', 'tests' and 'show' accept verbosity option"
rlRun -s "tmt tests show /tests/full"
rlAssertNotGrep "fmf-id url" $rlRun_LOG

rlRun -s "tmt tests show -v /tests/full"
rlAssertGrep "fmf-id url" $rlRun_LOG

rlRun -s "tmt tests -v show /tests/full"
rlAssertGrep "fmf-id url" $rlRun_LOG

rlRun -s "tmt -v tests show /tests/full"
rlAssertGrep "fmf-id url" $rlRun_LOG
rlPhaseEnd

rlPhaseStartCleanup
rlRun "popd"
rlPhaseEnd
Expand Down
3 changes: 3 additions & 0 deletions tmt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,9 @@ def web_link(self) -> Optional[str]:
if self.fmf_id.ref is None or self.fmf_id.url is None:
return None

if not self.fmf_sources:
return None

# Detect relative path of the last source from the metadata tree root
relative_path = self.fmf_sources[-1].relative_to(self.node.root)
relative_path = Path('/') if str(relative_path) == '.' else Path('/') / relative_path
Expand Down
28 changes: 25 additions & 3 deletions tmt/cli/_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ def tests(context: Context, **kwargs: Any) -> None:
Convert old metadata into the new fmf format.
"""

context.obj.logger = context.obj.logger.clone() \
.apply_verbosity_options(**kwargs)

# Show overview of available tests
if context.invoked_subcommand is None:
tmt.Test.overview(context.obj.tree)
Expand Down Expand Up @@ -386,7 +389,11 @@ def tests_show(context: Context, **kwargs: Any) -> None:
Use '.' to select tests under the current working directory.
"""
tmt.Test.store_cli_invocation(context)
for test in context.obj.tree.tests():

logger = context.obj.logger.clone() \
.apply_verbosity_options(**kwargs)

for test in context.obj.tree.tests(logger=logger):
test.show()
echo()

Expand Down Expand Up @@ -746,6 +753,9 @@ def plans(context: Context, **kwargs: Any) -> None:
Explore detailed test step configuration.
"""

context.obj.logger = context.obj.logger.clone() \
.apply_verbosity_options(**kwargs)

# Show overview of available plans
if context.invoked_subcommand is None:
tmt.Plan.overview(context.obj.tree)
Expand Down Expand Up @@ -786,7 +796,11 @@ def plans_show(context: Context, **kwargs: Any) -> None:
Use '.' to select plans under the current working directory.
"""
tmt.Plan.store_cli_invocation(context)
for plan in context.obj.tree.plans():

logger = context.obj.logger.clone() \
.apply_verbosity_options(**kwargs)

for plan in context.obj.tree.plans(logger=logger):
plan.show()
echo()

Expand Down Expand Up @@ -929,6 +943,10 @@ def stories(context: Context, **kwargs: Any) -> None:
Check available user stories.
Explore coverage (test, implementation, documentation).
"""

context.obj.logger = context.obj.logger.clone() \
.apply_verbosity_options(**kwargs)

# Show overview of available stories
if context.invoked_subcommand is None:
tmt.Story.overview(context.obj.tree)
Expand Down Expand Up @@ -990,7 +1008,11 @@ def stories_show(
Use '.' to select stories under the current working directory.
"""
tmt.Story.store_cli_invocation(context)
for story in context.obj.tree.stories():

logger = context.obj.logger.clone() \
.apply_verbosity_options(**kwargs)

for story in context.obj.tree.stories(logger=logger):
if story._match(implemented, verified, documented, covered,
unimplemented, unverified, undocumented, uncovered):
story.show()
Expand Down

0 comments on commit cc72da8

Please sign in to comment.