mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
test conda language directly
This commit is contained in:
parent
0316676fdc
commit
f1b5f66374
6 changed files with 57 additions and 79 deletions
|
|
@ -1,9 +1,13 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import os.path
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit import envcontext
|
||||
from pre_commit.languages.conda import _conda_exe
|
||||
from pre_commit.languages import conda
|
||||
from pre_commit.store import _make_local_repo
|
||||
from testing.language_helpers import run_language
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -37,4 +41,32 @@ from pre_commit.languages.conda import _conda_exe
|
|||
)
|
||||
def test_conda_exe(ctx, expected):
|
||||
with envcontext.envcontext(ctx):
|
||||
assert _conda_exe() == expected
|
||||
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')
|
||||
|
|
|
|||
|
|
@ -88,47 +88,6 @@ def _test_hook_repo(
|
|||
assert _norm_out(out) == expected
|
||||
|
||||
|
||||
def test_conda_hook(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tempdir_factory, store, 'conda_hooks_repo',
|
||||
'sys-exec', [os.devnull],
|
||||
b'conda-default\n',
|
||||
)
|
||||
|
||||
|
||||
def test_conda_with_additional_dependencies_hook(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tempdir_factory, store, 'conda_hooks_repo',
|
||||
'additional-deps', [os.devnull],
|
||||
b'OK\n',
|
||||
config_kwargs={
|
||||
'hooks': [{
|
||||
'id': 'additional-deps',
|
||||
'args': ['-c', 'import tzdata; print("OK")'],
|
||||
'additional_dependencies': ['python-tzdata'],
|
||||
}],
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def test_local_conda_additional_dependencies(store):
|
||||
config = {
|
||||
'repo': 'local',
|
||||
'hooks': [{
|
||||
'id': 'local-conda',
|
||||
'name': 'local-conda',
|
||||
'entry': 'python',
|
||||
'language': 'conda',
|
||||
'args': ['-c', 'import botocore; print("OK")'],
|
||||
'additional_dependencies': ['botocore'],
|
||||
}],
|
||||
}
|
||||
hook = _get_hook(config, store, 'local-conda')
|
||||
ret, out = _hook_run(hook, (), color=False)
|
||||
assert ret == 0
|
||||
assert _norm_out(out) == b'OK\n'
|
||||
|
||||
|
||||
def test_python_hook(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tempdir_factory, store, 'python_hooks_repo',
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import pytest
|
|||
|
||||
from pre_commit import git
|
||||
from pre_commit.store import _get_default_directory
|
||||
from pre_commit.store import _LOCAL_RESOURCES
|
||||
from pre_commit.store import Store
|
||||
from pre_commit.util import CalledProcessError
|
||||
from pre_commit.util import cmd_output
|
||||
|
|
@ -188,7 +189,7 @@ def test_local_resources_reflects_reality():
|
|||
for res in os.listdir('pre_commit/resources')
|
||||
if res.startswith('empty_template_')
|
||||
}
|
||||
assert on_disk == {os.path.basename(x) for x in Store.LOCAL_RESOURCES}
|
||||
assert on_disk == {os.path.basename(x) for x in _LOCAL_RESOURCES}
|
||||
|
||||
|
||||
def test_mark_config_as_used(store, tmpdir):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue