-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This creates a Dependency class to make dependencies hashable. Thanks to this change, we can easily find duplicates and remove them. This change is really necessary for Job dependencies, where the duplicates can be easily created by adding the same dependency to a test and job. Signed-off-by: Jan Richter <[email protected]> Signed-off-by: Cleber Rosa <[email protected]>
- Loading branch information
Showing
7 changed files
with
120 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
# | ||
# See LICENSE for more details. | ||
# | ||
# Copyright: Red Hat Inc. 2024 | ||
# Authors: Jan Richter <[email protected]> | ||
|
||
from avocado.core.nrunner.runnable import Runnable | ||
|
||
|
||
class Dependency: | ||
""" | ||
Data holder for dependency. | ||
""" | ||
|
||
def __init__(self, kind=None, uri=None, args=(), kwargs=None): | ||
self._kind = kind | ||
self._uri = uri | ||
self._args = args | ||
self._kwargs = kwargs or {} | ||
|
||
@property | ||
def kind(self): | ||
return self._kind | ||
|
||
@property | ||
def uri(self): | ||
return self._uri | ||
|
||
@property | ||
def args(self): | ||
return self._args | ||
|
||
@property | ||
def kwargs(self): | ||
return self._kwargs | ||
|
||
def __hash__(self): | ||
return hash( | ||
( | ||
self.kind, | ||
self.uri, | ||
tuple(sorted(self.args)), | ||
tuple(sorted(self.kwargs.items())), | ||
) | ||
) | ||
|
||
def __eq__(self, other): | ||
if isinstance(other, Dependency): | ||
return hash(self) == hash(other) | ||
return False | ||
|
||
def to_runnable(self, config): | ||
return Runnable(self.kind, self.uri, *self.args, config=config, **self.kwargs) | ||
|
||
@classmethod | ||
def from_dictionary(cls, dictionary): | ||
return cls( | ||
dictionary.pop("type", None), | ||
dictionary.pop("uri", None), | ||
dictionary.pop("args", ()), | ||
dictionary, | ||
) |
This file contains 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 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 |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
# Copyright: Red Hat Inc. 2021 | ||
# Authors: Willian Rampazzo <[email protected]> | ||
|
||
from avocado.core.nrunner.runnable import Runnable | ||
from avocado.core.plugin_interfaces import PreTest | ||
|
||
|
||
|
@@ -33,15 +32,7 @@ def pre_test_runnables(test_runnable, suite_config=None): # pylint: disable=W02 | |
if not test_runnable.dependencies: | ||
return [] | ||
dependency_runnables = [] | ||
for dependency in test_runnable.dependencies: | ||
# make a copy to change the dictionary and do not affect the | ||
# original `dependencies` dictionary from the test | ||
dependency_copy = dependency.copy() | ||
kind = dependency_copy.pop("type") | ||
uri = dependency_copy.pop("uri", None) | ||
args = dependency_copy.pop("args", ()) | ||
dependency_runnable = Runnable( | ||
kind, uri, *args, config=test_runnable.config, **dependency_copy | ||
) | ||
dependency_runnables.append(dependency_runnable) | ||
unique_dependencies = list(dict.fromkeys(test_runnable.dependencies)) | ||
for dependency in unique_dependencies: | ||
dependency_runnables.append(dependency.to_runnable(test_runnable.config)) | ||
return dependency_runnables |
This file contains 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 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 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 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