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
|
from __future__ import annotations
import os.path
import pytest
from pre_commit import envcontext
from pre_commit.languages import conda
from pre_commit.store import _make_local_repo
from testing.language_helpers import run_language
@pytest.mark.parametrize(
('ctx', 'expected'),
(
pytest.param(
(
('PRE_COMMIT_USE_MICROMAMBA', envcontext.UNSET),
('PRE_COMMIT_USE_MAMBA', envcontext.UNSET),
),
'conda',
id='default',
),
pytest.param(
(
('PRE_COMMIT_USE_MICROMAMBA', '1'),
('PRE_COMMIT_USE_MAMBA', ''),
),
'micromamba',
id='default',
),
pytest.param(
(
('PRE_COMMIT_USE_MICROMAMBA', ''),
('PRE_COMMIT_USE_MAMBA', '1'),
),
'mamba',
id='default',
),
),
)
def test_conda_exe(ctx, expected):
with envcontext.envcontext(ctx):
assert conda._conda_exe() == expected
def test_conda_language(tmp_path):
environment_yml = '''\
channels: [conda-forge, defaults]
dependencies: [python, pip]
'''
tmp_path.joinpath('environment.yml').write_text(environment_yml)
ret, out = run_language(
tmp_path,
conda,
'python -c "import sys; print(sys.prefix)"',
)
assert ret == 0
assert os.path.basename(out.strip()) == b'conda-default'
def test_conda_additional_deps(tmp_path):
_make_local_repo(tmp_path)
ret = run_language(
tmp_path,
conda,
'python -c "import botocore; print(1)"',
deps=('botocore',),
)
assert ret == (0, b'1\n')
|