-
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.
Fix bug in
Code.get_full_text_info
(#4083)
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
Showing
2 changed files
with
55 additions
and
11 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
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 |