| 1 |
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. |
| 2 |
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. |
| 3 |
# |
| 4 |
# This program is free software: you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation, either version 3 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
import pytest |
| 18 |
|
| 19 |
from cylc.flow.job_runner_handlers.slurm_packjob import JOB_RUNNER_HANDLER |
| 20 |
|
| 21 |
|
| 22 |
@pytest.mark.parametrize( |
| 23 |
'job_conf,lines', |
| 24 |
[ |
| 25 |
( # heterogeneous job, old-style (packjob) |
| 26 |
{ |
| 27 |
'directives': { |
| 28 |
'-p': 'middle', |
| 29 |
'packjob_0_--mem': '128gb', |
| 30 |
'packjob_1_--mem': '256gb', |
| 31 |
}, |
| 32 |
'execution_time_limit': 200, |
| 33 |
'job_file_path': 'cylc-run/chop/log/job/1/axe/01/job', |
| 34 |
'workflow_name': 'chop', |
| 35 |
'task_id': '1/axe', |
| 36 |
}, |
| 37 |
[ |
| 38 |
'#SBATCH --job-name=axe.1.chop', |
| 39 |
( |
| 40 |
'#SBATCH --output=' |
| 41 |
'cylc-run/chop/log/job/1/axe/01/job.out' |
| 42 |
), |
| 43 |
( |
| 44 |
'#SBATCH --error=' |
| 45 |
'cylc-run/chop/log/job/1/axe/01/job.err' |
| 46 |
), |
| 47 |
'#SBATCH --time=3:20', |
| 48 |
'#SBATCH -p=middle', |
| 49 |
'#SBATCH --mem=128gb', |
| 50 |
'#SBATCH packjob', |
| 51 |
'#SBATCH --mem=256gb', |
| 52 |
], |
| 53 |
), |
| 54 |
|
| 55 |
], |
| 56 |
) |
| 57 |
def test_format_directives(job_conf: dict, lines: list): |
| 58 |
assert JOB_RUNNER_HANDLER.format_directives(job_conf) == lines |
| 59 |
|
| 60 |
|
| 61 |
@pytest.mark.parametrize( |
| 62 |
'job_ids,cmd', |
| 63 |
[ |
| 64 |
[['1234567'], ['squeue', '-h', '-j', '1234567']], |
| 65 |
[ |
| 66 |
['1234567', '709394', '30624700'], |
| 67 |
['squeue', '-h', '-j', '1234567,709394,30624700'], |
| 68 |
], |
| 69 |
], |
| 70 |
) |
| 71 |
def test_get_poll_many_cmd(job_ids: list, cmd: list): |
| 72 |
assert JOB_RUNNER_HANDLER.get_poll_many_cmd(job_ids) == cmd |
| 73 |
|
| 74 |
|
| 75 |
@pytest.mark.parametrize( |
| 76 |
'out,job_ids', |
| 77 |
[ |
| 78 |
[ |
| 79 |
"""HEADING |
| 80 |
1234567 JOB PROPERTIES |
| 81 |
709394 JOB PROPERTIES |
| 82 |
30624700 JOB PROPERTIES |
| 83 |
""", ['1234567', '30624700', '709394'], |
| 84 |
], |
| 85 |
[ |
| 86 |
"""HEADING |
| 87 |
1234567+0 JOB PROPERTIES (HETERO) |
| 88 |
1234567+1 JOB PROPERTIES (HETERO) |
| 89 |
709394 JOB PROPERTIES |
| 90 |
30624700 JOB PROPERTIES |
| 91 |
""", ['1234567', '30624700', '709394'], |
| 92 |
], |
| 93 |
], |
| 94 |
) |
| 95 |
def test_filter_poll_many_output(job_ids: list, out: str): |
| 96 |
assert sorted(JOB_RUNNER_HANDLER.filter_poll_many_output(out)) == job_ids |