mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 09:04:41 +04:00
Added unit tests for dependencies
This commit is contained in:
parent
862426576f
commit
0ee4c3efa7
4 changed files with 62 additions and 11 deletions
|
|
@ -47,11 +47,13 @@ def install_environment(
|
||||||
with in_env(repo_cmd_runner, version) as node_env:
|
with in_env(repo_cmd_runner, version) as node_env:
|
||||||
node_env.run("cd '{prefix}' && npm install -g")
|
node_env.run("cd '{prefix}' && npm install -g")
|
||||||
if additional_dependencies:
|
if additional_dependencies:
|
||||||
node_env.run("cd '{prefix}' && npm install -g {deps}".format(
|
node_env.run(
|
||||||
|
"cd '{prefix}' && npm install -g " +
|
||||||
' '.join(
|
' '.join(
|
||||||
[shell_escape(dep) for dep in additional_dependencies]
|
[shell_escape(dep) for dep in
|
||||||
|
additional_dependencies]
|
||||||
)
|
)
|
||||||
))
|
)
|
||||||
|
|
||||||
|
|
||||||
def run_hook(repo_cmd_runner, hook, file_args):
|
def run_hook(repo_cmd_runner, hook, file_args):
|
||||||
|
|
|
||||||
|
|
@ -63,11 +63,12 @@ def install_environment(
|
||||||
with in_env(repo_cmd_runner, version) as env:
|
with in_env(repo_cmd_runner, version) as env:
|
||||||
env.run("cd '{prefix}' && pip install .")
|
env.run("cd '{prefix}' && pip install .")
|
||||||
if additional_dependencies:
|
if additional_dependencies:
|
||||||
env.run("cd '{prefix}' && pip install {deps}".format(
|
env.run(
|
||||||
|
"cd '{prefix}' && pip install " +
|
||||||
' '.join(
|
' '.join(
|
||||||
shell_escape(dep) for dep in additional_dependencies
|
shell_escape(dep) for dep in additional_dependencies
|
||||||
)
|
)
|
||||||
))
|
)
|
||||||
|
|
||||||
|
|
||||||
def run_hook(repo_cmd_runner, hook, file_args):
|
def run_hook(repo_cmd_runner, hook, file_args):
|
||||||
|
|
|
||||||
|
|
@ -98,12 +98,12 @@ def install_environment(
|
||||||
)
|
)
|
||||||
if additional_dependencies:
|
if additional_dependencies:
|
||||||
ruby_env.run(
|
ruby_env.run(
|
||||||
'cd {prefix} && gem install --no-document {deps}'.format(
|
'cd {prefix} && gem install --no-document ' +
|
||||||
' '.join(
|
' '.join(
|
||||||
shell_escape(dep) for dep in
|
shell_escape(dep) for dep in
|
||||||
additional_dependencies
|
additional_dependencies
|
||||||
)
|
)
|
||||||
))
|
)
|
||||||
|
|
||||||
|
|
||||||
def run_hook(repo_cmd_runner, hook, file_args):
|
def run_hook(repo_cmd_runner, hook, file_args):
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import io
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import shutil
|
import shutil
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
@ -278,6 +279,7 @@ def mock_repo_config():
|
||||||
'hooks': [{
|
'hooks': [{
|
||||||
'id': 'pyflakes',
|
'id': 'pyflakes',
|
||||||
'files': '\\.py$',
|
'files': '\\.py$',
|
||||||
|
'additional_dependencies': ['pep8']
|
||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
config_wrapped = apply_defaults([config], CONFIG_JSON_SCHEMA)
|
config_wrapped = apply_defaults([config], CONFIG_JSON_SCHEMA)
|
||||||
|
|
@ -303,6 +305,52 @@ def test_languages(tempdir_factory, store):
|
||||||
assert repo.languages == set([('python', 'default')])
|
assert repo.languages == set([('python', 'default')])
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.integration
|
||||||
|
def test_additional_dependencies(tempdir_factory, store):
|
||||||
|
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
||||||
|
config = make_config_from_repo(path)
|
||||||
|
config['hooks'][0]['additional_dependencies'] = ['pep8']
|
||||||
|
repo = Repository.create(config, store)
|
||||||
|
expected_deps = defaultdict(lambda: defaultdict(set))
|
||||||
|
expected_deps['python']['default'].update(['pep8'])
|
||||||
|
assert repo.additional_dependencies == expected_deps
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.integration
|
||||||
|
def test_additional_python_dependencies_installed(tempdir_factory, store):
|
||||||
|
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
||||||
|
config = make_config_from_repo(path)
|
||||||
|
config['hooks'][0]['additional_dependencies'] = ['pep8']
|
||||||
|
repo = Repository.create(config, store)
|
||||||
|
repo.run_hook(repo.hooks[0][1], [])
|
||||||
|
output = repo.cmd_runner.run(['pip', 'freeze'])
|
||||||
|
assert 'pep8' in output[1]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.integration
|
||||||
|
def test_additional_ruby_dependencies_installed(tempdir_factory, store):
|
||||||
|
path = make_repo(tempdir_factory, 'ruby_hooks_repo')
|
||||||
|
config = make_config_from_repo(path)
|
||||||
|
config['hooks'][0]['additional_dependencies'] = ['rubocop']
|
||||||
|
repo = Repository.create(config, store)
|
||||||
|
repo.run_hook(repo.hooks[0][1], [])
|
||||||
|
output = repo.cmd_runner.run(['gem', 'list', '--local'])
|
||||||
|
assert 'rubocop' in output[1]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.integration
|
||||||
|
def test_additional_node_dependencies_installed(tempdir_factory, store):
|
||||||
|
path = make_repo(tempdir_factory, 'node_hooks_repo')
|
||||||
|
config = make_config_from_repo(path)
|
||||||
|
config['hooks'][0]['additional_dependencies'] = ['eslint']
|
||||||
|
repo = Repository.create(config, store)
|
||||||
|
repo.run_hook(repo.hooks[0][1], [])
|
||||||
|
repo.cmd_runner.run(['npm', 'config', 'set', 'global', 'true',
|
||||||
|
'&&', 'npm', 'ls'])
|
||||||
|
output = repo.cmd_runner.run(['npm', 'ls'])
|
||||||
|
assert 'eslint' in output[1]
|
||||||
|
|
||||||
|
|
||||||
def test_reinstall(tempdir_factory, store, log_info_mock):
|
def test_reinstall(tempdir_factory, store, log_info_mock):
|
||||||
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
||||||
config = make_config_from_repo(path)
|
config = make_config_from_repo(path)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue