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

@ -1,8 +1,14 @@
from __future__ import absolute_import
import jsonschema
import pytest
import pre_commit.constants as C
import time
from plumbum import local
import pre_commit.constants as C
from pre_commit import git
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
@pytest.yield_fixture
def empty_git_dir(tmpdir):
@ -11,10 +17,9 @@ def empty_git_dir(tmpdir):
yield tmpdir.strpath
def add_and_commit():
local['git']['add', '.']()
local['git']['commit', '-m', 'random commit']()
local['git']['commit', '-m', 'random commit {0}'.format(time.time())]()
@pytest.yield_fixture
@ -42,8 +47,7 @@ hooks:
@pytest.yield_fixture
def python_pre_commit_git_repo(dummy_pre_commit_hooks_git_repo):
local.path('setup.py').write(
"""
local.path('setup.py').write("""
from setuptools import find_packages
from setuptools import setup
@ -53,7 +57,7 @@ setup(
packages=find_packages('.'),
entry_points={
'console_scripts': [
'entry = foo.main:func'
'foo = foo.main:func'
],
}
)
@ -66,15 +70,28 @@ setup(
with local.cwd(foo_module):
local.path('__init__.py').write('')
local.path('main.py').write(
"""
local.path('main.py').write("""
def func():
return 0
"""
)
add_and_commit()
yield dummy_pre_commit_hooks_git_repo
@pytest.fixture
def config_for_python_pre_commit_git_repo(python_pre_commit_git_repo):
config = {
'repo': 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