small cleanups in tests

This commit is contained in:
Anthony Sottile
2019-01-06 11:52:22 -08:00
parent 782244a7b8
commit bea33af310
6 changed files with 30 additions and 78 deletions

View File

@@ -1,5 +0,0 @@
- id: bar
name: Bar
entry: bar
language: python
files: \.py$

View File

@@ -1,5 +0,0 @@
- repo: git@github.com:pre-commit/pre-commit-hooks
hooks:
- id: pyflakes
- id: jslint
- id: trim_trailing_whitespace

View File

@@ -1 +0,0 @@
foo: bar

View File

@@ -13,7 +13,6 @@ from pre_commit.clientlib import MigrateShaToRev
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):
@@ -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'), (
(
@@ -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)
@@ -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(
@@ -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',

View File

@@ -1,8 +1,6 @@
from __future__ import unicode_literals
import os.path
import pipes
import shutil
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 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
@@ -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)

View File

@@ -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'
@@ -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'