mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Added the useful thinking bit of the autoupdate and tests.
This commit is contained in:
parent
d8f8f5e1f4
commit
49da1ba72a
5 changed files with 144 additions and 8 deletions
|
|
@ -1,12 +1,24 @@
|
|||
|
||||
import jsonschema
|
||||
import os
|
||||
import os.path
|
||||
import pkg_resources
|
||||
import pytest
|
||||
import shutil
|
||||
import stat
|
||||
from plumbum import local
|
||||
|
||||
from pre_commit import git
|
||||
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
||||
from pre_commit.clientlib.validate_config import validate_config_extra
|
||||
from pre_commit.commands import install
|
||||
from pre_commit.commands import RepositoryCannotBeUpdatedError
|
||||
from pre_commit.commands import uninstall
|
||||
from pre_commit.commands import _update_repository
|
||||
from pre_commit.ordereddict import OrderedDict
|
||||
from pre_commit.runner import Runner
|
||||
from testing.auto_namedtuple import auto_namedtuple
|
||||
from testing.util import get_resource_path
|
||||
|
||||
|
||||
def test_install_pre_commit(empty_git_dir):
|
||||
|
|
@ -35,3 +47,70 @@ def test_uninstall(empty_git_dir):
|
|||
assert os.path.exists(runner.pre_commit_path)
|
||||
uninstall(runner)
|
||||
assert not os.path.exists(runner.pre_commit_path)
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def up_to_date_repo(python_hooks_repo):
|
||||
config = OrderedDict((
|
||||
('repo', python_hooks_repo),
|
||||
('sha', git.get_head_sha(python_hooks_repo)),
|
||||
('hooks', [{'id': 'foo', 'files': ''}]),
|
||||
))
|
||||
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
|
||||
validate_config_extra([config])
|
||||
yield auto_namedtuple(
|
||||
repo_config=config,
|
||||
python_hooks_repo=python_hooks_repo,
|
||||
)
|
||||
|
||||
|
||||
def test_up_to_date_repo(up_to_date_repo):
|
||||
input_sha = up_to_date_repo.repo_config['sha']
|
||||
ret = _update_repository(up_to_date_repo.repo_config)
|
||||
assert ret['sha'] == input_sha
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def out_of_date_repo(python_hooks_repo):
|
||||
config = OrderedDict((
|
||||
('repo', python_hooks_repo),
|
||||
('sha', git.get_head_sha(python_hooks_repo)),
|
||||
('hooks', [{'id': 'foo', 'files': ''}]),
|
||||
))
|
||||
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
|
||||
validate_config_extra([config])
|
||||
local['git']['commit', '--allow-empty', '-m', 'foo']()
|
||||
head_sha = git.get_head_sha(python_hooks_repo)
|
||||
yield auto_namedtuple(
|
||||
repo_config=config,
|
||||
head_sha=head_sha,
|
||||
python_hooks_repo=python_hooks_repo,
|
||||
)
|
||||
|
||||
|
||||
def test_out_of_date_repo(out_of_date_repo):
|
||||
ret = _update_repository(out_of_date_repo.repo_config)
|
||||
assert ret['sha'] == out_of_date_repo.head_sha
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def hook_disappearing_repo(python_hooks_repo):
|
||||
config = OrderedDict((
|
||||
('repo', python_hooks_repo),
|
||||
('sha', git.get_head_sha(python_hooks_repo)),
|
||||
('hooks', [{'id': 'foo', 'files': ''}]),
|
||||
))
|
||||
jsonschema.validate([config], CONFIG_JSON_SCHEMA)
|
||||
validate_config_extra([config])
|
||||
shutil.copy(get_resource_path('manifest_without_foo.yaml'), 'manifest.yaml')
|
||||
local['git']['add', '.']()
|
||||
local['git']['commit', '-m', 'Remove foo']()
|
||||
yield auto_namedtuple(
|
||||
repo_config=config,
|
||||
python_hooks_repo=python_hooks_repo,
|
||||
)
|
||||
|
||||
|
||||
def test_hook_disppearing_repo_raises(hook_disappearing_repo):
|
||||
with pytest.raises(RepositoryCannotBeUpdatedError):
|
||||
_update_repository(hook_disappearing_repo.repo_config)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue