Files
the-littlest-jupyterhub/tests/test_conda.py

70 lines
1.9 KiB
Python
Raw Normal View History

"""
Test conda commandline wrappers
"""
from tljh import conda
import os
import pytest
import subprocess
import tempfile
@pytest.fixture(scope='module')
def prefix():
"""
Provide a temporary directory with a conda environment
"""
2021-07-31 20:44:23 +01:00
mambaforge_version = '4.10.3-3'
installer_sha256 = "a012c24e1cc3bcbe74a1e5693e510830e7c2956e85877b08d1e28707a0bd8d75"
installer_url = "https://github.com/conda-forge/miniforge/releases/download/{v}/Mambaforge-{v}-Linux-x86_64.sh".format(v=mambaforge_version)
with tempfile.TemporaryDirectory() as tmpdir:
2021-07-31 20:44:23 +01:00
with conda.download_miniconda_installer(installer_url, installer_sha256) as installer_path:
conda.install_miniconda(installer_path, tmpdir)
2019-08-26 15:13:19 +03:00
conda.ensure_conda_packages(tmpdir, [
2021-07-31 20:44:23 +01:00
'conda==4.10.3'
2019-08-26 15:13:19 +03:00
])
yield tmpdir
def test_ensure_packages(prefix):
"""
Test installing packages in conda environment
"""
conda.ensure_conda_packages(prefix, ['numpy'])
# Throws an error if this fails
subprocess.check_call([
os.path.join(prefix, 'bin', 'python'),
'-c',
'import numpy'
])
def test_ensure_pip_packages(prefix):
"""
Test installing pip packages in conda environment
"""
conda.ensure_conda_packages(prefix, ['pip'])
conda.ensure_pip_packages(prefix, ['numpy'])
# Throws an error if this fails
subprocess.check_call([
os.path.join(prefix, 'bin', 'python'),
'-c',
'import numpy'
])
def test_ensure_pip_requirements(prefix):
"""
Test installing pip packages with requirements.txt in conda environment
"""
conda.ensure_conda_packages(prefix, ['pip'])
with tempfile.NamedTemporaryFile() as f:
# Sample small package to test
f.write('there'.encode())
f.flush()
conda.ensure_pip_requirements(prefix, f.name)
subprocess.check_call([
os.path.join(prefix, 'bin', 'python'),
'-c',
'import there'
])