Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions testing/resources/manifest_without_foo.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions testing/resources/valid_yaml_but_invalid_config.yaml

This file was deleted.

1 change: 0 additions & 1 deletion testing/resources/valid_yaml_but_invalid_manifest.yaml

This file was deleted.

83 changes: 27 additions & 56 deletions tests/clientlib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from pre_commit.clientlib import validate_config_main
from pre_commit.clientlib import validate_manifest_main
from testing.fixtures import sample_local_config
from testing.util import get_resource_path


def is_valid_according_to_schema(obj, obj_schema):
Expand All @@ -30,19 +29,6 @@ def test_check_type_tag_failures(value):
check_type_tag(value)


@pytest.mark.parametrize(
('args', 'expected_output'),
(
(['.pre-commit-config.yaml'], 0),
(['non_existent_file.yaml'], 1),
([get_resource_path('valid_yaml_but_invalid_config.yaml')], 1),
([get_resource_path('non_parseable_yaml_file.notyaml')], 1),
),
)
def test_validate_config_main(args, expected_output):
assert validate_config_main(args) == expected_output


@pytest.mark.parametrize(
('config_obj', 'expected'), (
(
Expand Down Expand Up @@ -91,39 +77,13 @@ def test_config_valid(config_obj, expected):


def test_local_hooks_with_rev_fails():
config_obj = {'repos': [sample_local_config()]}
config_obj['repos'][0]['rev'] = 'foo'
config_obj = {'repos': [dict(sample_local_config(), rev='foo')]}
with pytest.raises(cfgv.ValidationError):
cfgv.validate(config_obj, CONFIG_SCHEMA)


@pytest.mark.parametrize(
'config_obj', (
{'repos': [{
'repo': 'local',
'hooks': [{
'id': 'arg-per-line',
'name': 'Args per line hook',
'entry': 'bin/hook.sh',
'language': 'script',
'files': '',
'args': ['hello', 'world'],
}],
}]},
{'repos': [{
'repo': 'local',
'hooks': [{
'id': 'arg-per-line',
'name': 'Args per line hook',
'entry': 'bin/hook.sh',
'language': 'script',
'files': '',
'args': ['hello', 'world'],
}],
}]},
),
)
def test_config_with_local_hooks_definition_passes(config_obj):
def test_config_with_local_hooks_definition_passes():
config_obj = {'repos': [sample_local_config()]}
cfgv.validate(config_obj, CONFIG_SCHEMA)


Expand All @@ -135,17 +95,30 @@ def test_config_schema_does_not_contain_defaults():
assert not isinstance(item, cfgv.Optional)


@pytest.mark.parametrize(
('args', 'expected_output'),
(
(['.pre-commit-hooks.yaml'], 0),
(['non_existent_file.yaml'], 1),
([get_resource_path('valid_yaml_but_invalid_manifest.yaml')], 1),
([get_resource_path('non_parseable_yaml_file.notyaml')], 1),
),
)
def test_validate_manifest_main(args, expected_output):
assert validate_manifest_main(args) == expected_output
def test_validate_manifest_main_ok():
assert not validate_manifest_main(('.pre-commit-hooks.yaml',))


def test_validate_config_main_ok():
assert not validate_config_main(('.pre-commit-config.yaml',))


def test_validate_config_old_list_format_ok(tmpdir):
f = tmpdir.join('cfg.yaml')
f.write('- {repo: meta, hooks: [{id: identity}]}')
assert not validate_config_main((f.strpath,))


@pytest.mark.parametrize('fn', (validate_config_main, validate_manifest_main))
def test_mains_not_ok(tmpdir, fn):
not_yaml = tmpdir.join('f.notyaml')
not_yaml.write('{')
not_schema = tmpdir.join('notconfig.yaml')
not_schema.write('{}')

assert fn(('does-not-exist',))
assert fn((not_yaml.strpath,))
assert fn((not_schema.strpath,))


@pytest.mark.parametrize(
Expand Down Expand Up @@ -174,8 +147,6 @@ def test_validate_manifest_main(args, expected_output):
),
(
# A regression in 0.13.5: always_run and files are permissible
# together (but meaningless). In a future version upgrade this to
# an error
[{
'id': 'a',
'name': 'b',
Expand Down
12 changes: 3 additions & 9 deletions tests/commands/autoupdate_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from __future__ import unicode_literals

import os.path
import pipes
import shutil

import pytest

Expand All @@ -16,10 +14,10 @@
from testing.fixtures import add_config_to_repo
from testing.fixtures import make_config_from_repo
from testing.fixtures import make_repo
from testing.fixtures import modify_manifest
from testing.fixtures import read_config
from testing.fixtures import sample_local_config
from testing.fixtures import write_config
from testing.util import get_resource_path
from testing.util import git_commit


Expand Down Expand Up @@ -275,12 +273,8 @@ def hook_disappearing_repo(tempdir_factory):
path = make_repo(tempdir_factory, 'python_hooks_repo')
original_rev = git.head_rev(path)

shutil.copy(
get_resource_path('manifest_without_foo.yaml'),
os.path.join(path, C.MANIFEST_FILE),
)
cmd_output('git', 'add', '.', cwd=path)
git_commit(cwd=path)
with modify_manifest(path) as manifest:
manifest[0]['id'] = 'bar'

yield auto_namedtuple(path=path, original_rev=original_rev)

Expand Down
2 changes: 0 additions & 2 deletions tests/commands/migrate_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ def test_migrate_config_sha_to_rev(tmpdir):
'- repo: https://github.com/pre-commit/pre-commit-hooks\n'
' sha: v1.2.0\n'
' hooks: []\n'
'repos:\n'
'- repo: https://github.com/pre-commit/pre-commit-hooks\n'
' sha: v1.2.0\n'
' hooks: []\n'
Expand All @@ -144,7 +143,6 @@ def test_migrate_config_sha_to_rev(tmpdir):
'- repo: https://github.com/pre-commit/pre-commit-hooks\n'
' rev: v1.2.0\n'
' hooks: []\n'
'repos:\n'
'- repo: https://github.com/pre-commit/pre-commit-hooks\n'
' rev: v1.2.0\n'
' hooks: []\n'
Expand Down