Rename pyenv to micromamba submodule and add tests

This commit is contained in:
Benoît Seignovert 2024-02-08 17:50:36 +01:00
parent bf8bce2fb1
commit 33abe472d4
Signed by: Benoît Seignovert
GPG key ID: F5D8895227D18A0B
8 changed files with 119 additions and 80 deletions

36
tests/test_micromamba.py Normal file
View file

@ -0,0 +1,36 @@
"""Test python environment module."""
from pathlib import Path
from glicid_spawner import micromamba
MICROMAMBA_ROOT = Path(__file__).parent / 'data' / 'micromamba'
def test_micromamba_envs_getter(monkeypatch):
"""Test micromamba envs getter."""
monkeypatch.setattr(micromamba, 'MICROMAMBA_ROOT', MICROMAMBA_ROOT)
monkeypatch.setattr(micromamba, 'GLOBAL_USER', 'global')
monkeypatch.setattr(micromamba, 'GLOBAL_EXCLUDED', 'qux')
# User with micromamba envs
envs = micromamba.get_envs('john-doe')
assert len(envs) == 3
assert [env.scope for env in envs] == ['USER', 'USER', 'GLOBAL']
assert [env.name for env in envs] == ['bar', 'foo', 'baz']
assert [env.path for env in envs] == [
str(MICROMAMBA_ROOT / 'john-doe' / 'envs' / 'bar'),
str(MICROMAMBA_ROOT / 'john-doe' / 'envs' / 'foo'),
str(MICROMAMBA_ROOT / 'global' / 'envs' / 'baz'),
]
# User without micromamba envs, only global envs listed
envs = micromamba.get_envs('jane-smith')
assert len(envs) == 1
assert [env.scope for env in envs] == ['GLOBAL']
assert [env.name for env in envs] == ['baz']
assert [env.path for env in envs] == [
str(MICROMAMBA_ROOT / 'global' / 'envs' / 'baz'),
]