Skip to content

Commit f83cbba

Browse files
committed
Add common tests for input generators of common relax workflow
The newly added test will automatically parametrize over all the implementations of the common relax workflow that register an entry point. The test checks that the signature of the `get_builder` method, as built dynamically through the input generator specification in the `define` method, respects the criteria of the common interface. This means that all the required ports are present and that their valid types are what they should be. This should hopefully catch if implementations change the specification accidentally in a way that is not intended. In the future, ideally we can extend these tests with tests that actually try to call `get_builder`, such that we can also verify that it successfully returns a builder when using any of the values that are defined as supported for the various arguments, such as for the `spin_type`, `relax_type` and `electronic_type`. However, this is technically not easy as calling `get_builder` may depend on certain pre-conditions being fulfilled depending on the implementation. For example, the Quantum ESPRESSO would require a version of the `SsspFamily` to be installed. We would need to find a way to automatically load these fixtures based on the implementation that is being tested.
1 parent 03556c6 commit f83cbba

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# -*- coding: utf-8 -*-
2+
"""Tests for the :mod:`aiida_common_workflows.workflows.relax.quantum_espresso` module."""
3+
# pylint: disable=redefined-outer-name
4+
import pytest
5+
6+
from aiida import engine
7+
from aiida import orm
8+
from aiida import plugins
9+
10+
from aiida_common_workflows.common.types import ElectronicType, RelaxType, SpinType
11+
from aiida_common_workflows.generators.ports import InputGeneratorPort
12+
from aiida_common_workflows.plugins import get_workflow_entry_point_names
13+
from aiida_common_workflows.workflows.relax.workchain import CommonRelaxWorkChain
14+
15+
16+
@pytest.fixture(scope='function', params=get_workflow_entry_point_names('relax'))
17+
def workchain(request) -> CommonRelaxWorkChain:
18+
"""Fixture that parametrizes over all the registered implementations of the ``CommonRelaxWorkChain``."""
19+
return plugins.WorkflowFactory(request.param)
20+
21+
22+
def test_spec(workchain):
23+
"""Test that the input specification of all implementations respects the common interface."""
24+
generator = workchain.get_input_generator()
25+
generator_spec = generator.spec()
26+
27+
required_ports = {
28+
'structure': {
29+
'valid_type': plugins.DataFactory('structure')
30+
},
31+
'protocol': {
32+
'valid_type': str
33+
},
34+
'spin_type': {
35+
'valid_type': SpinType
36+
},
37+
'relax_type': {
38+
'valid_type': RelaxType
39+
},
40+
'electronic_type': {
41+
'valid_type': ElectronicType
42+
},
43+
'magnetization_per_site': {
44+
'valid_type': list
45+
},
46+
'threshold_forces': {
47+
'valid_type': float
48+
},
49+
'threshold_stress': {
50+
'valid_type': float
51+
},
52+
'reference_workchain': {
53+
'valid_type': orm.WorkChainNode
54+
},
55+
'engines': {}
56+
}
57+
58+
for port_name, values in required_ports.items():
59+
assert isinstance(generator_spec.inputs.get_port(port_name), (InputGeneratorPort, engine.PortNamespace))
60+
61+
if 'valid_type' in values:
62+
assert generator_spec.inputs.get_port(port_name).valid_type is values['valid_type']

0 commit comments

Comments
 (0)