Files
the-littlest-jupyterhub/tests/test_conda.py
yuvipanda e97b81fe7a Require miniconda to be installed for conda. to work
We can no longer assume that sys.executable has conda
installed. Instead, we require that prefix has conda installed.
This requires miniconda to be installed into prefix.
2018-07-20 11:30:11 -07:00

66 lines
1.7 KiB
Python

"""
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
"""
miniconda_version = '4.5.4'
miniconda_installer_md5 = "a946ea1d0c4a642ddf0c3a26a18bb16d"
with tempfile.TemporaryDirectory() as tmpdir:
with conda.download_miniconda_installer(miniconda_version, miniconda_installer_md5) as installer_path:
conda.install_miniconda(installer_path, tmpdir)
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'
])