22
33import jsonschema
44import pytest
5- from plumbum import local
5+ from pre_commit import git
66
77import pre_commit .constants as C
88from pre_commit .clientlib .validate_config import CONFIG_JSON_SCHEMA
9- from pre_commit .repo_installer import create_repo_in_env
10- from pre_commit .repo_installer import install_pre_commit
9+ from pre_commit .repo_installer import RepoInstaller
1110
1211
13- def get_sha (git_repo ):
14- with local .cwd (git_repo ):
15- return (local ['git' ]['log' , '--format="%H"' ] | local ['head' ]['-n1' ])().strip ('"\n ' )
12+ @pytest .fixture
13+ def dummy_repo_config (dummy_git_repo ):
14+ # This is not a valid config, but it is pretty close
15+ return {
16+ 'repo' : dummy_git_repo ,
17+ 'sha' : git .get_head_sha (dummy_git_repo ),
18+ 'hooks' : [],
19+ }
20+
1621
1722@pytest .mark .integration
18- def test_create_repo_in_env (empty_git_dir , dummy_git_repo ):
19- sha = get_sha ( dummy_git_repo )
20- create_repo_in_env ( dummy_git_repo , sha )
23+ def test_create_repo_in_env (dummy_repo_config , dummy_git_repo ):
24+ repo_installer = RepoInstaller ( dummy_repo_config )
25+ repo_installer . create ( )
2126
22- assert os .path .exists (os .path .join (dummy_git_repo , C .PRE_COMMIT_DIR , sha ))
27+ assert os .path .exists (
28+ os .path .join (dummy_git_repo , C .HOOKS_WORKSPACE , repo_installer .sha ),
29+ )
2330
2431@pytest .mark .integration
25- def test_install_python_repo_in_env (empty_git_dir , python_pre_commit_git_repo ):
26- sha = get_sha (python_pre_commit_git_repo )
27- install_pre_commit (python_pre_commit_git_repo , sha )
32+ def test_install_python_repo_in_env (python_pre_commit_git_repo , config_for_python_pre_commit_git_repo ):
33+ repo_installer = RepoInstaller (config_for_python_pre_commit_git_repo )
34+ # TODO: do we need create here?
35+ repo_installer .install ()
2836
29- assert os .path .exists (os .path .join (python_pre_commit_git_repo , C .PRE_COMMIT_DIR , sha , 'py_env' ))
37+ assert os .path .exists (
38+ os .path .join (
39+ python_pre_commit_git_repo ,
40+ C .HOOKS_WORKSPACE ,
41+ repo_installer .sha ,
42+ 'py_env' ,
43+ ),
44+ )
3045
3146
3247@pytest .fixture
3348def simple_config (python_pre_commit_git_repo ):
3449 config = [
3550 {
3651 'repo' : python_pre_commit_git_repo ,
37- 'sha' : get_sha (python_pre_commit_git_repo ),
52+ 'sha' : git . get_head_sha (python_pre_commit_git_repo ),
3853 'hooks' : [
3954 {
4055 'id' : 'foo' ,
4156 'files' : '*.py' ,
42- }
57+ },
4358 ],
4459 },
4560 ]
4661 jsonschema .validate (config , CONFIG_JSON_SCHEMA )
4762 return config
48-
49-
50- @pytest .mark .integration
51- def test_install_config (empty_git_dir , python_pre_commit_git_repo , simple_config ):
52- for repo in simple_config :
53- install_pre_commit (repo ['repo' ], repo ['sha' ])
54-
55- assert os .path .exists (
56- os .path .join (
57- python_pre_commit_git_repo ,
58- C .PRE_COMMIT_DIR , simple_config [0 ]['sha' ],
59- 'py_env' ,
60- ),
61- )
0 commit comments