55from plumbum import local
66from pre_commit import git
77
8+ import pre_commit .constants as C
9+
10+ def add_and_commit ():
11+ local ['git' ]['add' , '.' ]()
12+ local ['git' ]['commit' , '-m' , 'random commit' ]()
13+
14+
15+ def get_sha (git_repo ):
16+ with local .cwd (git_repo ):
17+ return (local ['git' ]['log' , '--format="%H"' ] | local ['head' ]['-n1' ])().strip ('"\n ' )
18+
819
920@pytest .yield_fixture
1021def empty_git_dir (tmpdir ):
@@ -16,11 +27,66 @@ def empty_git_dir(tmpdir):
1627@pytest .yield_fixture
1728def dummy_git_repo (empty_git_dir ):
1829 local ['touch' ]['dummy' ]()
19- local ['git' ]['add' , 'dummy' ]()
20- local ['git' ]['commit' , '-m' , 'dummy commit' ]()
30+ add_and_commit ()
2131
2232 yield empty_git_dir
2333
34+
35+ @pytest .yield_fixture
36+ def dummy_pre_commit_hooks_git_repo (dummy_git_repo ):
37+ local .path (C .MANIFEST_FILE ).write ("""
38+ hooks:
39+ -
40+ id: foo
41+ name: Foo
42+ entry: foo
43+ language: python>2.6
44+ """ )
45+
46+ add_and_commit ()
47+
48+ yield dummy_git_repo
49+
50+ @pytest .yield_fixture
51+ def python_pre_commit_git_repo (dummy_pre_commit_hooks_git_repo ):
52+ local .path ('setup.py' ).write (
53+ """
54+ from setuptools import find_packages
55+ from setuptools import setup
56+
57+ setup(
58+ name='Foo',
59+ version='0.0.0',
60+ packages=find_packages('.'),
61+ entry_points={
62+ 'console_scripts': [
63+ 'entry = foo.main:func'
64+ ],
65+ }
66+ )
67+ """
68+ )
69+
70+ foo_module = local .path ('foo' )
71+
72+ foo_module .mkdir ()
73+
74+ with local .cwd (foo_module ):
75+ local .path ('__init__.py' ).write ('' )
76+ local .path ('main.py' ).write (
77+ """
78+
79+ def func():
80+ return 0
81+
82+ """
83+ )
84+
85+ add_and_commit ()
86+
87+ yield dummy_pre_commit_hooks_git_repo
88+
89+
2490def test_get_root (empty_git_dir ):
2591 assert git .get_root () == empty_git_dir
2692
@@ -52,4 +118,36 @@ def test_remove_pre_commit(empty_git_dir):
52118
53119
54120def test_create_repo_in_env (empty_git_dir , dummy_git_repo ):
55- git .create_repo_in_env ('pre-commit' , dummy_git_repo )
121+ sha = get_sha (dummy_git_repo )
122+ git .create_repo_in_env (dummy_git_repo , sha )
123+ assert os .path .exists (os .path .join (dummy_git_repo , C .PRE_COMMIT_DIR , sha ))
124+
125+
126+ def test_install_python_repo_in_env (empty_git_dir , python_pre_commit_git_repo ):
127+ sha = get_sha (python_pre_commit_git_repo )
128+ git .install_pre_commit (python_pre_commit_git_repo , sha )
129+ assert os .path .exists (os .path .join (python_pre_commit_git_repo , C .PRE_COMMIT_DIR , sha , 'py_env' ))
130+
131+
132+ # def install_config():
133+ # config = [
134+ # {
135+ # 'repo': 'repo1',
136+ # 'sha': 'dsfjksljfslkf',
137+ # 'hooks': [
138+ # {
139+ # 'id': 'script',
140+ # 'args': [
141+ # {
142+ # 'type': 'files',
143+ # 'opt': '*.py'
144+ # },
145+ # ]
146+ # }
147+ # ],
148+ # },
149+ # ]
150+ # for repo in config:
151+ # clone(repo)
152+ # for
153+
0 commit comments