Add spawner config tests
This commit is contained in:
parent
2333ccd168
commit
f1f6526daa
2 changed files with 44 additions and 2 deletions
|
@ -1,7 +1,7 @@
|
|||
"""GLiCID spawner module."""
|
||||
|
||||
from batchspawner import SlurmSpawner
|
||||
from traitlets import Unicode
|
||||
from traitlets import Unicode, default
|
||||
|
||||
from .form import options_form, options_from_form
|
||||
|
||||
|
@ -9,11 +9,15 @@ from .form import options_form, options_from_form
|
|||
class GlicidSpawner(SlurmSpawner):
|
||||
"""Glicid SLURM Spawner."""
|
||||
|
||||
batchspawner_singleuser_cmd = Unicode(
|
||||
glicid_singleuser_cmd = Unicode(
|
||||
'glicid-spawner-singleuser',
|
||||
help='Glicid spawner singleuser command.',
|
||||
).tag(config=True)
|
||||
|
||||
@default('batchspawner_singleuser_cmd')
|
||||
def _batchspawner_singleuser_cmd_default(self):
|
||||
return self.glicid_singleuser_cmd
|
||||
|
||||
def options_form(self) -> str:
|
||||
"""JupyterHub rendered form template."""
|
||||
return options_form(self.user.name)
|
||||
|
|
38
tests/test_spawner.py
Normal file
38
tests/test_spawner.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
"""Test GLiCID spawner module."""
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
import glicid_spawner.spawner
|
||||
from batchspawner import SlurmSpawner
|
||||
from glicid_spawner import GlicidSpawner
|
||||
|
||||
User = namedtuple('User', 'name')
|
||||
|
||||
|
||||
def test_spawner_config():
|
||||
"""Test spawner configuration."""
|
||||
spawner = GlicidSpawner()
|
||||
|
||||
assert isinstance(spawner, GlicidSpawner)
|
||||
assert isinstance(spawner, SlurmSpawner)
|
||||
|
||||
assert spawner.glicid_singleuser_cmd == 'glicid-spawner-singleuser'
|
||||
assert spawner.batchspawner_singleuser_cmd == 'glicid-spawner-singleuser'
|
||||
|
||||
|
||||
def test_spawner_options_form(monkeypatch):
|
||||
"""Test spawner options form."""
|
||||
monkeypatch.setattr(
|
||||
glicid_spawner.spawner, 'options_form', lambda username: f"options_form('{username}')"
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
glicid_spawner.spawner,
|
||||
'options_from_form',
|
||||
lambda formdata: f'options_from_form({formdata})',
|
||||
)
|
||||
|
||||
spawner = GlicidSpawner(user=User('john-doe'))
|
||||
|
||||
assert spawner.user.name == 'john-doe'
|
||||
assert spawner.options_form() == "options_form('john-doe')"
|
||||
assert spawner.options_from_form({'foo': 123}) == "options_from_form({'foo': 123})"
|
Loading…
Add table
Reference in a new issue