From b72dbdbde19f077ec040f38d353aa750eb1d77af Mon Sep 17 00:00:00 2001 From: Matthew Evans <7916000+ml-evs@users.noreply.github.com> Date: Wed, 7 Aug 2024 18:19:20 +0200 Subject: [PATCH] Add simple test for QResources -> slurm submission script (#45) * Add simple test for QResources -> slurm submission script with as many options as possible * Add example case --- tests/conftest.py | 28 ++++++++++++++++++++++++++++ tests/io/test_slurm.py | 14 ++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index a267056..004a414 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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, + ) diff --git a/tests/io/test_slurm.py b/tests/io/test_slurm.py index 1b92dae..edc7cee 100644 --- a/tests/io/test_slurm.py +++ b/tests/io/test_slurm.py @@ -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" + )