Add resources tests

This commit is contained in:
Benoît Seignovert 2024-02-08 16:37:20 +01:00
parent f00b406962
commit bf8bce2fb1
Signed by: Benoît Seignovert
GPG key ID: F5D8895227D18A0B
4 changed files with 39 additions and 12 deletions

View file

@ -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),
]

View file

@ -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 {

View file

@ -37,7 +37,7 @@
<input type="radio" name="ram" id="ram_{{loop.index0}}" value="{{loop.index0}}"
data-max-duration="{{ram.max_duration}}" {%- if loop.first -%}checked{%- endif -%}>
<label for="ram_{{loop.index0}}" class="btn btn-default btn-block">
{{ ram.description }} GB
{{ ram.description }}
</label>
</div>
{% endfor -%}
@ -51,7 +51,7 @@
<input type="radio" name="gpu" id="gpu_{{loop.index0}}" value="{{loop.index0}}"
data-max-duration="{{gpu.max_duration}}" {%- if loop.first -%}checked{%- endif -%}>
<label for="gpu_{{loop.index0}}" class="btn btn-default btn-block">
{{ gpu.description | capitalize }}
{{ gpu.description }}
</label>
</div>
{% endfor -%}

24
tests/test_resources.py Normal file
View file

@ -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