-
Notifications
You must be signed in to change notification settings - Fork 172
Add a "collection of results" class for collection-wide actions #5027
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
Open
happz
wants to merge
2
commits into
results-drop-show
Choose a base branch
from
results-collection
base: results-drop-show
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,7 @@ | |
| simple_field, | ||
| ) | ||
| from tmt.options import ClickOptionDecoratorType, option | ||
| from tmt.result import ResultOutcome | ||
| from tmt.result import BaseResult, ResultOutcome, Results | ||
| from tmt.utils import ( | ||
| DEFAULT_NAME, | ||
| Command, | ||
|
|
@@ -1030,7 +1030,7 @@ def _load_results( | |
| self, | ||
| result_class: type[ResultT], | ||
| allow_missing: bool = False, | ||
| ) -> list[ResultT]: | ||
| ) -> tmt.result.Results[ResultT]: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| """ | ||
| Load results of this step from the workdir | ||
| """ | ||
|
|
@@ -1040,19 +1040,19 @@ def _load_results( | |
| try: | ||
| raw_results: list[Any] = self.plan.my_run.read_state(self.step_workdir / 'results') | ||
|
|
||
| return [result_class.from_serialized(raw_result) for raw_result in raw_results] | ||
| return Results(result_class.from_serialized(raw_result) for raw_result in raw_results) | ||
|
|
||
| except tmt.utils.FileError as exc: | ||
| if allow_missing: | ||
| self.debug(f'{self.__class__.__name__} results not found.', level=2) | ||
| return [] | ||
| return Results() | ||
|
|
||
| raise GeneralError('Cannot load step results.') from exc | ||
|
|
||
| except Exception as exc: | ||
| raise GeneralError('Cannot load step results.') from exc | ||
|
|
||
| def _save_results(self, results: Sequence['BaseResult']) -> None: | ||
| def _save_results(self, results: Sequence[BaseResult]) -> None: | ||
| """ | ||
| Save results of this step to the workdir | ||
| """ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |
| ResultGuestData, | ||
| ResultInterpret, | ||
| ResultOutcome, | ||
| Results, | ||
| ) | ||
| from tmt.steps import Action, ActionTask, PluginTask, Step | ||
| from tmt.steps.context.abort import AbortContext, AbortStep | ||
|
|
@@ -750,19 +751,19 @@ def prepare_tests(self, guest: Guest, logger: tmt.log.Logger) -> list[TestInvoca | |
| if self.should_run_again: | ||
| assert self.parent is not None # narrow type | ||
| assert isinstance(self.parent, Execute) # narrow type | ||
| self.parent._results = [ | ||
| self.parent._results = Results( | ||
| result | ||
| for result in self.parent._results | ||
| if not ( | ||
| test.name == result.name and test.serial_number == result.serial_number | ||
| ) | ||
| ] | ||
| ) | ||
|
|
||
| # Keep old results in another variable to have numbers only for actually executed tests | ||
| if self.should_run_again: | ||
| assert self.parent is not None # narrow type | ||
| assert isinstance(self.parent, Execute) # narrow type | ||
| self.parent._old_results = self.parent._results[:] | ||
| self.parent._old_results = Results(self.parent._results[:]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| self.parent._results.clear() | ||
|
|
||
| return invocations | ||
|
|
@@ -1079,8 +1080,8 @@ def __init__( | |
|
|
||
| super().__init__(plan=plan, raw_data=raw_data, logger=logger) | ||
| # List of Result() objects representing test results | ||
| self._results: list[tmt.Result] = [] | ||
| self._old_results: list[tmt.Result] = [] | ||
| self._results: Results[Result] = Results() | ||
| self._old_results: Results[Result] = Results() | ||
|
|
||
| @property | ||
| def _preserved_workdir_members(self) -> set[str]: | ||
|
|
@@ -1197,17 +1198,17 @@ def update_results(self, results: list['Result']) -> None: | |
| # Replace existing pending result with the new one. | ||
| results_to_save[(result.serial_number, result.name, result.guest.name)] = result | ||
|
|
||
| self._results = list(results_to_save.values()) | ||
| self._results = Results(results_to_save.values()) | ||
|
|
||
| def create_results(self, tests: list['tmt.steps.discover.TestOrigin']) -> list['Result']: | ||
| def create_results(self, tests: list['tmt.steps.discover.TestOrigin']) -> Results[Result]: | ||
| """ | ||
| Get all available results from tests. For tests not yet executed, create a pending | ||
| result. | ||
| """ | ||
|
|
||
| guests = self.plan.provision.get_guests_info() | ||
|
|
||
| results = [] | ||
| results: Results[Result] = Results() | ||
| for result, test_origin in self.results_for_tests(tests): | ||
| if result: | ||
| results.append(result) | ||
|
|
@@ -1327,7 +1328,7 @@ def go(self, force: bool = False) -> None: | |
|
|
||
| self._assert_required_tests_executed() | ||
|
|
||
| def results(self) -> list["tmt.result.Result"]: | ||
| def results(self) -> 'tmt.result.Results[tmt.result.Result]': | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| """ | ||
| Results from executed tests | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Override
__getitem__,__add__, andcopyin theResultsclass to preserve the customResultscollection type during slicing, concatenation, and copying operations. Slicing or copying a standardlistsubclass otherwise degrades the type back to a standardlist, which can cause runtime errors if collection-specific methods (like.summary()) are called on the resulting object.