Convert autoupdate_test to use new fixture functions. · pre-commit/pre-commit@3baefd5 · GitHub
Skip to content

Commit 3baefd5

Browse files
committed
Convert autoupdate_test to use new fixture functions.
1 parent 047a933 commit 3baefd5

3 files changed

Lines changed: 108 additions & 85 deletions

File tree

‎pre_commit/constants.py‎

Lines changed: 2 additions & 0 deletions

‎testing/fixtures.py‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
from __future__ import absolute_import
22
from __future__ import unicode_literals
33

4+
import os.path
5+
from asottile.ordereddict import OrderedDict
46
from plumbum import local
57

8+
import pre_commit.constants as C
9+
from pre_commit.clientlib.validate_manifest import load_manifest
10+
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
11+
from pre_commit.clientlib.validate_config import validate_config_extra
12+
from pre_commit.jsonschema_extensions import apply_defaults
13+
from testing.util import copy_tree_to_path
14+
from testing.util import get_head_sha
15+
from testing.util import get_resource_path
16+
617

718
git = local['git']
819

@@ -12,3 +23,31 @@ def git_dir(tmpdir_factory):
1223
with local.cwd(path):
1324
git('init')
1425
return path
26+
27+
28+
def make_hooks_repo(tmpdir_factory, repo_source):
29+
path = git_dir(tmpdir_factory)
30+
copy_tree_to_path(get_resource_path(repo_source), path)
31+
with local.cwd(path):
32+
git('add', '.')
33+
git('commit', '-m', 'Add hooks')
34+
return path
35+
36+
37+
def make_config_from_repo(repo_path, sha=None, hooks=None, check=True):
38+
manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE))
39+
config = OrderedDict((
40+
('repo', repo_path),
41+
('sha', sha or get_head_sha(repo_path)),
42+
(
43+
'hooks',
44+
hooks or [OrderedDict((('id', hook['id']),)) for hook in manifest],
45+
),
46+
))
47+
48+
if check:
49+
wrapped_config = apply_defaults([config], CONFIG_JSON_SCHEMA)
50+
validate_config_extra(wrapped_config)
51+
return wrapped_config[0]
52+
else:
53+
return config

‎tests/commands/autoupdate_test.py‎

Lines changed: 67 additions & 85 deletions

0 commit comments

Comments
 (0)