Skip to content

Commit

Permalink
Devops: Determine command directory dynamically with which
Browse files Browse the repository at this point in the history
Before the path for `bash` and `cat` path was hardcoded. This has been changed
to run a subprocess running `which bash` and `which cat` to determine the path.
This is required to for example run the tests on macOS.
  • Loading branch information
agoscinski authored and sphuber committed Oct 24, 2024
1 parent 309352f commit d3e9333
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
4 changes: 2 additions & 2 deletions tests/cmdline/commands/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())]

Expand All @@ -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',
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import dataclasses
import os
import pathlib
import subprocess
import types
import typing as t
import warnings
Expand Down
36 changes: 18 additions & 18 deletions tests/orm/data/code/test_installed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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())
4 changes: 2 additions & 2 deletions tests/orm/data/code/test_portable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit d3e9333

Please sign in to comment.