mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 00:54:42 +04:00
Add an install-hooks command (similar to install --install-hooks). Resolves #456
This commit is contained in:
parent
8837cfa7ff
commit
f238495d6b
4 changed files with 51 additions and 10 deletions
|
|
@ -13,6 +13,7 @@ import mock
|
|||
import pre_commit.constants as C
|
||||
from pre_commit.commands.install_uninstall import IDENTIFYING_HASH
|
||||
from pre_commit.commands.install_uninstall import install
|
||||
from pre_commit.commands.install_uninstall import install_hooks
|
||||
from pre_commit.commands.install_uninstall import is_our_pre_commit
|
||||
from pre_commit.commands.install_uninstall import is_previous_pre_commit
|
||||
from pre_commit.commands.install_uninstall import PREVIOUS_IDENTIFYING_HASHES
|
||||
|
|
@ -460,6 +461,20 @@ def test_installs_hooks_with_hooks_True(
|
|||
assert PRE_INSTALLED.match(output)
|
||||
|
||||
|
||||
def test_install_hooks_command(tempdir_factory, mock_out_store_directory):
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(path):
|
||||
runner = Runner(path, C.CONFIG_FILE)
|
||||
install(runner)
|
||||
install_hooks(runner)
|
||||
ret, output = _get_commit_output(
|
||||
tempdir_factory, pre_commit_home=mock_out_store_directory,
|
||||
)
|
||||
|
||||
assert ret == 0
|
||||
assert PRE_INSTALLED.match(output)
|
||||
|
||||
|
||||
def test_installed_from_venv(tempdir_factory):
|
||||
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with cwd(path):
|
||||
|
|
|
|||
|
|
@ -15,17 +15,19 @@ from testing.auto_namedtuple import auto_namedtuple
|
|||
@pytest.yield_fixture
|
||||
def mock_commands():
|
||||
with mock.patch.object(main, 'autoupdate') as autoupdate_mock:
|
||||
with mock.patch.object(main, 'clean') as clean_mock:
|
||||
with mock.patch.object(main, 'install_hooks') as install_hooks_mock:
|
||||
with mock.patch.object(main, 'install') as install_mock:
|
||||
with mock.patch.object(main, 'uninstall') as uninstall_mock:
|
||||
with mock.patch.object(main, 'run') as run_mock:
|
||||
yield auto_namedtuple(
|
||||
autoupdate_mock=autoupdate_mock,
|
||||
clean_mock=clean_mock,
|
||||
install_mock=install_mock,
|
||||
uninstall_mock=uninstall_mock,
|
||||
run_mock=run_mock,
|
||||
)
|
||||
with mock.patch.object(main, 'clean') as clean_mock:
|
||||
yield auto_namedtuple(
|
||||
autoupdate_mock=autoupdate_mock,
|
||||
clean_mock=clean_mock,
|
||||
install_mock=install_mock,
|
||||
install_hooks_mock=install_hooks_mock,
|
||||
uninstall_mock=uninstall_mock,
|
||||
run_mock=run_mock,
|
||||
)
|
||||
|
||||
|
||||
class CalledExit(Exception):
|
||||
|
|
@ -121,6 +123,12 @@ def test_run_command(mock_commands):
|
|||
assert_only_one_mock_called(mock_commands)
|
||||
|
||||
|
||||
def test_install_hooks_command(mock_commands):
|
||||
main.main(('install-hooks',))
|
||||
assert mock_commands.install_hooks_mock.call_count == 1
|
||||
assert_only_one_mock_called(mock_commands)
|
||||
|
||||
|
||||
def test_no_commands_run_command(mock_commands):
|
||||
main.main([])
|
||||
assert mock_commands.run_mock.call_count == 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue