Skip to content

Commit d3e9333

Browse files
agoscinskisphuber
authored andcommitted
Devops: Determine command directory dynamically with which
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.
1 parent 309352f commit d3e9333

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

tests/cmdline/commands/test_code.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def test_code_test(run_cli_command):
533533

534534

535535
@pytest.fixture
536-
def command_options(request, aiida_localhost, tmp_path):
536+
def command_options(request, aiida_localhost, tmp_path, bash_path):
537537
"""Return tuple of list of options and entry point."""
538538
options = [request.param, '-n', '--label', str(uuid.uuid4())]
539539

@@ -553,7 +553,7 @@ def command_options(request, aiida_localhost, tmp_path):
553553
'--computer',
554554
str(aiida_localhost.pk),
555555
'--filepath-executable',
556-
'/usr/bin/bash',
556+
str(bash_path.absolute()),
557557
'--engine-command',
558558
engine_command,
559559
'--image-name',

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import dataclasses
1919
import os
2020
import pathlib
21+
import subprocess
2122
import types
2223
import typing as t
2324
import warnings

tests/orm/data/code/test_installed.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,29 @@
1717
from aiida.orm.nodes.data.code.installed import InstalledCode
1818

1919

20-
def test_constructor_raises(aiida_localhost):
20+
def test_constructor_raises(aiida_localhost, bash_path):
2121
"""Test the constructor when it is supposed to raise."""
2222
with pytest.raises(TypeError, match=r'missing .* required positional arguments'):
2323
InstalledCode()
2424

2525
with pytest.raises(TypeError, match=r'Got object of type .*'):
26-
InstalledCode(computer=aiida_localhost, filepath_executable=pathlib.Path('/usr/bin/bash'))
26+
InstalledCode(computer=aiida_localhost, filepath_executable=bash_path)
2727

2828
with pytest.raises(TypeError, match=r'Got object of type .*'):
2929
InstalledCode(computer='computer', filepath_executable='/usr/bin/bash')
3030

3131

32-
def test_constructor(aiida_localhost):
32+
def test_constructor(aiida_localhost, bash_path):
3333
"""Test the constructor."""
34-
filepath_executable = '/usr/bin/bash'
34+
filepath_executable = str(bash_path.absolute())
3535
code = InstalledCode(computer=aiida_localhost, filepath_executable=filepath_executable)
3636
assert code.computer.pk == aiida_localhost.pk
3737
assert code.filepath_executable == pathlib.PurePath(filepath_executable)
3838

3939

40-
def test_validate(aiida_localhost):
40+
def test_validate(aiida_localhost, bash_path):
4141
"""Test the validator is called before storing."""
42-
filepath_executable = '/usr/bin/bash'
42+
filepath_executable = str(bash_path.absolute())
4343
code = InstalledCode(computer=aiida_localhost, filepath_executable=filepath_executable)
4444

4545
code.computer = aiida_localhost
@@ -53,18 +53,18 @@ def test_validate(aiida_localhost):
5353
assert code.is_stored
5454

5555

56-
def test_can_run_on_computer(aiida_localhost):
56+
def test_can_run_on_computer(aiida_localhost, bash_path):
5757
"""Test the :meth:`aiida.orm.nodes.data.code.installed.InstalledCode.can_run_on_computer` method."""
58-
code = InstalledCode(computer=aiida_localhost, filepath_executable='/usr/bin/bash')
58+
code = InstalledCode(computer=aiida_localhost, filepath_executable=str(bash_path.absolute()))
5959
computer = Computer()
6060

6161
assert code.can_run_on_computer(aiida_localhost)
6262
assert not code.can_run_on_computer(computer)
6363

6464

65-
def test_filepath_executable(aiida_localhost):
65+
def test_filepath_executable(aiida_localhost, bash_path, cat_path):
6666
"""Test the :meth:`aiida.orm.nodes.data.code.installed.InstalledCode.filepath_executable` property."""
67-
filepath_executable = '/usr/bin/bash'
67+
filepath_executable = str(bash_path.absolute())
6868
code = InstalledCode(computer=aiida_localhost, filepath_executable=filepath_executable)
6969
assert code.filepath_executable == pathlib.PurePath(filepath_executable)
7070

@@ -74,7 +74,7 @@ def test_filepath_executable(aiida_localhost):
7474
assert code.filepath_executable == pathlib.PurePath(filepath_executable)
7575

7676
# Change through the property
77-
filepath_executable = '/usr/bin/cat'
77+
filepath_executable = str(cat_path.absolute())
7878
code.filepath_executable = filepath_executable
7979
assert code.filepath_executable == pathlib.PurePath(filepath_executable)
8080

@@ -101,7 +101,7 @@ def computer(request, aiida_computer_local, aiida_computer_ssh):
101101

102102
@pytest.mark.usefixtures('aiida_profile_clean')
103103
@pytest.mark.parametrize('computer', ('core.local', 'core.ssh'), indirect=True)
104-
def test_validate_filepath_executable(ssh_key, computer):
104+
def test_validate_filepath_executable(ssh_key, computer, bash_path):
105105
"""Test the :meth:`aiida.orm.nodes.data.code.installed.InstalledCode.validate_filepath_executable` method."""
106106
filepath_executable = '/usr/bin/not-existing'
107107
code = InstalledCode(computer=computer, filepath_executable=filepath_executable)
@@ -117,19 +117,19 @@ def test_validate_filepath_executable(ssh_key, computer):
117117
with pytest.raises(ValidationError, match=r'The provided remote absolute path .* does not exist on the computer\.'):
118118
code.validate_filepath_executable()
119119

120-
code.filepath_executable = '/usr/bin/bash'
120+
code.filepath_executable = str(bash_path.absolute())
121121
code.validate_filepath_executable()
122122

123123

124-
def test_full_label(aiida_localhost):
124+
def test_full_label(aiida_localhost, bash_path):
125125
"""Test the :meth:`aiida.orm.nodes.data.code.installed.InstalledCode.full_label` property."""
126126
label = 'some-label'
127-
code = InstalledCode(label=label, computer=aiida_localhost, filepath_executable='/usr/bin/bash')
127+
code = InstalledCode(label=label, computer=aiida_localhost, filepath_executable=str(bash_path.absolute()))
128128
assert code.full_label == f'{label}@{aiida_localhost.label}'
129129

130130

131-
def test_get_execname(aiida_localhost):
131+
def test_get_execname(aiida_localhost, bash_path):
132132
"""Test the deprecated :meth:`aiida.orm.nodes.data.code.installed.InstalledCode.get_execname` method."""
133-
code = InstalledCode(label='some-label', computer=aiida_localhost, filepath_executable='/usr/bin/bash')
133+
code = InstalledCode(label='some-label', computer=aiida_localhost, filepath_executable=str(bash_path.absolute()))
134134
with pytest.warns(AiidaDeprecationWarning):
135-
assert code.get_execname() == '/usr/bin/bash'
135+
assert code.get_execname() == str(bash_path.absolute())

tests/orm/data/code/test_portable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
from aiida.orm.nodes.data.code.portable import PortableCode
1818

1919

20-
def test_constructor_raises(tmp_path):
20+
def test_constructor_raises(tmp_path, bash_path):
2121
"""Test the constructor when it is supposed to raise."""
2222
with pytest.raises(TypeError, match=r'missing .* required positional argument'):
2323
PortableCode()
2424

2525
with pytest.raises(TypeError, match=r'Got object of type .*'):
26-
PortableCode(filepath_executable=pathlib.Path('/usr/bin/bash'), filepath_files=tmp_path)
26+
PortableCode(filepath_executable=bash_path, filepath_files=tmp_path)
2727

2828
with pytest.raises(TypeError, match=r'Got object of type .*'):
2929
PortableCode(filepath_executable='bash', filepath_files='string')

0 commit comments

Comments
 (0)