mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 17:14:43 +04:00
Merge pull request #910 from asottile/cleanup_tests
small cleanups in tests
This commit is contained in:
commit
a2b536030a
6 changed files with 30 additions and 78 deletions
|
|
@ -1,5 +0,0 @@
|
||||||
- id: bar
|
|
||||||
name: Bar
|
|
||||||
entry: bar
|
|
||||||
language: python
|
|
||||||
files: \.py$
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
- repo: git@github.com:pre-commit/pre-commit-hooks
|
|
||||||
hooks:
|
|
||||||
- id: pyflakes
|
|
||||||
- id: jslint
|
|
||||||
- id: trim_trailing_whitespace
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
foo: bar
|
|
||||||
|
|
@ -13,7 +13,6 @@ from pre_commit.clientlib import MigrateShaToRev
|
||||||
from pre_commit.clientlib import validate_config_main
|
from pre_commit.clientlib import validate_config_main
|
||||||
from pre_commit.clientlib import validate_manifest_main
|
from pre_commit.clientlib import validate_manifest_main
|
||||||
from testing.fixtures import sample_local_config
|
from testing.fixtures import sample_local_config
|
||||||
from testing.util import get_resource_path
|
|
||||||
|
|
||||||
|
|
||||||
def is_valid_according_to_schema(obj, obj_schema):
|
def is_valid_according_to_schema(obj, obj_schema):
|
||||||
|
|
@ -30,19 +29,6 @@ def test_check_type_tag_failures(value):
|
||||||
check_type_tag(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(
|
@pytest.mark.parametrize(
|
||||||
('config_obj', 'expected'), (
|
('config_obj', 'expected'), (
|
||||||
(
|
(
|
||||||
|
|
@ -91,39 +77,13 @@ def test_config_valid(config_obj, expected):
|
||||||
|
|
||||||
|
|
||||||
def test_local_hooks_with_rev_fails():
|
def test_local_hooks_with_rev_fails():
|
||||||
config_obj = {'repos': [sample_local_config()]}
|
config_obj = {'repos': [dict(sample_local_config(), rev='foo')]}
|
||||||
config_obj['repos'][0]['rev'] = 'foo'
|
|
||||||
with pytest.raises(cfgv.ValidationError):
|
with pytest.raises(cfgv.ValidationError):
|
||||||
cfgv.validate(config_obj, CONFIG_SCHEMA)
|
cfgv.validate(config_obj, CONFIG_SCHEMA)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
def test_config_with_local_hooks_definition_passes():
|
||||||
'config_obj', (
|
config_obj = {'repos': [sample_local_config()]}
|
||||||
{'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):
|
|
||||||
cfgv.validate(config_obj, CONFIG_SCHEMA)
|
cfgv.validate(config_obj, CONFIG_SCHEMA)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -135,17 +95,30 @@ def test_config_schema_does_not_contain_defaults():
|
||||||
assert not isinstance(item, cfgv.Optional)
|
assert not isinstance(item, cfgv.Optional)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
def test_validate_manifest_main_ok():
|
||||||
('args', 'expected_output'),
|
assert not validate_manifest_main(('.pre-commit-hooks.yaml',))
|
||||||
(
|
|
||||||
(['.pre-commit-hooks.yaml'], 0),
|
|
||||||
(['non_existent_file.yaml'], 1),
|
def test_validate_config_main_ok():
|
||||||
([get_resource_path('valid_yaml_but_invalid_manifest.yaml')], 1),
|
assert not validate_config_main(('.pre-commit-config.yaml',))
|
||||||
([get_resource_path('non_parseable_yaml_file.notyaml')], 1),
|
|
||||||
),
|
|
||||||
)
|
def test_validate_config_old_list_format_ok(tmpdir):
|
||||||
def test_validate_manifest_main(args, expected_output):
|
f = tmpdir.join('cfg.yaml')
|
||||||
assert validate_manifest_main(args) == expected_output
|
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(
|
@pytest.mark.parametrize(
|
||||||
|
|
@ -174,8 +147,6 @@ def test_validate_manifest_main(args, expected_output):
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
# A regression in 0.13.5: always_run and files are permissible
|
# 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',
|
'id': 'a',
|
||||||
'name': 'b',
|
'name': 'b',
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import os.path
|
|
||||||
import pipes
|
import pipes
|
||||||
import shutil
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
@ -16,10 +14,10 @@ from testing.auto_namedtuple import auto_namedtuple
|
||||||
from testing.fixtures import add_config_to_repo
|
from testing.fixtures import add_config_to_repo
|
||||||
from testing.fixtures import make_config_from_repo
|
from testing.fixtures import make_config_from_repo
|
||||||
from testing.fixtures import make_repo
|
from testing.fixtures import make_repo
|
||||||
|
from testing.fixtures import modify_manifest
|
||||||
from testing.fixtures import read_config
|
from testing.fixtures import read_config
|
||||||
from testing.fixtures import sample_local_config
|
from testing.fixtures import sample_local_config
|
||||||
from testing.fixtures import write_config
|
from testing.fixtures import write_config
|
||||||
from testing.util import get_resource_path
|
|
||||||
from testing.util import git_commit
|
from testing.util import git_commit
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -275,12 +273,8 @@ def hook_disappearing_repo(tempdir_factory):
|
||||||
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
||||||
original_rev = git.head_rev(path)
|
original_rev = git.head_rev(path)
|
||||||
|
|
||||||
shutil.copy(
|
with modify_manifest(path) as manifest:
|
||||||
get_resource_path('manifest_without_foo.yaml'),
|
manifest[0]['id'] = 'bar'
|
||||||
os.path.join(path, C.MANIFEST_FILE),
|
|
||||||
)
|
|
||||||
cmd_output('git', 'add', '.', cwd=path)
|
|
||||||
git_commit(cwd=path)
|
|
||||||
|
|
||||||
yield auto_namedtuple(path=path, original_rev=original_rev)
|
yield auto_namedtuple(path=path, original_rev=original_rev)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,6 @@ def test_migrate_config_sha_to_rev(tmpdir):
|
||||||
'- repo: https://github.com/pre-commit/pre-commit-hooks\n'
|
'- repo: https://github.com/pre-commit/pre-commit-hooks\n'
|
||||||
' sha: v1.2.0\n'
|
' sha: v1.2.0\n'
|
||||||
' hooks: []\n'
|
' hooks: []\n'
|
||||||
'repos:\n'
|
|
||||||
'- repo: https://github.com/pre-commit/pre-commit-hooks\n'
|
'- repo: https://github.com/pre-commit/pre-commit-hooks\n'
|
||||||
' sha: v1.2.0\n'
|
' sha: v1.2.0\n'
|
||||||
' hooks: []\n'
|
' hooks: []\n'
|
||||||
|
|
@ -144,7 +143,6 @@ def test_migrate_config_sha_to_rev(tmpdir):
|
||||||
'- repo: https://github.com/pre-commit/pre-commit-hooks\n'
|
'- repo: https://github.com/pre-commit/pre-commit-hooks\n'
|
||||||
' rev: v1.2.0\n'
|
' rev: v1.2.0\n'
|
||||||
' hooks: []\n'
|
' hooks: []\n'
|
||||||
'repos:\n'
|
|
||||||
'- repo: https://github.com/pre-commit/pre-commit-hooks\n'
|
'- repo: https://github.com/pre-commit/pre-commit-hooks\n'
|
||||||
' rev: v1.2.0\n'
|
' rev: v1.2.0\n'
|
||||||
' hooks: []\n'
|
' hooks: []\n'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue