added more integration with git repo creation

This commit is contained in:
Ken Struys 2014-03-13 16:29:59 -07:00
parent ed16271a19
commit 6498321e1e
2 changed files with 142 additions and 12 deletions

View file

@ -5,6 +5,17 @@ import pytest
from plumbum import local
from pre_commit import git
import pre_commit.constants as C
def add_and_commit():
local['git']['add', '.']()
local['git']['commit', '-m', 'random commit']()
def get_sha(git_repo):
with local.cwd(git_repo):
return (local['git']['log', '--format="%H"'] | local['head']['-n1'])().strip('"\n')
@pytest.yield_fixture
def empty_git_dir(tmpdir):
@ -16,11 +27,66 @@ def empty_git_dir(tmpdir):
@pytest.yield_fixture
def dummy_git_repo(empty_git_dir):
local['touch']['dummy']()
local['git']['add', 'dummy']()
local['git']['commit', '-m', 'dummy commit']()
add_and_commit()
yield empty_git_dir
@pytest.yield_fixture
def dummy_pre_commit_hooks_git_repo(dummy_git_repo):
local.path(C.MANIFEST_FILE).write("""
hooks:
-
id: foo
name: Foo
entry: foo
language: python>2.6
""")
add_and_commit()
yield dummy_git_repo
@pytest.yield_fixture
def python_pre_commit_git_repo(dummy_pre_commit_hooks_git_repo):
local.path('setup.py').write(
"""
from setuptools import find_packages
from setuptools import setup
setup(
name='Foo',
version='0.0.0',
packages=find_packages('.'),
entry_points={
'console_scripts': [
'entry = foo.main:func'
],
}
)
"""
)
foo_module = local.path('foo')
foo_module.mkdir()
with local.cwd(foo_module):
local.path('__init__.py').write('')
local.path('main.py').write(
"""
def func():
return 0
"""
)
add_and_commit()
yield dummy_pre_commit_hooks_git_repo
def test_get_root(empty_git_dir):
assert git.get_root() == empty_git_dir
@ -52,4 +118,36 @@ def test_remove_pre_commit(empty_git_dir):
def test_create_repo_in_env(empty_git_dir, dummy_git_repo):
git.create_repo_in_env('pre-commit', dummy_git_repo)
sha = get_sha(dummy_git_repo)
git.create_repo_in_env(dummy_git_repo, sha)
assert os.path.exists(os.path.join(dummy_git_repo, C.PRE_COMMIT_DIR, sha))
def test_install_python_repo_in_env(empty_git_dir, python_pre_commit_git_repo):
sha = get_sha(python_pre_commit_git_repo)
git.install_pre_commit(python_pre_commit_git_repo, sha)
assert os.path.exists(os.path.join(python_pre_commit_git_repo, C.PRE_COMMIT_DIR, sha, 'py_env'))
# def install_config():
# config = [
# {
# 'repo': 'repo1',
# 'sha': 'dsfjksljfslkf',
# 'hooks': [
# {
# 'id': 'script',
# 'args': [
# {
# 'type': 'files',
# 'opt': '*.py'
# },
# ]
# }
# ],
# },
# ]
# for repo in config:
# clone(repo)
# for