|
5 | 5 | import os |
6 | 6 | import os.path |
7 | 7 | import shutil |
8 | | -from collections import defaultdict |
9 | 8 |
|
10 | 9 | import mock |
11 | 10 | import pytest |
|
14 | 13 | from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA |
15 | 14 | from pre_commit.clientlib.validate_config import validate_config_extra |
16 | 15 | 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 |
19 | 19 | from pre_commit.repository import Repository |
20 | 20 | from pre_commit.util import cmd_output |
21 | 21 | from pre_commit.util import cwd |
@@ -311,44 +311,45 @@ def test_additional_dependencies(tempdir_factory, store): |
311 | 311 | config = make_config_from_repo(path) |
312 | 312 | config['hooks'][0]['additional_dependencies'] = ['pep8'] |
313 | 313 | 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',)) |
317 | 315 |
|
318 | 316 |
|
319 | 317 | @pytest.mark.integration |
320 | 318 | def test_additional_python_dependencies_installed(tempdir_factory, store): |
321 | 319 | path = make_repo(tempdir_factory, 'python_hooks_repo') |
322 | 320 | config = make_config_from_repo(path) |
323 | | - config['hooks'][0]['additional_dependencies'] = ['pep8'] |
| 321 | + config['hooks'][0]['additional_dependencies'] = ['mccabe'] |
324 | 322 | repo = Repository.create(config, store) |
325 | 323 | 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 |
328 | 327 |
|
329 | 328 |
|
330 | 329 | @pytest.mark.integration |
331 | 330 | def test_additional_ruby_dependencies_installed(tempdir_factory, store): |
332 | 331 | path = make_repo(tempdir_factory, 'ruby_hooks_repo') |
333 | 332 | config = make_config_from_repo(path) |
334 | | - config['hooks'][0]['additional_dependencies'] = ['rubocop'] |
| 333 | + config['hooks'][0]['additional_dependencies'] = ['mime-types'] |
335 | 334 | repo = Repository.create(config, store) |
336 | 335 | 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 |
339 | 339 |
|
340 | 340 |
|
341 | 341 | @pytest.mark.integration |
342 | 342 | def test_additional_node_dependencies_installed(tempdir_factory, store): |
343 | 343 | path = make_repo(tempdir_factory, 'node_hooks_repo') |
344 | 344 | 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'] |
346 | 347 | repo = Repository.create(config, store) |
347 | 348 | 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 |
352 | 353 |
|
353 | 354 |
|
354 | 355 | def test_reinstall(tempdir_factory, store, log_info_mock): |
@@ -383,7 +384,7 @@ class MyKeyboardInterrupt(KeyboardInterrupt): |
383 | 384 | # raise as well. |
384 | 385 | with pytest.raises(MyKeyboardInterrupt): |
385 | 386 | with mock.patch.object( |
386 | | - PythonEnv, 'run', side_effect=MyKeyboardInterrupt, |
| 387 | + python.PythonEnv, 'run', side_effect=MyKeyboardInterrupt, |
387 | 388 | ): |
388 | 389 | with mock.patch.object( |
389 | 390 | shutil, 'rmtree', side_effect=MyKeyboardInterrupt, |
@@ -474,5 +475,5 @@ def test_norm_version_expanduser(): # pragma: no cover |
474 | 475 | else: |
475 | 476 | path = '~/.pyenv/versions/3.4.3/bin/python' |
476 | 477 | expected_path = home + '/.pyenv/versions/3.4.3/bin/python' |
477 | | - result = norm_version(path) |
| 478 | + result = python.norm_version(path) |
478 | 479 | assert result == expected_path |
0 commit comments