Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeTranslator: do not assume get_export_formats exists #4188

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions aiida/restapi/translator/nodes/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,17 +416,14 @@ def get_all_download_formats(full_type=None):
for name in get_entry_point_names(entry_point_group):
try:
node_cls = load_entry_point(entry_point_group, name)
except LoadingEntryPointError:
pass
else:
node_cls.get_export_formats()
try:
available_formats = node_cls.get_export_formats()
if available_formats:
full_type = construct_full_type(node_cls.class_node_type, '')
all_formats[full_type] = available_formats
except AttributeError:
pass
except (AttributeError, LoadingEntryPointError):
continue

if available_formats:
full_type = construct_full_type(node_cls.class_node_type, '')
all_formats[full_type] = available_formats

return all_formats

@staticmethod
Expand Down
15 changes: 15 additions & 0 deletions tests/restapi/test_translator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Tests for the `aiida.restapi.translator` module."""
# pylint: disable=invalid-name
from aiida.restapi.translator.nodes.node import NodeTranslator
from aiida.orm import Data


def test_get_all_download_formats():
"""Test the `get_all_download_formats` method."""
NodeTranslator.get_all_download_formats()


def test_get_all_download_formats_missing_get_export_formats(monkeypatch):
"""Test `get_all_download_formats` does not except if a `Data` class does not implement `get_export_formats`."""
monkeypatch.delattr(Data, 'get_export_formats')
NodeTranslator.get_all_download_formats()