From bf8bce2fb10937933fcc7f60569339ab9e86753a Mon Sep 17 00:00:00 2001 From: Benoit Seignovert Date: Thu, 8 Feb 2024 16:37:20 +0100 Subject: [PATCH] Add resources tests --- src/glicid_spawner/resources.py | 17 +++++++------ src/glicid_spawner/slurm.py | 6 ++++- src/glicid_spawner/templates/interactive.html | 4 ++-- tests/test_resources.py | 24 +++++++++++++++++++ 4 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 tests/test_resources.py diff --git a/src/glicid_spawner/resources.py b/src/glicid_spawner/resources.py index 6d833d4..e5be588 100644 --- a/src/glicid_spawner/resources.py +++ b/src/glicid_spawner/resources.py @@ -5,7 +5,7 @@ from dataclasses import dataclass @dataclass class Resource: - """Cluster generic resource.""" + """Generic cluster resource.""" description: str max_duration: int @@ -21,16 +21,15 @@ CPU = [ ] RAM = [ - Resource('4', 24), - Resource('8', 12), - Resource('16', 6), - Resource('32', 3), - Resource('48', 2), - Resource('96', 1), + Resource('4 GB', 24), + Resource('8 GB', 12), + Resource('16 GB', 6), + Resource('32 GB', 3), + Resource('48 GB', 2), + Resource('96 GB', 1), ] GPU = [ - Resource('no', 24), - Resource('A40', 2), + Resource('No', 24), Resource('A100', 1), ] diff --git a/src/glicid_spawner/slurm.py b/src/glicid_spawner/slurm.py index 49e8d70..3268fe4 100644 --- a/src/glicid_spawner/slurm.py +++ b/src/glicid_spawner/slurm.py @@ -74,7 +74,11 @@ def _sinfo_reader(result) -> list: def sinfo(with_states=('idle', 'mixed')) -> dict: - """SLURM SINFO resources available with a given state(s).""" + """SLURM SINFO resources available with a given state(s). + + Grouped by cluster and partition names. + + """ resources = _sinfo_reader(_sinfo_run()) return { diff --git a/src/glicid_spawner/templates/interactive.html b/src/glicid_spawner/templates/interactive.html index 05978c8..9d71ca3 100644 --- a/src/glicid_spawner/templates/interactive.html +++ b/src/glicid_spawner/templates/interactive.html @@ -37,7 +37,7 @@ {% endfor -%} @@ -51,7 +51,7 @@ {% endfor -%} diff --git a/tests/test_resources.py b/tests/test_resources.py new file mode 100644 index 0000000..f9c695e --- /dev/null +++ b/tests/test_resources.py @@ -0,0 +1,24 @@ +"""Test resources module.""" + +from glicid_spawner.resources import CPU, GPU, RAM + + +def test_glicid_default_resources(): + """Test GLiCID default resources.""" + assert len(CPU) == 6 + assert CPU[0].description == '1' + assert CPU[0].max_duration == 24 + assert CPU[-1].description == '24' + assert CPU[-1].max_duration == 1 + + assert len(RAM) == 6 + assert RAM[0].description == '4 GB' + assert RAM[0].max_duration == 24 + assert RAM[-1].description == '96 GB' + assert RAM[-1].max_duration == 1 + + assert len(GPU) == 2 + assert GPU[0].description == 'No' + assert GPU[0].max_duration == 24 + assert GPU[-1].description == 'A100' + assert GPU[-1].max_duration == 1