Skip to content

Commit 726d242

Browse files
authored
Merge pull request #537 from djarecka/mnt/subm_check
changed to sge/slurm checks, moving to utils
2 parents 7e8232c + d5a7c95 commit 726d242

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

pydra/engine/tests/test_submitter.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,18 @@
77
import pytest
88

99
from .utils import (
10+
need_sge,
11+
need_slurm,
1012
gen_basic_wf,
1113
gen_basic_wf_with_threadcount,
1214
gen_basic_wf_with_threadcount_concurrent,
1315
)
1416
from ..core import Workflow
15-
from ..task import ShellCommandTask
1617
from ..submitter import Submitter
1718
from ... import mark
1819
from pathlib import Path
19-
import uuid
2020
from datetime import datetime
2121

22-
slurm_available = bool(shutil.which("sbatch"))
23-
sge_available = bool(shutil.which("qsub"))
24-
2522

2623
@mark.task
2724
def sleep_add_one(x):
@@ -182,7 +179,7 @@ def test_serial_wf():
182179
assert res.output.out == 9
183180

184181

185-
@pytest.mark.skipif(not slurm_available, reason="slurm not installed")
182+
@need_slurm
186183
def test_slurm_wf(tmpdir):
187184
wf = gen_basic_wf()
188185
wf.cache_dir = tmpdir
@@ -198,7 +195,7 @@ def test_slurm_wf(tmpdir):
198195
assert len([sd for sd in script_dir.listdir() if sd.isdir()]) == 2
199196

200197

201-
@pytest.mark.skipif(not slurm_available, reason="slurm not installed")
198+
@need_slurm
202199
def test_slurm_wf_cf(tmpdir):
203200
# submit entire workflow as single job executing with cf worker
204201
wf = gen_basic_wf()
@@ -217,7 +214,7 @@ def test_slurm_wf_cf(tmpdir):
217214
assert sdirs[0].basename == wf.uid
218215

219216

220-
@pytest.mark.skipif(not slurm_available, reason="slurm not installed")
217+
@need_slurm
221218
def test_slurm_wf_state(tmpdir):
222219
wf = gen_basic_wf()
223220
wf.split("x")
@@ -234,7 +231,7 @@ def test_slurm_wf_state(tmpdir):
234231
assert len(sdirs) == 2 * len(wf.inputs.x)
235232

236233

237-
@pytest.mark.skipif(not slurm_available, reason="slurm not installed")
234+
@need_slurm
238235
@pytest.mark.flaky(reruns=3)
239236
def test_slurm_max_jobs(tmpdir):
240237
wf = Workflow("new_wf", input_spec=["x", "y"], cache_dir=tmpdir)
@@ -274,7 +271,7 @@ def test_slurm_max_jobs(tmpdir):
274271
assert (prev - et).seconds >= 2
275272

276273

277-
@pytest.mark.skipif(not slurm_available, reason="slurm not installed")
274+
@need_slurm
278275
def test_slurm_args_1(tmpdir):
279276
"""testing sbatch_args provided to the submitter"""
280277
task = sleep_add_one(x=1)
@@ -289,7 +286,7 @@ def test_slurm_args_1(tmpdir):
289286
assert script_dir.exists()
290287

291288

292-
@pytest.mark.skipif(not slurm_available, reason="slurm not installed")
289+
@need_slurm
293290
def test_slurm_args_2(tmpdir):
294291
"""testing sbatch_args provided to the submitter
295292
exception should be raised for invalid options
@@ -339,7 +336,7 @@ def cancel(job_name_part):
339336

340337

341338
@pytest.mark.flaky(reruns=1)
342-
@pytest.mark.skipif(not slurm_available, reason="slurm not installed")
339+
@need_slurm
343340
def test_slurm_cancel_rerun_1(tmpdir):
344341
"""testing that tasks run with slurm is re-queue
345342
Running wf with 2 tasks, one sleeps and the other trying to get
@@ -372,7 +369,7 @@ def test_slurm_cancel_rerun_1(tmpdir):
372369

373370

374371
@pytest.mark.flaky(reruns=1)
375-
@pytest.mark.skipif(not slurm_available, reason="slurm not installed")
372+
@need_slurm
376373
def test_slurm_cancel_rerun_2(tmpdir):
377374
"""testing that tasks run with slurm that has --no-requeue
378375
Running wf with 2 tasks, one sleeps and the other gets
@@ -392,7 +389,7 @@ def test_slurm_cancel_rerun_2(tmpdir):
392389
sub(wf)
393390

394391

395-
@pytest.mark.skipif(not sge_available, reason="sge not installed")
392+
@need_sge
396393
def test_sge_wf(tmpdir):
397394
"""testing that a basic workflow can be run with the SGEWorker"""
398395
wf = gen_basic_wf()
@@ -412,7 +409,7 @@ def test_sge_wf(tmpdir):
412409
assert len([sd for sd in script_dir.listdir() if sd.isdir()]) == 2
413410

414411

415-
@pytest.mark.skipif(not sge_available, reason="sge not installed")
412+
@need_sge
416413
def test_sge_wf_cf(tmpdir):
417414
"""testing the SGEWorker can submit SGE tasks while the workflow
418415
uses the concurrent futures plugin"""
@@ -433,7 +430,7 @@ def test_sge_wf_cf(tmpdir):
433430
assert Path(sdirs[0]).name == wf.uid
434431

435432

436-
@pytest.mark.skipif(not sge_available, reason="sge not installed")
433+
@need_sge
437434
def test_sge_wf_state(tmpdir):
438435
"""testing the SGEWorker can be used with a workflow with state"""
439436
wf = gen_basic_wf()
@@ -466,7 +463,7 @@ def qacct_output_to_dict(qacct_output):
466463
return stdout_dict
467464

468465

469-
@pytest.mark.skipif(not sge_available, reason="sge not installed")
466+
@need_sge
470467
def test_sge_set_threadcount(tmpdir):
471468
"""testing the number of threads for an SGEWorker task can be set
472469
using the input_spec variable sgeThreads"""
@@ -496,7 +493,7 @@ def test_sge_set_threadcount(tmpdir):
496493
assert int(out_job1_dict["slots"][0]) == 1
497494

498495

499-
@pytest.mark.skipif(not sge_available, reason="sge not installed")
496+
@need_sge
500497
def test_sge_limit_maxthreads(tmpdir):
501498
"""testing the ability to limit the number of threads used by the SGE
502499
at one time with the max_threads argument to SGEWorker"""
@@ -540,7 +537,7 @@ def test_sge_limit_maxthreads(tmpdir):
540537
assert job_1_endtime < job_2_starttime
541538

542539

543-
@pytest.mark.skipif(not sge_available, reason="sge not installed")
540+
@need_sge
544541
def test_sge_no_limit_maxthreads(tmpdir):
545542
"""testing unlimited threads can be used at once by SGE
546543
when max_threads is not set"""

pydra/engine/tests/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
sys.platform.startswith("win"),
2121
reason="docker command not adjusted for windows docker",
2222
)
23+
need_slurm = pytest.mark.skipif(
24+
not (bool(shutil.which("sbatch")) and bool(shutil.which("sacct"))),
25+
reason="slurm not available",
26+
)
27+
need_sge = pytest.mark.skipif(
28+
not (bool(shutil.which("qsub")) and bool(shutil.which("qacct"))),
29+
reason="sge not available",
30+
)
2331

2432

2533
def result_no_submitter(shell_task, plugin=None):

0 commit comments

Comments
 (0)