Skip to content

Commit

Permalink
Tags Filtering Fix
Browse files Browse the repository at this point in the history
Filtering now properly handles both verbose and non-verbose output modes
while checking for tag matches.
without changing the existing behavior that users expect when using
'avocado list -t <tag>'

Reference:      #6066
Signed-off-by: Harvey Lynden <[email protected]>
  • Loading branch information
harvey0100 committed Dec 16, 2024
1 parent 91752d4 commit 5c20a23
Showing 1 changed file with 44 additions and 17 deletions.
61 changes: 44 additions & 17 deletions avocado/plugins/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ def _display(self, suite, matrix):
TERM_SUPPORT.header_str("Tag(s)"),
)

# Any kind of color, string format and term specific should be applied
# only during output/display phase. So this seems to be a better place
# for this:
matrix = self._prepare_matrix_for_display(matrix, verbose)

for line in iter_tabular_output(matrix, header=header, strip=True):
LOG_UI.debug(line)

Expand Down Expand Up @@ -133,6 +129,39 @@ def _display_extra(suite, verbose=True):
for key in sorted(suite.tags_stats):
LOG_UI.info("%s: %s", key, suite.tags_stats[key])

@staticmethod
def _matches_tag_filter(runnable, filter_by_tags):
"""Check if runnable matches the tag filter criteria.
:param runnable: The runnable to check
:param filter_by_tags: List of tags to filter by
:returns: True if runnable matches filter, False otherwise
"""
if not filter_by_tags:
return True
if not runnable.tags:
return False
return any(tag in runnable.tags for tag in filter_by_tags)

@staticmethod
def _build_matrix_entry(runnable, resolution, verbose):
"""Build a matrix entry for the given runnable.
:param runnable: The runnable to create entry for
:param resolution: The resolution containing the runnable
:param verbose: Whether to include verbose information
:returns: Tuple containing matrix entry
"""
if verbose:
return (
runnable.kind,
runnable.identifier,
runnable.uri,
resolution.origin,
runnable.tags or {},
)
return (runnable.kind, runnable.identifier)

@staticmethod
def _get_resolution_matrix(suite):
"""Used for resolver.
Expand All @@ -142,21 +171,19 @@ def _get_resolution_matrix(suite):
"""
test_matrix = []
verbose = suite.config.get("core.verbose")
filter_by_tags = suite.config.get("filter.by_tags.tags")

for resolution in suite.resolutions:
if resolution.result != ReferenceResolutionResult.SUCCESS:
continue

for runnable in resolution.resolutions:
if verbose:
tags = runnable.tags or {}
test_matrix.append(
(
runnable.kind,
runnable.identifier,
runnable.uri,
resolution.origin,
tags,
)
)
else:
test_matrix.append((runnable.kind, runnable.identifier))
if not List._matches_tag_filter(runnable, filter_by_tags):
continue

entry = List._build_matrix_entry(runnable, resolution, verbose)
test_matrix.append(entry)

return test_matrix

@staticmethod
Expand Down

0 comments on commit 5c20a23

Please sign in to comment.