Add flask app with auto-reload to render the form template
This commit is contained in:
parent
433862d0ad
commit
2333ccd168
12 changed files with 662 additions and 61 deletions
90
tests/test_form.py
Normal file
90
tests/test_form.py
Normal file
|
@ -0,0 +1,90 @@
|
|||
"""Test form templates module."""
|
||||
|
||||
import re
|
||||
|
||||
from glicid_spawner import form, micromamba
|
||||
from glicid_spawner.form import options_form, options_from_form
|
||||
|
||||
|
||||
def test_options_form(monkeypatch):
|
||||
"""Test options form render."""
|
||||
monkeypatch.setattr(
|
||||
form,
|
||||
'get_envs',
|
||||
lambda username: [
|
||||
micromamba.MicromambaEnv('USER', 'foo', f'/{username}/envs/foo'),
|
||||
micromamba.MicromambaEnv('USER', 'bar', f'/{username}/envs/bar'),
|
||||
micromamba.MicromambaEnv('GLOBAL', 'baz', '/global/envs/baz'),
|
||||
],
|
||||
)
|
||||
|
||||
html = re.sub(r'\n\s+', ' ', options_form('john-doe')) # trim line breaks
|
||||
|
||||
# Username
|
||||
assert '<div class="form-control-static">john-doe</div>' in html
|
||||
|
||||
# Python environments
|
||||
assert '<option value="/john-doe/envs/foo">foo (USER)</option>' in html
|
||||
assert '<option value="/john-doe/envs/bar">bar (USER)</option>' in html
|
||||
assert '<option value="/global/envs/baz">baz (GLOBAL)</option>' in html
|
||||
|
||||
# CPU
|
||||
assert (
|
||||
'<input type="radio" name="cpu" id="cpu_0" value="0" data-max-duration="24" checked>'
|
||||
in html
|
||||
)
|
||||
assert '<label for="cpu_0" class="btn btn-default btn-block"> 1 </label>' in html
|
||||
assert '<input type="radio" name="cpu" id="cpu_5" value="5" data-max-duration="1">' in html
|
||||
assert '<label for="cpu_5" class="btn btn-default btn-block"> 24 </label>' in html
|
||||
|
||||
# Memory
|
||||
assert (
|
||||
'<input type="radio" name="ram" id="ram_0" value="0" data-max-duration="24" checked>'
|
||||
in html
|
||||
)
|
||||
assert '<label for="ram_0" class="btn btn-default btn-block"> 4 GB </label>' in html
|
||||
assert '<input type="radio" name="ram" id="ram_5" value="5" data-max-duration="1">' in html
|
||||
assert '<label for="ram_5" class="btn btn-default btn-block"> 96 GB </label>' in html
|
||||
|
||||
# GPU
|
||||
assert (
|
||||
'<input type="radio" name="gpu" id="gpu_0" value="0" data-max-duration="24" checked>'
|
||||
in html
|
||||
)
|
||||
assert '<label for="gpu_0" class="btn btn-default btn-block"> No </label>' in html
|
||||
assert '<input type="radio" name="gpu" id="gpu_1" value="1" data-max-duration="1">' in html
|
||||
assert '<label for="gpu_1" class="btn btn-default btn-block"> A100 </label>' in html
|
||||
|
||||
|
||||
def test_options_from_form():
|
||||
"""Test options from form parser."""
|
||||
# No GPU
|
||||
formdata = {
|
||||
'python-env': ['/john-doe/envs/bar'],
|
||||
'cpu': ['1'],
|
||||
'ram': ['2'],
|
||||
'gpu': ['0'],
|
||||
}
|
||||
|
||||
assert options_from_form(formdata) == {
|
||||
'pyenv': '/john-doe/envs/bar',
|
||||
'nprocs': 2,
|
||||
'memory': '16GB',
|
||||
'runtime': '06:00:00',
|
||||
}
|
||||
|
||||
# No GPU
|
||||
formdata = {
|
||||
'python-env': ['/global/envs/baz'],
|
||||
'cpu': ['0'],
|
||||
'ram': ['0'],
|
||||
'gpu': ['1'],
|
||||
}
|
||||
|
||||
assert options_from_form(formdata) == {
|
||||
'pyenv': '/global/envs/baz',
|
||||
'nprocs': 1,
|
||||
'memory': '4GB',
|
||||
'runtime': '01:00:00',
|
||||
'gres': 'gpu:a100',
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue