"""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 '
john-doe
' in html
# Python environments
assert '' in html
assert '' in html
assert '' in html
# CPU
assert (
''
in html
)
assert '' in html
assert '' in html
assert '' in html
# Memory
assert (
''
in html
)
assert '' in html
assert '' in html
assert '' in html
# GPU
assert (
''
in html
)
assert '' in html
assert '' in html
assert '' 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',
}