Skip to content

Commit 738c2ad

Browse files
committed
Fixups + make the tests work
1 parent 0ee4c3e commit 738c2ad

File tree

4 files changed

+25
-27
lines changed

4 files changed

+25
-27
lines changed

pre_commit/languages/node.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ def install_environment(
5050
node_env.run(
5151
"cd '{prefix}' && npm install -g " +
5252
' '.join(
53-
[shell_escape(dep) for dep in
54-
additional_dependencies]
53+
shell_escape(dep) for dep in additional_dependencies
5554
)
5655
)
5756

pre_commit/languages/ruby.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,14 @@ def install_environment(
9393
if version != 'default':
9494
_install_ruby(ruby_env, version)
9595
ruby_env.run(
96-
'cd {prefix} && gem build *.gemspec'
97-
' && gem install --no-ri --no-rdoc *.gem',
96+
'cd {prefix} && gem build *.gemspec && '
97+
'gem install --no-ri --no-rdoc *.gem',
9898
)
9999
if additional_dependencies:
100100
ruby_env.run(
101-
'cd {prefix} && gem install --no-document ' +
101+
'cd {prefix} && gem install --no-ri --no-rdoc ' +
102102
' '.join(
103-
shell_escape(dep) for dep in
104-
additional_dependencies
103+
shell_escape(dep) for dep in additional_dependencies
105104
)
106105
)
107106

pre_commit/languages/script.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def install_environment(
1818
def run_hook(repo_cmd_runner, hook, file_args):
1919
return repo_cmd_runner.run(
2020
['xargs', '-0', '{{prefix}}{0}'.format(hook['entry'])] + hook['args'],
21-
# TODO: this is duplicated in pre_commit/languages/helpers.py
2221
stdin=file_args_to_stdin(file_args),
2322
retcode=None,
2423
encoding=None,

tests/repository_test.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import os
66
import os.path
77
import shutil
8-
from collections import defaultdict
98

109
import mock
1110
import pytest
@@ -14,8 +13,9 @@
1413
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
1514
from pre_commit.clientlib.validate_config import validate_config_extra
1615
from pre_commit.jsonschema_extensions import apply_defaults
17-
from pre_commit.languages.python import norm_version
18-
from pre_commit.languages.python import PythonEnv
16+
from pre_commit.languages import node
17+
from pre_commit.languages import python
18+
from pre_commit.languages import ruby
1919
from pre_commit.repository import Repository
2020
from pre_commit.util import cmd_output
2121
from pre_commit.util import cwd
@@ -311,44 +311,45 @@ def test_additional_dependencies(tempdir_factory, store):
311311
config = make_config_from_repo(path)
312312
config['hooks'][0]['additional_dependencies'] = ['pep8']
313313
repo = Repository.create(config, store)
314-
expected_deps = defaultdict(lambda: defaultdict(set))
315-
expected_deps['python']['default'].update(['pep8'])
316-
assert repo.additional_dependencies == expected_deps
314+
assert repo.additional_dependencies['python']['default'] == set(('pep8',))
317315

318316

319317
@pytest.mark.integration
320318
def test_additional_python_dependencies_installed(tempdir_factory, store):
321319
path = make_repo(tempdir_factory, 'python_hooks_repo')
322320
config = make_config_from_repo(path)
323-
config['hooks'][0]['additional_dependencies'] = ['pep8']
321+
config['hooks'][0]['additional_dependencies'] = ['mccabe']
324322
repo = Repository.create(config, store)
325323
repo.run_hook(repo.hooks[0][1], [])
326-
output = repo.cmd_runner.run(['pip', 'freeze'])
327-
assert 'pep8' in output[1]
324+
with python.in_env(repo.cmd_runner, 'default') as env:
325+
output = env.run('pip freeze -l')[1]
326+
assert 'mccabe' in output
328327

329328

330329
@pytest.mark.integration
331330
def test_additional_ruby_dependencies_installed(tempdir_factory, store):
332331
path = make_repo(tempdir_factory, 'ruby_hooks_repo')
333332
config = make_config_from_repo(path)
334-
config['hooks'][0]['additional_dependencies'] = ['rubocop']
333+
config['hooks'][0]['additional_dependencies'] = ['mime-types']
335334
repo = Repository.create(config, store)
336335
repo.run_hook(repo.hooks[0][1], [])
337-
output = repo.cmd_runner.run(['gem', 'list', '--local'])
338-
assert 'rubocop' in output[1]
336+
with ruby.in_env(repo.cmd_runner, 'default') as env:
337+
output = env.run('gem list --local')[1]
338+
assert 'mime-types' in output
339339

340340

341341
@pytest.mark.integration
342342
def test_additional_node_dependencies_installed(tempdir_factory, store):
343343
path = make_repo(tempdir_factory, 'node_hooks_repo')
344344
config = make_config_from_repo(path)
345-
config['hooks'][0]['additional_dependencies'] = ['eslint']
345+
# Careful to choose a small package that's not depped by npm
346+
config['hooks'][0]['additional_dependencies'] = ['lodash']
346347
repo = Repository.create(config, store)
347348
repo.run_hook(repo.hooks[0][1], [])
348-
repo.cmd_runner.run(['npm', 'config', 'set', 'global', 'true',
349-
'&&', 'npm', 'ls'])
350-
output = repo.cmd_runner.run(['npm', 'ls'])
351-
assert 'eslint' in output[1]
349+
with node.in_env(repo.cmd_runner, 'default') as env:
350+
env.run('npm config set global true')
351+
output = env.run(('npm ls'))[1]
352+
assert 'lodash' in output
352353

353354

354355
def test_reinstall(tempdir_factory, store, log_info_mock):
@@ -383,7 +384,7 @@ class MyKeyboardInterrupt(KeyboardInterrupt):
383384
# raise as well.
384385
with pytest.raises(MyKeyboardInterrupt):
385386
with mock.patch.object(
386-
PythonEnv, 'run', side_effect=MyKeyboardInterrupt,
387+
python.PythonEnv, 'run', side_effect=MyKeyboardInterrupt,
387388
):
388389
with mock.patch.object(
389390
shutil, 'rmtree', side_effect=MyKeyboardInterrupt,
@@ -474,5 +475,5 @@ def test_norm_version_expanduser(): # pragma: no cover
474475
else:
475476
path = '~/.pyenv/versions/3.4.3/bin/python'
476477
expected_path = home + '/.pyenv/versions/3.4.3/bin/python'
477-
result = norm_version(path)
478+
result = python.norm_version(path)
478479
assert result == expected_path

0 commit comments

Comments
 (0)