-
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.
Add support for process functions in
verdi plugin list
So far, only actual `Process` subclasses were supported, however, process functions can be turned into a `Process` subclass just as well. The wrapped function gets a new attribute `spec`, which when called returns the `ProcessSpec` that is dynamically built based on the function signature of the decorated function.
- Loading branch information
Showing
5 changed files
with
93 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""Pytest fixtures for command line interface tests.""" | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def run_cli_command(): | ||
"""Run a `click` command with the given options. | ||
The call will raise if the command triggered an exception or the exit code returned is non-zero | ||
""" | ||
|
||
def _run_cli_command(command, options=None, raises=None): | ||
"""Run the command and check the result. | ||
:param options: the list of command line options to pass to the command invocation | ||
:param raises: optionally an exception class that is expected to be raised | ||
""" | ||
import traceback | ||
from click.testing import CliRunner | ||
|
||
runner = CliRunner() | ||
result = runner.invoke(command, options or []) | ||
|
||
if raises is not None: | ||
assert result.exception is not None, result.output | ||
assert result.exit_code != 0 | ||
else: | ||
assert result.exception is None, ''.join(traceback.format_exception(*result.exc_info)) | ||
assert result.exit_code == 0, result.output | ||
|
||
result.output_lines = [line.strip() for line in result.output.split('\n') if line.strip()] | ||
|
||
return result | ||
|
||
return _run_cli_command |
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,43 @@ | ||
"""Tests for the `verdi plugin list` command.""" | ||
import pytest | ||
|
||
from aiida.cmdline.commands import cmd_plugin | ||
from aiida.plugins import CalculationFactory, WorkflowFactory | ||
|
||
|
||
def test_plugin_list(run_cli_command): | ||
"""Test the `verdi plugin list` command.""" | ||
from aiida.plugins.entry_point import ENTRY_POINT_GROUP_TO_MODULE_PATH_MAP | ||
|
||
# Call base command without parameters and check that all entry point groups are listed | ||
result = run_cli_command(cmd_plugin.plugin_list, []) | ||
for key in ENTRY_POINT_GROUP_TO_MODULE_PATH_MAP: | ||
assert key in result.output | ||
|
||
|
||
def test_plugin_list_group(run_cli_command): | ||
"""Test the `verdi plugin list` command for entry point group.""" | ||
from aiida.plugins.entry_point import ENTRY_POINT_GROUP_TO_MODULE_PATH_MAP | ||
|
||
# Call for each entry point group and just check it doesn't except | ||
for key in ENTRY_POINT_GROUP_TO_MODULE_PATH_MAP: | ||
run_cli_command(cmd_plugin.plugin_list, [key]) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'entry_point_string', ( | ||
'aiida.calculations:arithmetic.add', | ||
'aiida.workflows:arithmetic.multiply_add', | ||
'aiida.workflows:arithmetic.add_multiply', | ||
) | ||
) | ||
def test_plugin_list_detail(run_cli_command, entry_point_string): | ||
"""Test the `verdi plugin list` command for specific entry points.""" | ||
from aiida.plugins.entry_point import parse_entry_point_string | ||
|
||
entry_point_group, entry_point_name = parse_entry_point_string(entry_point_string) | ||
factory = CalculationFactory if entry_point_group == 'aiida.calculations' else WorkflowFactory | ||
entry_point = factory(entry_point_name) | ||
|
||
result = run_cli_command(cmd_plugin.plugin_list, [entry_point_group, entry_point_name]) | ||
assert entry_point.__doc__ in result.output |
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