1
1
"""This module contains tests for the base image, which are AiiDA and package management related tests."""
2
2
3
+ import email
3
4
import json
4
5
5
6
import pytest
6
7
from packaging .version import parse
7
8
8
9
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
+
9
17
@pytest .mark .parametrize ("pkg_manager" , ["pip" , "mamba" ])
10
18
def test_prevent_installation_of_aiida (
11
19
aiidalab_exec , nb_user , aiida_version , pkg_manager
@@ -76,8 +84,6 @@ def test_path_local_pip(aiidalab_exec, nb_user):
76
84
77
85
def test_pip_user_install (aiidalab_exec , pip_install , nb_user ):
78
86
"""Test that pip installs packages to ~/.local/ by default"""
79
- import email
80
-
81
87
# We use 'tuna' as an example of python-only package without dependencies
82
88
pkg = "tuna"
83
89
pip_install (pkg )
@@ -86,3 +92,16 @@ def test_pip_user_install(aiidalab_exec, pip_install, nb_user):
86
92
# `pip show` output is in the RFC-compliant email header format
87
93
msg = email .message_from_string (output )
88
94
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