Skip to content

Commit

Permalink
Add simple test for QResources -> slurm submission script (#45)
Browse files Browse the repository at this point in the history
* Add simple test for QResources -> slurm submission script with as many options as possible

* Add example case
  • Loading branch information
ml-evs authored Aug 7, 2024
1 parent 833f1f0 commit b72dbdb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,31 @@ def inkwargs_outref(cls, in_out_ref, inkey, outkey):
@pytest.fixture(scope="session")
def test_utils():
return TestUtils


@pytest.fixture(scope="session")
def maximalist_qresources():
"""A set of QResources options that try to make use of most features"""
from qtoolkit.core.data_objects import QResources

return QResources(
queue_name="test_queue",
job_name="test_job",
memory_per_thread=1000,
nodes=1,
processes=1,
processes_per_node=1,
threads_per_process=1,
gpus_per_job=1,
time_limit=100,
account="test_account",
qos="test_qos",
priority=1,
output_filepath="test_output_filepath",
error_filepath="test_error_filepath",
process_placement="no_constraints",
email_address="test_email_address@email.address",
rerunnable=True,
project="test_project",
njobs=1,
)
14 changes: 14 additions & 0 deletions tests/io/test_slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,17 @@ def test_check_convert_qresources(self, slurm_io):
UnsupportedResourcesError, match=r"Keys not supported: rerunnable"
):
slurm_io.check_convert_qresources(res)

def test_submission_script(self, slurm_io, maximalist_qresources):
# only `rerunnable` and `project` are unsupported by SlurmIO
maximalist_qresources.rerunnable = None
maximalist_qresources.project = None

script_qresources = slurm_io.get_submission_script(
commands=["ls -l"], options=maximalist_qresources
)
assert script_qresources.split(
"\n"
) == "#!/bin/bash\n\n#SBATCH --partition=test_queue\n#SBATCH --job-name=test_job\n#SBATCH --nodes=1\n#SBATCH --ntasks=1\n#SBATCH --ntasks-per-node=1\n#SBATCH --cpus-per-task=1\n#SBATCH --mem-per-cpu=1000\n#SBATCH --time=0-0:1:40\n#SBATCH --account=test_account\n#SBATCH --mail-user=test_email_address@email.address\n#SBATCH --mail-type=ALL\n#SBATCH --gres=gpu:1\n#SBATCH --output=test_output_filepath\n#SBATCH --error=test_error_filepath\n#SBATCH --qos=test_qos\n#SBATCH --priority=1\nls -l".split(
"\n"
)

0 comments on commit b72dbdb

Please sign in to comment.