Skip to content

Commit

Permalink
Fix bug in Code.get_full_text_info
Browse files Browse the repository at this point in the history
This method was not tested and so it went unnoticed that it was still
using the `_get_folder_pathsubfolder` repository method that has been
removed in `aiida-core==1.0.0`. Direct access to the folder underlying
the node repository is no longer allowed and instead the API should be
used to inspect the available objects, in this case `list_objects`.
  • Loading branch information
sphuber committed May 20, 2020
1 parent b86425f commit fa608e9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
20 changes: 9 additions & 11 deletions aiida/orm/nodes/data/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@
# For further information on the license, see the LICENSE.txt file #
# For further information please visit http://www.aiida.net #
###########################################################################

import os

from aiida.common.exceptions import ValidationError, EntryPointError, InputValidationError

from .data import Data

DEPRECATION_DOCS_URL = 'http://aiida-core.readthedocs.io/en/latest/concepts/processes.html#the-process-builder'

__all__ = ('Code',)


Expand Down Expand Up @@ -491,9 +487,12 @@ def get_builder(self):
return builder

def get_full_text_info(self, verbose=False):
"""Return a list of lists with a human-readable detailed information on this code.
:return: list of lists where each entry consists of two elements: a key and a value
"""
Return a (multiline) string with a human-readable detailed information on this computer
"""
from aiida.orm.utils.repository import FileType

result = []
result.append(['PK', self.pk])
result.append(['UUID', self.uuid])
Expand All @@ -508,11 +507,11 @@ def get_full_text_info(self, verbose=False):
result.append(['Type', 'local'])
result.append(['Exec name', self.get_execname()])
result.append(['List of files/folders:', ''])
for fname in self.list_object_names():
if self._repository._get_folder_pathsubfolder.isdir(fname):
result.append(['directory', fname])
for obj in self.list_objects():
if obj.type == FileType.DIRECTORY:
result.append(['directory', obj.name])
else:
result.append(['file', fname])
result.append(['file', obj.name])
else:
result.append(['Type', 'remote'])
result.append(['Remote machine', self.get_remote_computer().name])
Expand All @@ -536,7 +535,6 @@ def get_full_text_info(self, verbose=False):

@classmethod
def setup(cls, **kwargs):
# raise NotImplementedError
from aiida.cmdline.commands.code import CodeInputValidationClass
code = CodeInputValidationClass().set_and_validate_from_code(kwargs)

Expand Down
46 changes: 46 additions & 0 deletions tests/orm/data/test_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Tests for the `Code` class."""
# pylint: disable=redefined-outer-name
import pytest

from aiida.orm import Code


@pytest.fixture
def create_codes(tmpdir, aiida_localhost):
"""Create a local and remote `Code` instance."""
filename = 'add.sh'
filepath = str(tmpdir / filename) # Cast the filepath to str as Python 3.5 does not support Path objects for `open`

with open(filepath, 'w'):
pass

code_local = Code(local_executable=filename, files=[filepath]).store()
code_remote = Code(remote_computer_exec=(aiida_localhost, '/bin/true')).store()

return code_local, code_remote


@pytest.mark.usefixtures('clear_database_before_test')
def test_get_full_text_info(create_codes):
"""Test the `Code.get_full_text_info` method."""
for code in create_codes:
full_text_info = code.get_full_text_info()

assert isinstance(full_text_info, list)
assert ['PK', code.pk] in full_text_info
assert ['UUID', code.uuid] in full_text_info
assert ['Label', code.label] in full_text_info
assert ['Description', code.description] in full_text_info

if code.is_local():
assert ['Type', 'local'] in full_text_info
assert ['Exec name', code.get_execname()] in full_text_info
assert ['List of files/folders:', ''] in full_text_info
else:
assert ['Type', 'remote'] in full_text_info
assert ['Remote machine', code.computer.name] in full_text_info
assert ['Remote absolute path', code.get_remote_exec_path()] in full_text_info

for code in create_codes:
full_text_info = code.get_full_text_info(verbose=True)
assert ['Calculations', 0] in full_text_info

0 comments on commit fa608e9

Please sign in to comment.