-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BaseRestartWorkChain
: add method to enable/disable process handlers
The `process_handler` decorator is updated with a new keyword argument `enabled` which is by default `True`. By setting it to `False` the process handler is disabled and will always be skipped during the `inspect_process` outline step. This default can be overridden on a per instance basis through a new input called `handler_overrides`. The base spec of `BaseRestartWorkChain` defines this new base input called `handler_overrides` which takes a mapping of process handler names to a boolean. For `True` the process handler is enabled and for `False` it is disabled, where disabled means that during the `inspect_process` call it is not called but skipped. The validator on the port ensures that the keys correspond to actual instance methods of the work chain that are decorated with `process_handler`. The value specified in `handler_overrides`, as the name suggests, override the default value specified in the decorator.
- Loading branch information
Showing
6 changed files
with
179 additions
and
27 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# -*- coding: utf-8 -*- | ||
########################################################################### | ||
# Copyright (c), The AiiDA team. All rights reserved. # | ||
# This file is part of the AiiDA code. # | ||
# # | ||
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-core # | ||
# For further information on the license, see the LICENSE.txt file # | ||
# For further information please visit http://www.aiida.net # | ||
########################################################################### | ||
"""Tests for `aiida.engine.processes.workchains.restart` module.""" | ||
from aiida.backends.testbase import AiidaTestCase | ||
from aiida.engine.processes.workchains.restart import BaseRestartWorkChain | ||
from aiida.engine.processes.workchains.utils import process_handler | ||
|
||
|
||
class TestBaseRestartWorkChain(AiidaTestCase): | ||
"""Tests for the `BaseRestartWorkChain` class.""" | ||
|
||
@staticmethod | ||
def test_is_process_handler(): | ||
"""Test the `BaseRestartWorkChain.is_process_handler` class method.""" | ||
|
||
class SomeWorkChain(BaseRestartWorkChain): | ||
"""Dummy class.""" | ||
|
||
@process_handler() | ||
def handler_a(self, node): | ||
pass | ||
|
||
def not_a_handler(self, node): | ||
pass | ||
|
||
assert SomeWorkChain.is_process_handler('handler_a') | ||
assert not SomeWorkChain.is_process_handler('not_a_handler') | ||
assert not SomeWorkChain.is_process_handler('unexisting_method') | ||
|
||
@staticmethod | ||
def test_get_process_handler(): | ||
"""Test the `BaseRestartWorkChain.get_process_handlers` class method.""" | ||
|
||
class SomeWorkChain(BaseRestartWorkChain): | ||
"""Dummy class.""" | ||
|
||
@process_handler | ||
def handler_a(self, node): | ||
pass | ||
|
||
def not_a_handler(self, node): | ||
pass | ||
|
||
assert [handler.__name__ for handler in SomeWorkChain.get_process_handlers()] == ['handler_a'] |
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