Refactor fixtures in tests.

This commit is contained in:
Anthony Sottile 2014-06-15 18:48:43 -07:00
parent 3baefd57e2
commit 85a76617c1
43 changed files with 249 additions and 278 deletions

View file

@ -1,3 +1,5 @@
from __future__ import unicode_literals
import collections

View file

@ -1,8 +1,10 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import io
import os.path
from asottile.ordereddict import OrderedDict
from asottile.yaml import ordered_dump
from plumbum import local
import pre_commit.constants as C
@ -25,7 +27,7 @@ def git_dir(tmpdir_factory):
return path
def make_hooks_repo(tmpdir_factory, repo_source):
def make_repo(tmpdir_factory, repo_source):
path = git_dir(tmpdir_factory)
copy_tree_to_path(get_resource_path(repo_source), path)
with local.cwd(path):
@ -51,3 +53,17 @@ def make_config_from_repo(repo_path, sha=None, hooks=None, check=True):
return wrapped_config[0]
else:
return config
def write_config(directory, config):
assert type(config) is OrderedDict
with io.open(os.path.join(directory, C.CONFIG_FILE), 'w') as config_file:
config_file.write(ordered_dump([config], **C.YAML_DUMP_KWARGS))
def make_consuming_repo(tmpdir_factory, repo_source):
path = make_repo(tmpdir_factory, repo_source)
config = make_config_from_repo(path)
git_path = git_dir(tmpdir_factory)
write_config(git_path, config)
return git_path

View file

@ -1,3 +1,5 @@
from __future__ import unicode_literals
import jsonschema
import os
import os.path