-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_runtime_env.py
209 lines (165 loc) · 7.19 KB
/
test_runtime_env.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
from runtime_env import RuntimeEnvironment
from packaging import tags
import os
import pytest
cvmfs = pytest.mark.skipif(
not os.path.isdir("/cvmfs"), reason="tests for /cvmfs only"
)
venv = pytest.mark.skipif(
os.environ.get("VIRTUAL_ENV") is None, reason="No virtual env are activated."
)
def test_wheelhouse_default(monkeypatch):
"""
Test that the default wheelhouse is /cvmfs/soft.computecanada.ca/custom/python/wheelhouse
"""
monkeypatch.delenv("WHEELHOUSE", raising=False)
assert RuntimeEnvironment().wheelhouse == "/cvmfs/soft.computecanada.ca/custom/python/wheelhouse"
def test_wheelhouse_variable(monkeypatch):
"""
Test that the wheelhouse is read from WHEELHOUSE enviroment variable.
"""
monkeypatch.setenv("WHEELHOUSE", "potato/house/")
assert RuntimeEnvironment().wheelhouse == "potato/house/"
def test_pip_config_file_default(monkeypatch):
"""
Test that the default pip_config_file is None
"""
monkeypatch.delenv("PIP_CONFIG_FILE", raising=False)
assert RuntimeEnvironment().pip_config_file is None
def test_pip_config_file_variable(monkeypatch):
"""
Test that the pip config file is read from PIP_CONFIG_FILE enviroment variable.
"""
monkeypatch.setenv("PIP_CONFIG_FILE", "pip.conf")
assert RuntimeEnvironment().pip_config_file == "pip.conf"
def test_current_python_default(monkeypatch):
"""
Test that the default current_python is None
"""
monkeypatch.delenv("VIRTUAL_ENV", raising=False)
monkeypatch.delenv("EBVERSIONPYTHON", raising=False)
assert RuntimeEnvironment().current_python is None
@pytest.mark.parametrize("input,expected", [
("3.8.2", "3.8"),
("3.10.2", "3.10"),
])
def test_current_python_variable_module(monkeypatch, input, expected):
"""
Test that the current python version is read from EBVERSIONPYTHON enviroment variable.
"""
monkeypatch.setenv("EBVERSIONPYTHON", input)
monkeypatch.delenv("VIRTUAL_ENV", raising=False)
assert RuntimeEnvironment().current_python == expected
@venv
def test_current_python_variable_venv(monkeypatch):
"""
Test that the current python version is read from VIRTUAL_ENV enviroment variable.
A python 3.11 virtual env is expected to exists.
"""
monkeypatch.delenv("EBVERSIONPYTHON", raising=False)
assert RuntimeEnvironment().current_python == "3.11"
# Ensure virtual env python has priority
monkeypatch.setenv("EBVERSIONPYTHON", "3.10.2")
assert RuntimeEnvironment().current_python == "3.11"
def test_python_dirs_default(monkeypatch):
"""
Test that the default python directories is from
/cvmfs/soft.computecanada.ca/easybuild/software/20*/Core/python:/cvmfs/soft.computecanada.ca/easybuild/software/20*/*/Core/python:/cvmfs/soft.computecanada.ca/easybuild/software/20*/*/Compiler/gcccore/python
"""
monkeypatch.delenv("PYTHON_DIRS", raising=False)
assert RuntimeEnvironment().python_directories == ":".join(
[
"/cvmfs/soft.computecanada.ca/easybuild/software/20*/Core/python",
"/cvmfs/soft.computecanada.ca/easybuild/software/20*/*/Core/python",
"/cvmfs/soft.computecanada.ca/easybuild/software/20*/*/Compiler/gcccore/python",
]
)
def test_python_dirs_variable(monkeypatch):
"""
Test that the python directories is read from PYTHON_DIRS enviroment variable.
"""
monkeypatch.setenv("PYTHON_DIRS", "potato/dir/")
assert RuntimeEnvironment().python_directories == "potato/dir/"
def test_current_architecture_default(monkeypatch):
"""
Test that the default current architecture is None when RSNT_ARCH is not defined
"""
monkeypatch.delenv("RSNT_ARCH", raising=False)
assert RuntimeEnvironment().current_architecture is None
def test_current_architecture_variable(monkeypatch):
"""
Test that the current architecture is read from RSNT_ARCH enviroment variable.
"""
arch = "generic"
monkeypatch.setenv("RSNT_ARCH", arch)
assert RuntimeEnvironment().current_architecture == arch
def test_available_architectures(monkeypatch):
"""
Test that the default available_architectures is a frozenset(['avx', 'avx2', 'avx512', 'generic', 'sse3'])
prior to 2023, and a frozenset(['x86-64-v3', 'x86-64-v4', 'generic']) for 2023 forward.
"""
# An environment variable EBVERSIONGENTOO is used to determine the available architectures
# and exists under 2020 and 2023, but not under 2020
monkeypatch.delenv("EBVERSIONGENTOO", raising=False) # prior to 2020
assert isinstance(RuntimeEnvironment().available_architectures, frozenset)
assert RuntimeEnvironment().available_architectures == frozenset(
["avx", "avx2", "avx512", "generic", "sse3"]
)
monkeypatch.setenv("EBVERSIONGENTOO", "2020")
assert isinstance(RuntimeEnvironment().available_architectures, frozenset)
assert RuntimeEnvironment().available_architectures == frozenset(
["avx", "avx2", "avx512", "generic", "sse3"]
)
monkeypatch.setenv("EBVERSIONGENTOO", "2023")
assert isinstance(RuntimeEnvironment().available_architectures, frozenset)
assert RuntimeEnvironment().available_architectures == frozenset(
["x86-64-v3", "x86-64-v4", "generic"]
)
def test_available_pythons(monkeypatch, tmp_path):
"""
Test that the default available pythons versions are from tmp directory.
"""
pd = tmp_path / "python/2017"
for d in ["2.7.18", "3.7.4", "3.8.2"]:
(pd / d).mkdir(parents=True)
monkeypatch.setenv("PYTHON_DIRS", f"{str(tmp_path)}/python/2017")
assert RuntimeEnvironment().available_pythons == ["2.7", "3.7", "3.8"]
pd = tmp_path / "python/2021"
(pd / "3.9.6").mkdir(parents=True)
monkeypatch.setenv("PYTHON_DIRS", f"{str(tmp_path)}/python/2017:{str(tmp_path)}/python/2021")
assert RuntimeEnvironment().available_pythons == ["2.7", "3.7", "3.8", "3.9"]
@cvmfs
def test_available_pythons_cvmfs(monkeypatch):
"""
Test that the default available pythons versions are from CVMFS.
"""
monkeypatch.delenv("PYTHON_DIRS", raising=False)
assert RuntimeEnvironment().available_pythons == ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
@pytest.mark.parametrize("python,tag", [
("3.8", "38"),
("3.10", "310"),
])
def test_compatible_tags(python, tag):
"""
Test the python 3.8 and 3.10 compatible tags.
"""
platform = list(tags._generic_platforms())[0]
other = frozenset(
[
tags.Tag(f"cp{tag}", f"cp{tag}", platform),
tags.Tag(f"cp{tag}", "abi3", platform),
tags.Tag(f"cp{tag}", "none", platform),
tags.Tag(f"py{tag}", "none", platform),
tags.Tag("py3", "none", platform),
tags.Tag(f"py{tag}", "none", "any"),
tags.Tag("py3", "none", "any"),
]
)
env = RuntimeEnvironment()
assert isinstance(env.compatible_tags, dict)
assert isinstance(env.compatible_tags[python], frozenset)
for tag in other:
assert tag in env.compatible_tags[python]
# Test that previous compatible tags are included
assert tags.Tag("cp38", "abi3", "linux_x86_64") in env.compatible_tags[python]
assert tags.Tag("py38", "none", "linux_x86_64") in env.compatible_tags[python]