diff --git a/aiida_quantumespresso/calculations/namelists.py b/aiida_quantumespresso/calculations/namelists.py index 99e0b7ed8..b0d82c3ab 100644 --- a/aiida_quantumespresso/calculations/namelists.py +++ b/aiida_quantumespresso/calculations/namelists.py @@ -172,15 +172,20 @@ def prepare_for_submission(self, folder): with folder.open(input_filename, 'w') as infile: infile.write(file_content) + symlink = settings.pop('PARENT_FOLDER_SYMLINK', False) + remote_copy_list = [] local_copy_list = [] + remote_symlink_list = [] + + ptr = remote_symlink_list if symlink else remote_copy_list # copy remote output dir, if specified parent_calc_folder = self.inputs.get('parent_folder', None) if parent_calc_folder is not None: if isinstance(parent_calc_folder, RemoteData): parent_calc_out_subfolder = settings.pop('PARENT_CALC_OUT_SUBFOLDER', self._INPUT_SUBFOLDER) - remote_copy_list.append(( + ptr.append(( parent_calc_folder.computer.uuid, os.path.join(parent_calc_folder.get_remote_path(), parent_calc_out_subfolder), self._OUTPUT_SUBFOLDER @@ -209,6 +214,7 @@ def prepare_for_submission(self, folder): calcinfo.codes_info = [codeinfo] calcinfo.local_copy_list = local_copy_list calcinfo.remote_copy_list = remote_copy_list + calcinfo.remote_symlink_list = remote_symlink_list # Retrieve by default the output file and the xml file calcinfo.retrieve_list = [] diff --git a/tests/calculations/test_pw2gw.py b/tests/calculations/test_pw2gw.py index 002729bdb..f10e5681f 100644 --- a/tests/calculations/test_pw2gw.py +++ b/tests/calculations/test_pw2gw.py @@ -1,18 +1,16 @@ # -*- coding: utf-8 -*- +# pylint: disable=redefined-outer-name """Tests for the `Pw2gwCalculation` class.""" +import os +import pytest + from aiida import orm from aiida.common import datastructures -from aiida_quantumespresso.utils.resources import get_default_options - - -def test_pw_default( - aiida_profile, fixture_localhost, fixture_sandbox, fixture_code, generate_calc_job, generate_remote_data, tmpdir, - file_regression -): - """Test a default `Pw2gwCalculation`.""" - entry_point_name = 'quantumespresso.pw2gw' +@pytest.fixture() +def parameters(): + """Fixture: parameters for pw calculation.""" parameters = { 'INPUTPP': { 'qplda': False, @@ -24,27 +22,78 @@ def test_pw_default( } } - parent = generate_remote_data( + return parameters + + +@pytest.fixture(params=[ + False, +], ids=[ + 'base', +]) +def settings(request): + """Fixture: parameters for z2pack calculation.""" + settings = {} + + if request.param: + settings['PARENT_FOLDER_SYMLINK'] = True + + return settings + + +@pytest.fixture +def remote(fixture_localhost, tmpdir, generate_remote_data): + """Fixture: Remote folder created by a CalcJob with inputs.""" + remote = generate_remote_data( fixture_localhost, str(tmpdir), 'quantumespresso.pw', ) + return remote + + +@pytest.fixture() +def inputs(fixture_code, remote, parameters, settings): + """Fixture: inputs for Z2packBaseWorkChain.""" + from aiida_quantumespresso.utils.resources import get_default_options + inputs = { - 'code': fixture_code(entry_point_name), + 'code': fixture_code('quantumespresso.pw2gw'), + 'parent_folder': remote, 'parameters': orm.Dict(dict=parameters), - 'parent_folder': parent, + 'settings': orm.Dict(dict=settings), 'metadata': { 'options': get_default_options() } } + return inputs + + +@pytest.mark.parametrize( + 'settings,with_symlink', [(False, False), (True, True)], ids=['base', 'with_symlink'], indirect=['settings'] +) +def test_pw2gw_default( + aiida_profile, fixture_sandbox, generate_calc_job, file_regression, remote, inputs, with_symlink +): + """Test a default `Pw2gwCalculation`.""" + entry_point_name = 'quantumespresso.pw2gw' calc_info = generate_calc_job(fixture_sandbox, entry_point_name, inputs) retrieve_list = ['aiida.out', 'epsX.dat', 'epsY.dat', 'epsZ.dat', 'epsTOT.dat'] + remote_copy_list = [ + (remote.computer.uuid, os.path.join(remote.get_remote_path(), path), path) for path in ['./pseudo/'] + ] + remote_symlink_list = [] + + ptr = remote_copy_list if not with_symlink else remote_symlink_list + ptr.extend([(remote.computer.uuid, os.path.join(remote.get_remote_path(), path), path) for path in ['./out/']]) + assert isinstance(calc_info, datastructures.CalcInfo) assert sorted(calc_info.retrieve_list) == sorted(retrieve_list) + assert sorted(calc_info.remote_copy_list) == sorted(remote_copy_list) + assert sorted(calc_info.remote_symlink_list) == sorted(remote_symlink_list) with fixture_sandbox.open('aiida.in') as handle: input_written = handle.read() diff --git a/tests/calculations/test_pw2gw/test_pw_default.in b/tests/calculations/test_pw2gw/test_pw2gw_default_base_.in similarity index 100% rename from tests/calculations/test_pw2gw/test_pw_default.in rename to tests/calculations/test_pw2gw/test_pw2gw_default_base_.in diff --git a/tests/calculations/test_pw2gw/test_pw2gw_default_with_symlink_.in b/tests/calculations/test_pw2gw/test_pw2gw_default_with_symlink_.in new file mode 100644 index 000000000..d1ca65e37 --- /dev/null +++ b/tests/calculations/test_pw2gw/test_pw2gw_default_with_symlink_.in @@ -0,0 +1,10 @@ +&INPUTPP + deltae = 1.0000000000d-03 + emax = 1.5000000000d+01 + emin = 0.0000000000d+00 + outdir = './out/' + prefix = 'aiida' + qplda = .false. + vkb = .false. + vxcdiag = .false. +/