mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Refactor fixtures in tests.
This commit is contained in:
parent
3baefd57e2
commit
85a76617c1
43 changed files with 249 additions and 278 deletions
|
|
@ -1,4 +1,5 @@
|
|||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import argparse
|
||||
import jsonschema
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import sys
|
||||
|
||||
from pre_commit.clientlib.validate_base import get_run_function
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import sys
|
||||
|
||||
from pre_commit.clientlib.validate_base import get_run_function
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import sys
|
||||
|
||||
RED = '\033[41m'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
CONFIG_FILE = '.pre-commit-config.yaml'
|
||||
|
||||
MANIFEST_FILE = 'hooks.yaml'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
"""five: six, redux"""
|
||||
# pylint:disable=invalid-name
|
||||
PY2 = (str is bytes)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import functools
|
||||
import logging
|
||||
import os
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import copy
|
||||
import jsonschema
|
||||
import jsonschema.validators
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from pre_commit.languages import node
|
||||
from pre_commit.languages import python
|
||||
from pre_commit.languages import ruby
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
def run_hook(env, hook, file_args):
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
|
||||
from pre_commit.languages import helpers
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
|
||||
from pre_commit.languages import helpers
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
ENVIRONMENT_DIR = None
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import shlex
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
import sys
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
from asottile.cached_property import cached_property
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import subprocess
|
||||
|
||||
from pre_commit import color
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import os.path
|
||||
import subprocess
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from asottile.cached_property import cached_property
|
||||
from asottile.ordereddict import OrderedDict
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import os.path
|
||||
from asottile.cached_property import cached_property
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import logging
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import functools
|
||||
import os
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import collections
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import jsonschema
|
||||
import os
|
||||
import os.path
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
from asottile.ordereddict import OrderedDict
|
||||
from asottile.yaml import ordered_load
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit.clientlib.validate_manifest import additional_manifest_check
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
import sys
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import pytest
|
||||
import shutil
|
||||
from asottile.ordereddict import OrderedDict
|
||||
from asottile.yaml import ordered_dump
|
||||
from plumbum import local
|
||||
|
||||
import pre_commit.constants as C
|
||||
|
|
@ -14,14 +12,15 @@ from pre_commit.commands.autoupdate import RepositoryCannotBeUpdatedError
|
|||
from pre_commit.runner import Runner
|
||||
from testing.auto_namedtuple import auto_namedtuple
|
||||
from testing.fixtures import make_config_from_repo
|
||||
from testing.fixtures import make_hooks_repo
|
||||
from testing.fixtures import make_repo
|
||||
from testing.fixtures import write_config
|
||||
from testing.util import get_head_sha
|
||||
from testing.util import get_resource_path
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def up_to_date_repo(tmpdir_factory):
|
||||
yield make_hooks_repo(tmpdir_factory, 'python_hooks_repo')
|
||||
yield make_repo(tmpdir_factory, 'python_hooks_repo')
|
||||
|
||||
|
||||
def test_up_to_date_repo(up_to_date_repo, runner_with_mocked_store):
|
||||
|
|
@ -36,8 +35,7 @@ def test_autoupdate_up_to_date_repo(
|
|||
):
|
||||
# Write out the config
|
||||
config = make_config_from_repo(up_to_date_repo, check=False)
|
||||
with io.open(C.CONFIG_FILE, 'w') as config_file:
|
||||
config_file.write(ordered_dump([config], **C.YAML_DUMP_KWARGS))
|
||||
write_config('.', config)
|
||||
|
||||
before = open(C.CONFIG_FILE).read()
|
||||
assert '^$' not in before
|
||||
|
|
@ -50,7 +48,7 @@ def test_autoupdate_up_to_date_repo(
|
|||
|
||||
@pytest.yield_fixture
|
||||
def out_of_date_repo(tmpdir_factory):
|
||||
path = make_hooks_repo(tmpdir_factory, 'python_hooks_repo')
|
||||
path = make_repo(tmpdir_factory, 'python_hooks_repo')
|
||||
original_sha = get_head_sha(path)
|
||||
|
||||
# Make a commit
|
||||
|
|
@ -79,8 +77,7 @@ def test_autoupdate_out_of_date_repo(
|
|||
config = make_config_from_repo(
|
||||
out_of_date_repo.path, sha=out_of_date_repo.original_sha, check=False,
|
||||
)
|
||||
with io.open(C.CONFIG_FILE, 'w') as config_file:
|
||||
config_file.write(ordered_dump([config], **C.YAML_DUMP_KWARGS))
|
||||
write_config('.', config)
|
||||
|
||||
before = open(C.CONFIG_FILE).read()
|
||||
runner = Runner('.')
|
||||
|
|
@ -95,7 +92,7 @@ def test_autoupdate_out_of_date_repo(
|
|||
|
||||
@pytest.yield_fixture
|
||||
def hook_disappearing_repo(tmpdir_factory):
|
||||
path = make_hooks_repo(tmpdir_factory, 'python_hooks_repo')
|
||||
path = make_repo(tmpdir_factory, 'python_hooks_repo')
|
||||
original_sha = get_head_sha(path)
|
||||
|
||||
with local.cwd(path):
|
||||
|
|
@ -130,8 +127,7 @@ def test_autoupdate_hook_disappearing_repo(
|
|||
hooks=[OrderedDict((('id', 'foo'),))],
|
||||
check=False,
|
||||
)
|
||||
with io.open(C.CONFIG_FILE, 'w') as config_file:
|
||||
config_file.write(ordered_dump([config], **C.YAML_DUMP_KWARGS))
|
||||
write_config('.', config)
|
||||
|
||||
before = open(C.CONFIG_FILE).read()
|
||||
runner = Runner('.')
|
||||
|
|
|
|||
|
|
@ -11,6 +11,21 @@ from pre_commit.commands.run import _has_unmerged_paths
|
|||
from pre_commit.commands.run import run
|
||||
from pre_commit.runner import Runner
|
||||
from testing.auto_namedtuple import auto_namedtuple
|
||||
from testing.fixtures import make_consuming_repo
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def repo_with_passing_hook(tmpdir_factory):
|
||||
git_path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
with local.cwd(git_path):
|
||||
yield git_path
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def repo_with_failing_hook(tmpdir_factory):
|
||||
git_path = make_consuming_repo(tmpdir_factory, 'failing_hook_repo')
|
||||
with local.cwd(git_path):
|
||||
yield git_path
|
||||
|
||||
|
||||
def stage_a_file():
|
||||
|
|
|
|||
|
|
@ -1,26 +1,19 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import mock
|
||||
import os
|
||||
import os.path
|
||||
import pytest
|
||||
import time
|
||||
import yaml
|
||||
from plumbum import local
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit import five
|
||||
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
||||
from pre_commit.clientlib.validate_config import validate_config_extra
|
||||
from pre_commit.jsonschema_extensions import apply_defaults
|
||||
from pre_commit.prefixed_command_runner import PrefixedCommandRunner
|
||||
from pre_commit.runner import Runner
|
||||
from pre_commit.store import Store
|
||||
from testing.fixtures import git_dir
|
||||
from testing.util import copy_tree_to_path
|
||||
from testing.util import get_head_sha
|
||||
from testing.util import get_resource_path
|
||||
from testing.fixtures import make_consuming_repo
|
||||
|
||||
|
||||
git = local['git']
|
||||
|
|
@ -48,194 +41,36 @@ def in_tmpdir(tmpdir_factory):
|
|||
yield path
|
||||
|
||||
|
||||
def add_and_commit():
|
||||
git('add', '.')
|
||||
git('commit', '-m', 'random commit {0}'.format(time.time()))
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def dummy_git_repo(tmpdir_factory):
|
||||
path = git_dir(tmpdir_factory)
|
||||
def in_merge_conflict(tmpdir_factory):
|
||||
path = make_consuming_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
with local.cwd(path):
|
||||
# This is needed otherwise there is no `HEAD`
|
||||
local['touch']('dummy')
|
||||
add_and_commit()
|
||||
yield path
|
||||
|
||||
|
||||
def _make_repo(repo_path, repo_source):
|
||||
copy_tree_to_path(get_resource_path(repo_source), repo_path)
|
||||
add_and_commit()
|
||||
return repo_path
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def python_hooks_repo(dummy_git_repo):
|
||||
yield _make_repo(dummy_git_repo, 'python_hooks_repo')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def python3_hooks_repo(dummy_git_repo):
|
||||
yield _make_repo(dummy_git_repo, 'python3_hooks_repo')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def node_hooks_repo(dummy_git_repo):
|
||||
yield _make_repo(dummy_git_repo, 'node_hooks_repo')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def node_0_11_8_hooks_repo(dummy_git_repo):
|
||||
yield _make_repo(dummy_git_repo, 'node_0_11_8_hooks_repo')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def ruby_hooks_repo(dummy_git_repo):
|
||||
yield _make_repo(dummy_git_repo, 'ruby_hooks_repo')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def ruby_1_9_3_hooks_repo(dummy_git_repo):
|
||||
yield _make_repo(dummy_git_repo, 'ruby_1_9_3_hooks_repo')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def consumer_repo(dummy_git_repo):
|
||||
yield _make_repo(dummy_git_repo, 'consumer_repo')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def prints_cwd_repo(dummy_git_repo):
|
||||
yield _make_repo(dummy_git_repo, 'prints_cwd_repo')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def script_hooks_repo(dummy_git_repo):
|
||||
yield _make_repo(dummy_git_repo, 'script_hooks_repo')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def failing_hook_repo(dummy_git_repo):
|
||||
yield _make_repo(dummy_git_repo, 'failing_hook_repo')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def system_hook_with_spaces_repo(dummy_git_repo):
|
||||
yield _make_repo(dummy_git_repo, 'system_hook_with_spaces_repo')
|
||||
|
||||
|
||||
def _make_config(path, hook_id):
|
||||
config = {
|
||||
'repo': path,
|
||||
'sha': get_head_sha(path),
|
||||
'hooks': [{'id': hook_id}],
|
||||
}
|
||||
config_wrapped = apply_defaults([config], CONFIG_JSON_SCHEMA)
|
||||
validate_config_extra(config_wrapped)
|
||||
return config_wrapped[0]
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_node_hooks_repo(node_hooks_repo):
|
||||
yield _make_config(node_hooks_repo, 'foo')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_node_0_11_8_hooks_repo(node_0_11_8_hooks_repo):
|
||||
yield _make_config(node_0_11_8_hooks_repo, 'node-11-8-hook')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_ruby_hooks_repo(ruby_hooks_repo):
|
||||
yield _make_config(ruby_hooks_repo, 'ruby_hook')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_ruby_1_9_3_hooks_repo(ruby_1_9_3_hooks_repo):
|
||||
yield _make_config(ruby_1_9_3_hooks_repo, 'ruby_hook')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_python_hooks_repo(python_hooks_repo):
|
||||
yield _make_config(python_hooks_repo, 'foo')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_python3_hooks_repo(python3_hooks_repo):
|
||||
yield _make_config(python3_hooks_repo, 'python3-hook')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_prints_cwd_repo(prints_cwd_repo):
|
||||
yield _make_config(prints_cwd_repo, 'prints_cwd')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_script_hooks_repo(script_hooks_repo):
|
||||
yield _make_config(script_hooks_repo, 'bash_hook')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_system_hook_with_spaces(system_hook_with_spaces_repo):
|
||||
yield _make_config(
|
||||
system_hook_with_spaces_repo, 'system-hook-with-spaces',
|
||||
)
|
||||
|
||||
|
||||
def _make_repo_from_configs(*configs):
|
||||
with open(C.CONFIG_FILE, 'w') as config_file:
|
||||
yaml.dump(
|
||||
configs,
|
||||
stream=config_file,
|
||||
Dumper=yaml.SafeDumper,
|
||||
**C.YAML_DUMP_KWARGS
|
||||
)
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def repo_with_passing_hook(config_for_script_hooks_repo, tmpdir_factory):
|
||||
path = git_dir(tmpdir_factory)
|
||||
with local.cwd(path):
|
||||
_make_repo_from_configs(config_for_script_hooks_repo)
|
||||
yield path
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def repo_with_failing_hook(failing_hook_repo, tmpdir_factory):
|
||||
path = git_dir(tmpdir_factory)
|
||||
with local.cwd(path):
|
||||
_make_repo_from_configs(
|
||||
_make_config(failing_hook_repo, 'failing_hook')
|
||||
)
|
||||
yield path
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def in_merge_conflict(repo_with_passing_hook):
|
||||
local['touch']('dummy')
|
||||
git('add', 'dummy')
|
||||
git('add', C.CONFIG_FILE)
|
||||
git('commit', '-m' 'add hooks file')
|
||||
git('clone', '.', 'foo')
|
||||
with local.cwd('foo'):
|
||||
git('commit', '-m', 'Add config.')
|
||||
|
||||
conflict_path = tmpdir_factory.get()
|
||||
git('clone', path, conflict_path)
|
||||
with local.cwd(conflict_path):
|
||||
git('checkout', 'origin/master', '-b', 'foo')
|
||||
with open('conflict_file', 'w') as conflict_file:
|
||||
with io.open('conflict_file', 'w') as conflict_file:
|
||||
conflict_file.write('herp\nderp\n')
|
||||
git('add', 'conflict_file')
|
||||
with open('foo_only_file', 'w') as foo_only_file:
|
||||
with io.open('foo_only_file', 'w') as foo_only_file:
|
||||
foo_only_file.write('foo')
|
||||
git('add', 'foo_only_file')
|
||||
git('commit', '-m', 'conflict_file')
|
||||
git('checkout', 'origin/master', '-b', 'bar')
|
||||
with open('conflict_file', 'w') as conflict_file:
|
||||
with io.open('conflict_file', 'w') as conflict_file:
|
||||
conflict_file.write('harp\nddrp\n')
|
||||
git('add', 'conflict_file')
|
||||
with open('bar_only_file', 'w') as bar_only_file:
|
||||
with io.open('bar_only_file', 'w') as bar_only_file:
|
||||
bar_only_file.write('bar')
|
||||
git('add', 'bar_only_file')
|
||||
git('commit', '-m', 'conflict_file')
|
||||
git('merge', 'foo', retcode=None)
|
||||
yield os.path.join(repo_with_passing_hook, 'foo')
|
||||
yield os.path.join(conflict_path)
|
||||
|
||||
|
||||
@pytest.yield_fixture(scope='session', autouse=True)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import pytest
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import jsonschema.exceptions
|
||||
import pytest
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit.languages.all import all_languages
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
|
||||
from pre_commit.languages.ruby import _install_rbenv
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import mock
|
||||
|
||||
from pre_commit import color
|
||||
|
|
|
|||
|
|
@ -1,13 +1,18 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit.manifest import Manifest
|
||||
from testing.fixtures import make_repo
|
||||
from testing.util import get_head_sha
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def manifest(store, script_hooks_repo):
|
||||
head_sha = get_head_sha(script_hooks_repo)
|
||||
repo_path_getter = store.get_repo_path_getter(script_hooks_repo, head_sha)
|
||||
def manifest(store, tmpdir_factory):
|
||||
path = make_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
head_sha = get_head_sha(path)
|
||||
repo_path_getter = store.get_repo_path_getter(path, head_sha)
|
||||
yield Manifest(repo_path_getter)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit import color
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import mock
|
||||
import pytest
|
||||
|
|
@ -9,7 +11,9 @@ from pre_commit.prefixed_command_runner import PrefixedCommandRunner
|
|||
|
||||
|
||||
def test_CalledProcessError_str():
|
||||
error = CalledProcessError(1, ['git', 'status'], 0, ('stdout', 'stderr'))
|
||||
error = CalledProcessError(
|
||||
1, [str('git'), str('status')], 0, (str('stdout'), str('stderr'))
|
||||
)
|
||||
assert str(error) == (
|
||||
"Command: ['git', 'status']\n"
|
||||
"Return code: 1\n"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import mock
|
||||
import os.path
|
||||
import pytest
|
||||
from plumbum import local
|
||||
|
|
@ -6,101 +10,115 @@ from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
|||
from pre_commit.clientlib.validate_config import validate_config_extra
|
||||
from pre_commit.jsonschema_extensions import apply_defaults
|
||||
from pre_commit.repository import Repository
|
||||
from testing.fixtures import git_dir
|
||||
from testing.fixtures import make_config_from_repo
|
||||
from testing.fixtures import make_repo
|
||||
from testing.util import skipif_slowtests_false
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_install_python_repo_in_env(config_for_python_hooks_repo, store):
|
||||
repo = Repository.create(config_for_python_hooks_repo, store)
|
||||
def test_install_python_repo_in_env(tmpdir_factory, store):
|
||||
path = make_repo(tmpdir_factory, 'python_hooks_repo')
|
||||
config = make_config_from_repo(path)
|
||||
repo = Repository.create(config, store)
|
||||
repo.install()
|
||||
assert os.path.exists(os.path.join(store.directory, repo.sha, 'py_env'))
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_run_a_python_hook(config_for_python_hooks_repo, store):
|
||||
repo = Repository.create(config_for_python_hooks_repo, store)
|
||||
ret = repo.run_hook('foo', ['/dev/null'])
|
||||
def _test_hook_repo(tmpdir_factory, store, repo_path, hook_id, args, expected):
|
||||
path = make_repo(tmpdir_factory, repo_path)
|
||||
config = make_config_from_repo(path)
|
||||
repo = Repository.create(config, store)
|
||||
ret = repo.run_hook(hook_id, args)
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == "['/dev/null']\nHello World\n"
|
||||
assert ret[1] == expected
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_run_versioned_hook(config_for_python3_hooks_repo, store):
|
||||
repo = Repository.create(config_for_python3_hooks_repo, store)
|
||||
ret = repo.run_hook('python3-hook', ['/dev/null'])
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == "3.3\n['/dev/null']\nHello World\n"
|
||||
def test_python_hook(tmpdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'python_hooks_repo',
|
||||
'foo', ['/dev/null'], "['/dev/null']\nHello World\n",
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_versioned_python_hook(tmpdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'python3_hooks_repo',
|
||||
'python3-hook', ['/dev/null'], "3.3\n['/dev/null']\nHello World\n",
|
||||
)
|
||||
|
||||
|
||||
@skipif_slowtests_false
|
||||
@pytest.mark.integration
|
||||
def test_run_versioned_node_hook(config_for_node_0_11_8_hooks_repo, store):
|
||||
repo = Repository.create(config_for_node_0_11_8_hooks_repo, store)
|
||||
ret = repo.run_hook('node-11-8-hook', ['/dev/null'])
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == 'v0.11.8\nHello World\n'
|
||||
def test_run_a_node_hook(tmpdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'node_hooks_repo',
|
||||
'foo', [], 'Hello World\n',
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.herpderp
|
||||
@skipif_slowtests_false
|
||||
@pytest.mark.integration
|
||||
def test_run_versioned_ruby_hook(config_for_ruby_1_9_3_hooks_repo, store):
|
||||
repo = Repository.create(config_for_ruby_1_9_3_hooks_repo, store)
|
||||
ret = repo.run_hook('ruby_hook', [])
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == '1.9.3\n484\nHello world from a ruby hook\n'
|
||||
def test_run_versioned_node_hook(tmpdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'node_0_11_8_hooks_repo',
|
||||
'node-11-8-hook', ['/dev/null'], 'v0.11.8\nHello World\n',
|
||||
)
|
||||
|
||||
|
||||
@skipif_slowtests_false
|
||||
@pytest.mark.integration
|
||||
def test_run_a_ruby_hook(tmpdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'ruby_hooks_repo',
|
||||
'ruby_hook', [], 'Hello world from a ruby hook\n',
|
||||
)
|
||||
|
||||
|
||||
@skipif_slowtests_false
|
||||
@pytest.mark.integration
|
||||
def test_run_versioned_ruby_hook(tmpdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'ruby_1_9_3_hooks_repo',
|
||||
'ruby_hook', [], '1.9.3\n484\nHello world from a ruby hook\n',
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_lots_of_files(config_for_python_hooks_repo, store):
|
||||
repo = Repository.create(config_for_python_hooks_repo, store)
|
||||
ret = repo.run_hook('foo', ['/dev/null'] * 15000)
|
||||
assert ret[0] == 0
|
||||
def test_system_hook_with_spaces(tmpdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'system_hook_with_spaces_repo',
|
||||
'system-hook-with-spaces', [], 'Hello World\n',
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_cwd_of_hook(config_for_prints_cwd_repo, store):
|
||||
def test_run_a_script_hook(tmpdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'script_hooks_repo',
|
||||
'bash_hook', ['bar'], 'bar\nHello World\n',
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_cwd_of_hook(tmpdir_factory, store):
|
||||
# Note: this doubles as a test for `system` hooks
|
||||
repo = Repository.create(config_for_prints_cwd_repo, store)
|
||||
ret = repo.run_hook('prints_cwd', [])
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == repo.repo_url + '\n'
|
||||
path = git_dir(tmpdir_factory)
|
||||
with local.cwd(path):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'prints_cwd_repo',
|
||||
'prints_cwd', [], path + '\n',
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_system_hook_with_spaces(config_for_system_hook_with_spaces, store):
|
||||
repo = Repository.create(config_for_system_hook_with_spaces, store)
|
||||
ret = repo.run_hook('system-hook-with-spaces', [])
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == 'Hello World\n'
|
||||
|
||||
|
||||
@skipif_slowtests_false
|
||||
@pytest.mark.integration
|
||||
def test_run_a_node_hook(config_for_node_hooks_repo, store):
|
||||
repo = Repository.create(config_for_node_hooks_repo, store)
|
||||
ret = repo.run_hook('foo', [])
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == 'Hello World\n'
|
||||
|
||||
|
||||
@pytest.mark.herpderp
|
||||
@skipif_slowtests_false
|
||||
@pytest.mark.integration
|
||||
def test_run_a_ruby_hook(config_for_ruby_hooks_repo, store):
|
||||
repo = Repository.create(config_for_ruby_hooks_repo, store)
|
||||
ret = repo.run_hook('ruby_hook', [])
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == 'Hello world from a ruby hook\n'
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_run_a_script_hook(config_for_script_hooks_repo, store):
|
||||
repo = Repository.create(config_for_script_hooks_repo, store)
|
||||
ret = repo.run_hook('bash_hook', ['bar'])
|
||||
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == 'bar\nHello World\n'
|
||||
def test_lots_of_files(tmpdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tmpdir_factory, store, 'script_hooks_repo',
|
||||
'bash_hook', ['/dev/null'] * 15000, mock.ANY,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -129,37 +147,49 @@ def test_sha(mock_repo_config):
|
|||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_languages(config_for_python_hooks_repo, store):
|
||||
repo = Repository.create(config_for_python_hooks_repo, store)
|
||||
def test_languages(tmpdir_factory, store):
|
||||
path = make_repo(tmpdir_factory, 'python_hooks_repo')
|
||||
config = make_config_from_repo(path)
|
||||
repo = Repository.create(config, store)
|
||||
assert repo.languages == set([('python', 'default')])
|
||||
|
||||
|
||||
def test_reinstall(config_for_python_hooks_repo, store):
|
||||
repo = Repository.create(config_for_python_hooks_repo, store)
|
||||
def test_reinstall(tmpdir_factory, store):
|
||||
path = make_repo(tmpdir_factory, 'python_hooks_repo')
|
||||
config = make_config_from_repo(path)
|
||||
repo = Repository.create(config, store)
|
||||
repo.require_installed()
|
||||
# Reinstall with same repo should not trigger another install
|
||||
# TODO: how to assert this?
|
||||
repo.require_installed()
|
||||
# Reinstall on another run should not trigger another install
|
||||
# TODO: how to assert this?
|
||||
repo = Repository.create(config_for_python_hooks_repo, store)
|
||||
repo = Repository.create(config, store)
|
||||
repo.require_installed()
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_really_long_file_paths(config_for_python_hooks_repo, store):
|
||||
path = 'really_long' * 10
|
||||
local['git']('init', path)
|
||||
with local.cwd(path):
|
||||
repo = Repository.create(config_for_python_hooks_repo, store)
|
||||
def test_really_long_file_paths(tmpdir_factory, store):
|
||||
base_path = tmpdir_factory.get()
|
||||
really_long_path = os.path.join(base_path, 'really_long' * 10)
|
||||
local['git']('init', really_long_path)
|
||||
|
||||
path = make_repo(tmpdir_factory, 'python_hooks_repo')
|
||||
config = make_config_from_repo(path)
|
||||
|
||||
with local.cwd(really_long_path):
|
||||
repo = Repository.create(config, store)
|
||||
repo.require_installed()
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_config_overrides_repo_specifics(config_for_script_hooks_repo, store):
|
||||
repo = Repository.create(config_for_script_hooks_repo, store)
|
||||
def test_config_overrides_repo_specifics(tmpdir_factory, store):
|
||||
path = make_repo(tmpdir_factory, 'script_hooks_repo')
|
||||
config = make_config_from_repo(path)
|
||||
|
||||
repo = Repository.create(config, store)
|
||||
assert repo.hooks['bash_hook']['files'] == ''
|
||||
# Set the file regex to something else
|
||||
config_for_script_hooks_repo['hooks'][0]['files'] = '\\.sh$'
|
||||
repo = Repository.create(config_for_script_hooks_repo, store)
|
||||
config['hooks'][0]['files'] = '\\.sh$'
|
||||
repo = Repository.create(config, store)
|
||||
assert repo.hooks['bash_hook']['files'] == '\\.sh$'
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from plumbum import local
|
|||
import pre_commit.constants as C
|
||||
from pre_commit.runner import Runner
|
||||
from testing.fixtures import git_dir
|
||||
from testing.fixtures import make_repo
|
||||
|
||||
|
||||
def test_init_has_no_side_effects(tmpdir):
|
||||
|
|
@ -45,9 +46,10 @@ def test_config_file_path():
|
|||
assert runner.config_file_path == expected_path
|
||||
|
||||
|
||||
def test_repositories(consumer_repo, mock_out_store_directory):
|
||||
def test_repositories(tmpdir_factory, mock_out_store_directory):
|
||||
# TODO: make this not have external deps
|
||||
runner = Runner(consumer_repo)
|
||||
path = make_repo(tmpdir_factory, 'consumer_repo')
|
||||
runner = Runner(path)
|
||||
assert len(runner.repositories) == 2
|
||||
assert [repo.repo_url for repo in runner.repositories] == [
|
||||
'git@github.com:pre-commit/pre-commit-hooks',
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
import os
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue