Skip to content

Commit 8e475e5

Browse files
committed
Merge branch 'main' into fix-env-type
2 parents cbdeea9 + c07a62d commit 8e475e5

File tree

6 files changed

+48
-25
lines changed

6 files changed

+48
-25
lines changed

docs/user_guide.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ following example shows:
311311
.. literalinclude:: ../tests/user_guide/test_prelaunch.py
312312
:language: python
313313
:dedent: 4
314-
:lines: 12-18
314+
:lines: 13-19
315315

316316
where the contents of ``pre_launch.sh`` is
317317

src/psij/executors/batch/slurm/slurm.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ _PSIJ_NC=`scontrol show hostnames | wc -l`
9494
form, we need to duplicate each node line by PPN, which we need to calculate}}
9595
if [ "$_PSIJ_PPN" == "" ]; then
9696
if [ "$_PSIJ_NC" != "" ] && [ "$_PSIJ_PC" != "" ]; then
97-
$_PSIJ_PPN=$((_PSIJ_PC/_PSIJ_NC))
97+
_PSIJ_PPN=$((_PSIJ_PC/_PSIJ_NC))
9898
fi
9999
fi
100100

tests/_test_tools.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import os
2+
import shutil
3+
import tempfile
4+
from contextlib import contextmanager
15
from datetime import timedelta
26
from pathlib import Path
3-
from typing import Optional
7+
from typing import Optional, Union, Iterator
48

59
from executor_test_params import ExecutorTestParams
610

@@ -53,3 +57,18 @@ def _get_executor_instance(ep: ExecutorTestParams, job: Optional[Job] = None) ->
5357
if ep.queue_name is not None:
5458
job.spec.attributes.queue_name = ep.queue_name
5559
return JobExecutor.get_instance(ep.executor, url=ep.url)
60+
61+
62+
@contextmanager
63+
def _deploy(path: Union[Path, str]) -> Iterator[Path]:
64+
# Copies `path` to a directory assumed to be on a shared FS (~/.psij/test) and
65+
# returns the resulting path
66+
if isinstance(path, str):
67+
path = Path(path)
68+
with tempfile.NamedTemporaryFile(dir=Path.home() / '.psij' / 'test', delete=False) as df:
69+
try:
70+
df.close()
71+
shutil.copyfile(path, df.name)
72+
yield Path(df.name)
73+
finally:
74+
os.unlink(df.name)

tests/test_nodefile.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66

7-
from _test_tools import assert_completed, _get_executor_instance
7+
from _test_tools import assert_completed, _get_executor_instance, _deploy
88
from executor_test_params import ExecutorTestParams
99
from psij import Job, JobSpec, ResourceSpecV1
1010

@@ -14,17 +14,20 @@
1414
def test_nodefile(execparams: ExecutorTestParams) -> None:
1515
if execparams.executor in NOT_TESTED:
1616
pytest.skip('This test does not work with %s' % execparams.executor)
17+
if execparams.launcher == 'single':
18+
pytest.skip('This test does not work with the single launcher')
1719

1820
my_path = os.path.dirname(os.path.realpath(__file__))
1921

2022
N_PROC = 4
2123
with TemporaryDirectory(dir=Path.home() / '.psij' / 'test') as td:
2224
outp = Path(td, 'stdout.txt')
23-
spec = JobSpec('/bin/bash', [os.path.join(my_path, 'test_nodefile.sh'), str(N_PROC)],
24-
stdout_path=outp)
25-
job = Job(spec)
26-
spec.resources = ResourceSpecV1(process_count=N_PROC)
27-
ex = _get_executor_instance(execparams, job)
28-
ex.submit(job)
29-
status = job.wait()
30-
assert_completed(job, status)
25+
with _deploy(os.path.join(my_path, 'test_nodefile.sh')) as excp:
26+
spec = JobSpec('/bin/bash', [str(excp), str(N_PROC)],
27+
stdout_path=outp)
28+
job = Job(spec)
29+
spec.resources = ResourceSpecV1(process_count=N_PROC)
30+
ex = _get_executor_instance(execparams, job)
31+
ex.submit(job)
32+
status = job.wait()
33+
assert_completed(job, status)

tests/user_guide/pre_launch.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
module() {
3+
xmodule() {
44
case "$1" in
55
load)
66
export MODULE_TEST_LOADED="1"
@@ -16,6 +16,6 @@ module() {
1616
esac
1717
}
1818

19-
export -f module
19+
export -f xmodule
2020

21-
module load test
21+
xmodule load test

tests/user_guide/test_prelaunch.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import os
22
from pathlib import Path
33

4-
from _test_tools import assert_completed
4+
from _test_tools import assert_completed, _deploy
55
from psij import Job, JobSpec, JobExecutor
66

77

88
def test_user_guide_pre_launch() -> None:
99
script_dir = os.path.dirname(os.path.realpath(__file__))
1010

11-
# START
12-
ex = JobExecutor.get_instance('local')
13-
spec = JobSpec('/bin/bash', ['-c', 'module is-loaded test'])
14-
spec.pre_launch = Path(script_dir) / 'pre_launch.sh'
11+
with _deploy(Path(script_dir) / 'pre_launch.sh') as pre_launch_sh_path:
12+
# START
13+
ex = JobExecutor.get_instance('local')
14+
spec = JobSpec('/bin/bash', ['-c', 'xmodule is-loaded test'])
15+
spec.pre_launch = pre_launch_sh_path
1516

16-
job = Job(spec)
17-
ex.submit(job)
18-
status = job.wait()
19-
# END
20-
assert_completed(job, status)
17+
job = Job(spec)
18+
ex.submit(job)
19+
status = job.wait()
20+
# END
21+
assert_completed(job, status)

0 commit comments

Comments
 (0)