Closed mbercx closed 9 months ago
Hehe, I was worried you might drop the word "tests". I'm also wondering what a good approach is for testing this change, maybe @sphuber can give a suggestion?
Hehe, I was worried you might drop the word "tests". I'm also wondering what a good approach is for testing this change, maybe @sphuber can give a suggestion?
Something like this?
from aiida.engine import WorkChain
from aiida_quantumespresso.workflows.ph.base import PhBaseWorkChain
class SubPhBaseWorkChain(WorkChain):
@classmethod
def define(cls, spec):
super().define(spec)
spec.expose_inputs(PhBaseWorkChain, exclude=('qpoints', 'qpoints_distance'))
def test_validate_inputs_excluded_qpoints_distance(generate_inputs_ph_base):
from aiida.engine.utils import instantiate_process
from aiida.manage.manager import get_manager
inputs = generate_inputs_ph_base
inputs.pop('qpoints', None)
inputs.pop('qpoints_distance', None)
runner = get_manager().get_runner()
instantiate_process(runner, SubPhBaseWorkChain, **inputs)
Currently, the top-level
validate_inputs
validator for thePhBaseWorkChain
will always check if either theqpoints
orqpoints_distance
inputs are provided. However, there are cases where a higher-level work chain that wraps thePhBaseWorkChain
might provide the q-points input on the fly. Such a work chain would have to set thePhBaseWorkChain
validator toNone
in its owndefine
method.However, as also discussed for a similar case for the
PwCalculation
in a389629, it's more elegant to check if theqpoints_distance
andqpoints
ports are present in the namespace. Typically a work chain that provides the q-points input on the fly will exclude these ports when exposing thePhBaseWorkChain
inputs. By checking if the ports are present in the validator, we avoid having to set the validator toNone
as well in the higher-level work chain.