mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Factor out bash and activate files
This commit is contained in:
parent
00a3a9a09b
commit
a5b56bd9e3
13 changed files with 149 additions and 189 deletions
|
|
@ -14,7 +14,7 @@ def test_install_environment_argspec(language):
|
|||
args=['repo_cmd_runner', 'version', 'additional_dependencies'],
|
||||
varargs=None,
|
||||
keywords=None,
|
||||
defaults=('default', None),
|
||||
defaults=('default', ()),
|
||||
)
|
||||
argspec = inspect.getargspec(languages[language].install_environment)
|
||||
assert argspec == expected_argspec
|
||||
|
|
|
|||
|
|
@ -110,35 +110,6 @@ def test_path_multiple_args():
|
|||
assert ret == os.path.join('foo', 'bar', 'baz')
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('prefix', 'path_end', 'expected_output'),
|
||||
tuple(
|
||||
(prefix, path_end, expected_output + os.sep)
|
||||
for prefix, path_end, expected_output in PATH_TESTS
|
||||
),
|
||||
)
|
||||
def test_from_command_runner(prefix, path_end, expected_output):
|
||||
first = PrefixedCommandRunner(prefix)
|
||||
second = PrefixedCommandRunner.from_command_runner(first, path_end)
|
||||
assert second.prefix_dir == expected_output
|
||||
|
||||
|
||||
def test_from_command_runner_preserves_popen(popen_mock, makedirs_mock):
|
||||
first = PrefixedCommandRunner(
|
||||
'foo', popen=popen_mock, makedirs=makedirs_mock,
|
||||
)
|
||||
second = PrefixedCommandRunner.from_command_runner(first, 'bar')
|
||||
second.run(['foo/bar/baz'], retcode=None)
|
||||
popen_mock.assert_called_once_with(
|
||||
[five.n('foo/bar/baz')],
|
||||
env=None,
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
makedirs_mock.assert_called_once_with(os.path.join('foo', 'bar') + os.sep)
|
||||
|
||||
|
||||
def test_create_path_if_not_exists(in_tmpdir):
|
||||
instance = PrefixedCommandRunner('foo')
|
||||
assert not os.path.exists('foo')
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ from pre_commit import five
|
|||
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
||||
from pre_commit.clientlib.validate_config import validate_config_extra
|
||||
from pre_commit.jsonschema_extensions import apply_defaults
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.languages import node
|
||||
from pre_commit.languages import python
|
||||
from pre_commit.languages import ruby
|
||||
|
|
@ -355,8 +356,8 @@ def test_additional_python_dependencies_installed(tempdir_factory, store):
|
|||
config['hooks'][0]['additional_dependencies'] = ['mccabe']
|
||||
repo = Repository.create(config, store)
|
||||
repo.run_hook(repo.hooks[0][1], [])
|
||||
with python.in_env(repo.cmd_runner, 'default') as env:
|
||||
output = env.run('pip freeze -l')[1]
|
||||
with python.in_env(repo.cmd_runner, 'default'):
|
||||
output = cmd_output('pip', 'freeze', '-l')[1]
|
||||
assert 'mccabe' in output
|
||||
|
||||
|
||||
|
|
@ -372,8 +373,8 @@ def test_additional_dependencies_roll_forward(tempdir_factory, store):
|
|||
repo = Repository.create(config, store)
|
||||
repo.run_hook(repo.hooks[0][1], [])
|
||||
# We should see our additional dependency installed
|
||||
with python.in_env(repo.cmd_runner, 'default') as env:
|
||||
output = env.run('pip freeze -l')[1]
|
||||
with python.in_env(repo.cmd_runner, 'default'):
|
||||
output = cmd_output('pip', 'freeze', '-l')[1]
|
||||
assert 'mccabe' in output
|
||||
|
||||
|
||||
|
|
@ -388,8 +389,8 @@ def test_additional_ruby_dependencies_installed(
|
|||
config['hooks'][0]['additional_dependencies'] = ['thread_safe']
|
||||
repo = Repository.create(config, store)
|
||||
repo.run_hook(repo.hooks[0][1], [])
|
||||
with ruby.in_env(repo.cmd_runner, 'default') as env:
|
||||
output = env.run('gem list --local')[1]
|
||||
with ruby.in_env(repo.cmd_runner, 'default'):
|
||||
output = cmd_output('gem', 'list', '--local')[1]
|
||||
assert 'thread_safe' in output
|
||||
|
||||
|
||||
|
|
@ -405,9 +406,9 @@ def test_additional_node_dependencies_installed(
|
|||
config['hooks'][0]['additional_dependencies'] = ['lodash']
|
||||
repo = Repository.create(config, store)
|
||||
repo.run_hook(repo.hooks[0][1], [])
|
||||
with node.in_env(repo.cmd_runner, 'default') as env:
|
||||
env.run('npm config set global true')
|
||||
output = env.run(('npm ls'))[1]
|
||||
with node.in_env(repo.cmd_runner, 'default'):
|
||||
cmd_output('npm', 'config', 'set', 'global', 'true')
|
||||
output = cmd_output('npm', 'ls')[1]
|
||||
assert 'lodash' in output
|
||||
|
||||
|
||||
|
|
@ -443,7 +444,7 @@ def test_control_c_control_c_on_install(tempdir_factory, store):
|
|||
# raise as well.
|
||||
with pytest.raises(MyKeyboardInterrupt):
|
||||
with mock.patch.object(
|
||||
python.PythonEnv, 'run', side_effect=MyKeyboardInterrupt,
|
||||
helpers, 'run_setup_cmd', side_effect=MyKeyboardInterrupt,
|
||||
):
|
||||
with mock.patch.object(
|
||||
shutil, 'rmtree', side_effect=MyKeyboardInterrupt,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue