diff --git a/tests/cmdline/commands/test_code.py b/tests/cmdline/commands/test_code.py index 85f1534ece..d2f09c0f24 100644 --- a/tests/cmdline/commands/test_code.py +++ b/tests/cmdline/commands/test_code.py @@ -533,7 +533,7 @@ def test_code_test(run_cli_command): @pytest.fixture -def command_options(request, aiida_localhost, tmp_path): +def command_options(request, aiida_localhost, tmp_path, bash_path): """Return tuple of list of options and entry point.""" options = [request.param, '-n', '--label', str(uuid.uuid4())] @@ -553,7 +553,7 @@ def command_options(request, aiida_localhost, tmp_path): '--computer', str(aiida_localhost.pk), '--filepath-executable', - '/usr/bin/bash', + str(bash_path.absolute()), '--engine-command', engine_command, '--image-name', diff --git a/tests/conftest.py b/tests/conftest.py index d4ca5ee1db..1dcb644b21 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -18,6 +18,7 @@ import dataclasses import os import pathlib +import subprocess import types import typing as t import warnings diff --git a/tests/orm/data/code/test_installed.py b/tests/orm/data/code/test_installed.py index 5e1fda4273..928d718080 100644 --- a/tests/orm/data/code/test_installed.py +++ b/tests/orm/data/code/test_installed.py @@ -17,29 +17,29 @@ from aiida.orm.nodes.data.code.installed import InstalledCode -def test_constructor_raises(aiida_localhost): +def test_constructor_raises(aiida_localhost, bash_path): """Test the constructor when it is supposed to raise.""" with pytest.raises(TypeError, match=r'missing .* required positional arguments'): InstalledCode() with pytest.raises(TypeError, match=r'Got object of type .*'): - InstalledCode(computer=aiida_localhost, filepath_executable=pathlib.Path('/usr/bin/bash')) + InstalledCode(computer=aiida_localhost, filepath_executable=bash_path) with pytest.raises(TypeError, match=r'Got object of type .*'): InstalledCode(computer='computer', filepath_executable='/usr/bin/bash') -def test_constructor(aiida_localhost): +def test_constructor(aiida_localhost, bash_path): """Test the constructor.""" - filepath_executable = '/usr/bin/bash' + filepath_executable = str(bash_path.absolute()) code = InstalledCode(computer=aiida_localhost, filepath_executable=filepath_executable) assert code.computer.pk == aiida_localhost.pk assert code.filepath_executable == pathlib.PurePath(filepath_executable) -def test_validate(aiida_localhost): +def test_validate(aiida_localhost, bash_path): """Test the validator is called before storing.""" - filepath_executable = '/usr/bin/bash' + filepath_executable = str(bash_path.absolute()) code = InstalledCode(computer=aiida_localhost, filepath_executable=filepath_executable) code.computer = aiida_localhost @@ -53,18 +53,18 @@ def test_validate(aiida_localhost): assert code.is_stored -def test_can_run_on_computer(aiida_localhost): +def test_can_run_on_computer(aiida_localhost, bash_path): """Test the :meth:`aiida.orm.nodes.data.code.installed.InstalledCode.can_run_on_computer` method.""" - code = InstalledCode(computer=aiida_localhost, filepath_executable='/usr/bin/bash') + code = InstalledCode(computer=aiida_localhost, filepath_executable=str(bash_path.absolute())) computer = Computer() assert code.can_run_on_computer(aiida_localhost) assert not code.can_run_on_computer(computer) -def test_filepath_executable(aiida_localhost): +def test_filepath_executable(aiida_localhost, bash_path, cat_path): """Test the :meth:`aiida.orm.nodes.data.code.installed.InstalledCode.filepath_executable` property.""" - filepath_executable = '/usr/bin/bash' + filepath_executable = str(bash_path.absolute()) code = InstalledCode(computer=aiida_localhost, filepath_executable=filepath_executable) assert code.filepath_executable == pathlib.PurePath(filepath_executable) @@ -74,7 +74,7 @@ def test_filepath_executable(aiida_localhost): assert code.filepath_executable == pathlib.PurePath(filepath_executable) # Change through the property - filepath_executable = '/usr/bin/cat' + filepath_executable = str(cat_path.absolute()) code.filepath_executable = filepath_executable assert code.filepath_executable == pathlib.PurePath(filepath_executable) @@ -101,7 +101,7 @@ def computer(request, aiida_computer_local, aiida_computer_ssh): @pytest.mark.usefixtures('aiida_profile_clean') @pytest.mark.parametrize('computer', ('core.local', 'core.ssh'), indirect=True) -def test_validate_filepath_executable(ssh_key, computer): +def test_validate_filepath_executable(ssh_key, computer, bash_path): """Test the :meth:`aiida.orm.nodes.data.code.installed.InstalledCode.validate_filepath_executable` method.""" filepath_executable = '/usr/bin/not-existing' code = InstalledCode(computer=computer, filepath_executable=filepath_executable) @@ -117,19 +117,19 @@ def test_validate_filepath_executable(ssh_key, computer): with pytest.raises(ValidationError, match=r'The provided remote absolute path .* does not exist on the computer\.'): code.validate_filepath_executable() - code.filepath_executable = '/usr/bin/bash' + code.filepath_executable = str(bash_path.absolute()) code.validate_filepath_executable() -def test_full_label(aiida_localhost): +def test_full_label(aiida_localhost, bash_path): """Test the :meth:`aiida.orm.nodes.data.code.installed.InstalledCode.full_label` property.""" label = 'some-label' - code = InstalledCode(label=label, computer=aiida_localhost, filepath_executable='/usr/bin/bash') + code = InstalledCode(label=label, computer=aiida_localhost, filepath_executable=str(bash_path.absolute())) assert code.full_label == f'{label}@{aiida_localhost.label}' -def test_get_execname(aiida_localhost): +def test_get_execname(aiida_localhost, bash_path): """Test the deprecated :meth:`aiida.orm.nodes.data.code.installed.InstalledCode.get_execname` method.""" - code = InstalledCode(label='some-label', computer=aiida_localhost, filepath_executable='/usr/bin/bash') + code = InstalledCode(label='some-label', computer=aiida_localhost, filepath_executable=str(bash_path.absolute())) with pytest.warns(AiidaDeprecationWarning): - assert code.get_execname() == '/usr/bin/bash' + assert code.get_execname() == str(bash_path.absolute()) diff --git a/tests/orm/data/code/test_portable.py b/tests/orm/data/code/test_portable.py index a0b3414264..4bffa04515 100644 --- a/tests/orm/data/code/test_portable.py +++ b/tests/orm/data/code/test_portable.py @@ -17,13 +17,13 @@ from aiida.orm.nodes.data.code.portable import PortableCode -def test_constructor_raises(tmp_path): +def test_constructor_raises(tmp_path, bash_path): """Test the constructor when it is supposed to raise.""" with pytest.raises(TypeError, match=r'missing .* required positional argument'): PortableCode() with pytest.raises(TypeError, match=r'Got object of type .*'): - PortableCode(filepath_executable=pathlib.Path('/usr/bin/bash'), filepath_files=tmp_path) + PortableCode(filepath_executable=bash_path, filepath_files=tmp_path) with pytest.raises(TypeError, match=r'Got object of type .*'): PortableCode(filepath_executable='bash', filepath_files='string')