-
Notifications
You must be signed in to change notification settings - Fork 117
[feat] Add support for class directives #1868
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
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3d20133
Add support for class directives
d5e343b
Remove unused imports
234b3ac
Apply directives in `__rfm_init__` instead of `__init__`
dd3d7b9
Merge branch 'master' into feat/directives
5816767
Add skip and skip_if directives and address PR comments
170fc4f
Document the directives
47fcb19
Remove unused import
a01d3dc
Merge branch 'master' into feat/directives
eb35fbe
Use `__getattribute__()` to implement the aliasing for directives
625de21
Update documentation + remove unnecessary function
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 |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # Copyright 2016-2021 Swiss National Supercomputing Centre (CSCS/ETH Zurich) | ||
| # ReFrame Project Developers. See the top-level LICENSE file for details. | ||
| # | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| # | ||
| # Base classes to manage the namespace of a regression test. | ||
| # | ||
|
|
||
| '''ReFrame Directives | ||
|
|
||
| A directive makes available a method defined in a class to the execution of | ||
| the class body during its creation. | ||
|
|
||
| A directive simply captures the arguments passed to it and all directives are | ||
| stored in a registry inside the class. When the final object is created, they | ||
| will be applied to that instance by calling the target method on the freshly | ||
| created object. | ||
| ''' | ||
|
|
||
| NAMES = ('depends_on', 'skip', 'skip_if') | ||
|
|
||
|
|
||
| class _Directive: | ||
| '''A test directive. | ||
|
|
||
| A directive captures the arguments passed to it, so as to call an actual | ||
| object function later on during the test's initialization. | ||
|
|
||
| ''' | ||
|
|
||
| def __init__(self, name, *args, **kwargs): | ||
| self._name = name | ||
| self._args = args | ||
| self._kwargs = kwargs | ||
|
|
||
| def __repr__(self): | ||
| cls = type(self).__qualname__ | ||
| return f'{cls}({self.name!r}, {self.args}, {self.kwargs})' | ||
|
|
||
| @property | ||
| def name(self): | ||
| return self._name | ||
|
|
||
| @property | ||
| def args(self): | ||
| return self._args | ||
|
|
||
| @property | ||
| def kwargs(self): | ||
| return self._kwargs | ||
|
|
||
| def apply(self, obj): | ||
| fn = getattr(obj, self.name) | ||
| fn(*self.args, **self.kwargs) | ||
|
|
||
|
|
||
| class DirectiveRegistry: | ||
| def __init__(self): | ||
| self.__directives = [] | ||
|
|
||
| @property | ||
| def directives(self): | ||
| return self.__directives | ||
|
|
||
| def add(self, name, *args, **kwargs): | ||
| self.__directives.append(_Directive(name, *args, **kwargs)) | ||
|
|
||
|
|
||
| def apply(cls, obj): | ||
| '''Apply all directives of class ``cls`` to the object ``obj``.''' | ||
|
|
||
| for c in cls.mro(): | ||
| if hasattr(c, '_rfm_dir_registry'): | ||
| for d in c._rfm_dir_registry.directives: | ||
| d.apply(obj) |
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.
This is already true with the post-init hook, right? I think we should just avoid mentioning
__init__in the new docs and just refer to the recommended syntax.