Refactored how the installer works

This commit is contained in:
Anthony Sottile 2014-03-13 19:36:44 -07:00
parent 8b0247e17f
commit abea886a3d
8 changed files with 105 additions and 70 deletions

View file

@ -2,31 +2,46 @@ import os
import jsonschema
import pytest
from plumbum import local
from pre_commit import git
import pre_commit.constants as C
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
from pre_commit.repo_installer import create_repo_in_env
from pre_commit.repo_installer import install_pre_commit
from pre_commit.repo_installer import RepoInstaller
def get_sha(git_repo):
with local.cwd(git_repo):
return (local['git']['log', '--format="%H"'] | local['head']['-n1'])().strip('"\n')
@pytest.fixture
def dummy_repo_config(dummy_git_repo):
# This is not a valid config, but it is pretty close
return {
'repo': dummy_git_repo,
'sha': git.get_head_sha(dummy_git_repo),
'hooks': [],
}
@pytest.mark.integration
def test_create_repo_in_env(empty_git_dir, dummy_git_repo):
sha = get_sha(dummy_git_repo)
create_repo_in_env(dummy_git_repo, sha)
def test_create_repo_in_env(dummy_repo_config, dummy_git_repo):
repo_installer = RepoInstaller(dummy_repo_config)
repo_installer.create()
assert os.path.exists(os.path.join(dummy_git_repo, C.PRE_COMMIT_DIR, sha))
assert os.path.exists(
os.path.join(dummy_git_repo, C.HOOKS_WORKSPACE, repo_installer.sha),
)
@pytest.mark.integration
def test_install_python_repo_in_env(empty_git_dir, python_pre_commit_git_repo):
sha = get_sha(python_pre_commit_git_repo)
install_pre_commit(python_pre_commit_git_repo, sha)
def test_install_python_repo_in_env(python_pre_commit_git_repo, config_for_python_pre_commit_git_repo):
repo_installer = RepoInstaller(config_for_python_pre_commit_git_repo)
# TODO: do we need create here?
repo_installer.install()
assert os.path.exists(os.path.join(python_pre_commit_git_repo, C.PRE_COMMIT_DIR, sha, 'py_env'))
assert os.path.exists(
os.path.join(
python_pre_commit_git_repo,
C.HOOKS_WORKSPACE,
repo_installer.sha,
'py_env',
),
)
@pytest.fixture
@ -34,28 +49,14 @@ def simple_config(python_pre_commit_git_repo):
config = [
{
'repo': python_pre_commit_git_repo,
'sha': get_sha(python_pre_commit_git_repo),
'sha': git.get_head_sha(python_pre_commit_git_repo),
'hooks': [
{
'id': 'foo',
'files': '*.py',
}
},
],
},
]
jsonschema.validate(config, CONFIG_JSON_SCHEMA)
return config
@pytest.mark.integration
def test_install_config(empty_git_dir, python_pre_commit_git_repo, simple_config):
for repo in simple_config:
install_pre_commit(repo['repo'], repo['sha'])
assert os.path.exists(
os.path.join(
python_pre_commit_git_repo,
C.PRE_COMMIT_DIR, simple_config[0]['sha'],
'py_env',
),
)