Skip to content

Commit

Permalink
Merge branch 'main' into docker-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhollas committed May 24, 2024
2 parents 57f209d + e952d77 commit 2f92c27
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
11 changes: 6 additions & 5 deletions docs/source/topics/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -786,17 +786,18 @@ Return a :class:`~aiida.manage.tests.pytest_fixtures.EntryPointManager` instance

.. code-block:: python
from aiida.parsers import Parser
class CustomParser(Parser):
"""Parser implementation."""
def test_parser(entry_points):
"""Test a custom ``Parser`` implementation."""
from aiida.parsers import Parser
from aiida.plugins import ParserFactory
class CustomParser(Parser):
"""Parser implementation."""
entry_points.add(CustomParser, 'aiida.parsers:custom.parser')
assert ParserFactory('custom.parser', CustomParser)
assert ParserFactory('custom.parser') is CustomParser
Any entry points additions and removals are automatically undone at the end of the test.

Expand Down
4 changes: 3 additions & 1 deletion src/aiida/cmdline/commands/cmd_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def plugin_list(entry_point_group, entry_point):
echo.echo_critical(str(exception))
else:
try:
if (inspect.isclass(plugin) and issubclass(plugin, Process)) or plugin.is_process_function:
if (inspect.isclass(plugin) and issubclass(plugin, Process)) or (
hasattr(plugin, 'is_process_function') and plugin.is_process_function
):
print_process_info(plugin)
else:
echo.echo(str(plugin.get_description()))
Expand Down
19 changes: 18 additions & 1 deletion tests/cmdline/commands/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

import pytest
from aiida.cmdline.commands import cmd_plugin
from aiida.plugins import CalculationFactory, WorkflowFactory
from aiida.parsers import Parser
from aiida.plugins import CalculationFactory, ParserFactory, WorkflowFactory
from aiida.plugins.entry_point import ENTRY_POINT_GROUP_TO_MODULE_PATH_MAP


Expand Down Expand Up @@ -56,3 +57,19 @@ def test_plugin_list_detail(run_cli_command, entry_point_string):

result = run_cli_command(cmd_plugin.plugin_list, [entry_point_group, entry_point_name])
assert entry_point.__doc__ in result.output


class CustomParser(Parser):
@classmethod
def get_description(cls) -> str:
return 'str69'


def test_plugin_description(run_cli_command, entry_points):
"""Test that ``verdi plugin list`` uses ``get_description`` if defined."""

entry_points.add(CustomParser, 'aiida.parsers:custom.parser')
assert ParserFactory('custom.parser') is CustomParser

result = run_cli_command(cmd_plugin.plugin_list, ['aiida.parsers', 'custom.parser'])
assert result.output.strip() == 'str69'

0 comments on commit 2f92c27

Please sign in to comment.