11"""This module contains tests for the base image, which are AiiDA and package management related tests."""
22
3+ import email
34import json
45
56import pytest
67from packaging .version import parse
78
89
10+ @pytest .fixture
11+ def venv (tmp_path , aiidalab_exec ):
12+ venv_path = tmp_path / ".venv"
13+ aiidalab_exec (f"python -m venv { venv_path } " )
14+ return venv_path
15+
16+
917@pytest .mark .parametrize ("pkg_manager" , ["pip" , "mamba" ])
1018def test_prevent_installation_of_aiida (
1119 aiidalab_exec , nb_user , aiida_version , pkg_manager
@@ -76,8 +84,6 @@ def test_path_local_pip(aiidalab_exec, nb_user):
7684
7785def test_pip_user_install (aiidalab_exec , pip_install , nb_user ):
7886 """Test that pip installs packages to ~/.local/ by default"""
79- import email
80-
8187 # We use 'tuna' as an example of python-only package without dependencies
8288 pkg = "tuna"
8389 pip_install (pkg )
@@ -86,3 +92,16 @@ def test_pip_user_install(aiidalab_exec, pip_install, nb_user):
8692 # `pip show` output is in the RFC-compliant email header format
8793 msg = email .message_from_string (output )
8894 assert msg .get ("Location" ).startswith (f"/home/{ nb_user } /.local/" )
95+
96+
97+ def test_pip_install_in_venv (aiidalab_exec , venv , nb_user ):
98+ """Test that pip installs packages to an activated venv"""
99+
100+ pkg = "tuna"
101+ pip = venv / "bin/pip"
102+
103+ aiidalab_exec (f"{ pip } install { pkg } " )
104+
105+ output = aiidalab_exec (f"{ pip } show { pkg } " )
106+ msg = email .message_from_string (output )
107+ assert msg .get ("Location" ).startswith (f"{ venv } /lib" )
0 commit comments