Skip to content

Commit a2b5360

Browse files
authored
Merge pull request pre-commit#910 from asottile/cleanup_tests
small cleanups in tests
2 parents 782244a + bea33af commit a2b5360

File tree

6 files changed

+30
-78
lines changed

6 files changed

+30
-78
lines changed

testing/resources/manifest_without_foo.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

testing/resources/valid_yaml_but_invalid_config.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

testing/resources/valid_yaml_but_invalid_manifest.yaml

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/clientlib_test.py

Lines changed: 27 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from pre_commit.clientlib import validate_config_main
1414
from pre_commit.clientlib import validate_manifest_main
1515
from testing.fixtures import sample_local_config
16-
from testing.util import get_resource_path
1716

1817

1918
def is_valid_according_to_schema(obj, obj_schema):
@@ -30,19 +29,6 @@ def test_check_type_tag_failures(value):
3029
check_type_tag(value)
3130

3231

33-
@pytest.mark.parametrize(
34-
('args', 'expected_output'),
35-
(
36-
(['.pre-commit-config.yaml'], 0),
37-
(['non_existent_file.yaml'], 1),
38-
([get_resource_path('valid_yaml_but_invalid_config.yaml')], 1),
39-
([get_resource_path('non_parseable_yaml_file.notyaml')], 1),
40-
),
41-
)
42-
def test_validate_config_main(args, expected_output):
43-
assert validate_config_main(args) == expected_output
44-
45-
4632
@pytest.mark.parametrize(
4733
('config_obj', 'expected'), (
4834
(
@@ -91,39 +77,13 @@ def test_config_valid(config_obj, expected):
9177

9278

9379
def test_local_hooks_with_rev_fails():
94-
config_obj = {'repos': [sample_local_config()]}
95-
config_obj['repos'][0]['rev'] = 'foo'
80+
config_obj = {'repos': [dict(sample_local_config(), rev='foo')]}
9681
with pytest.raises(cfgv.ValidationError):
9782
cfgv.validate(config_obj, CONFIG_SCHEMA)
9883

9984

100-
@pytest.mark.parametrize(
101-
'config_obj', (
102-
{'repos': [{
103-
'repo': 'local',
104-
'hooks': [{
105-
'id': 'arg-per-line',
106-
'name': 'Args per line hook',
107-
'entry': 'bin/hook.sh',
108-
'language': 'script',
109-
'files': '',
110-
'args': ['hello', 'world'],
111-
}],
112-
}]},
113-
{'repos': [{
114-
'repo': 'local',
115-
'hooks': [{
116-
'id': 'arg-per-line',
117-
'name': 'Args per line hook',
118-
'entry': 'bin/hook.sh',
119-
'language': 'script',
120-
'files': '',
121-
'args': ['hello', 'world'],
122-
}],
123-
}]},
124-
),
125-
)
126-
def test_config_with_local_hooks_definition_passes(config_obj):
85+
def test_config_with_local_hooks_definition_passes():
86+
config_obj = {'repos': [sample_local_config()]}
12787
cfgv.validate(config_obj, CONFIG_SCHEMA)
12888

12989

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

13797

138-
@pytest.mark.parametrize(
139-
('args', 'expected_output'),
140-
(
141-
(['.pre-commit-hooks.yaml'], 0),
142-
(['non_existent_file.yaml'], 1),
143-
([get_resource_path('valid_yaml_but_invalid_manifest.yaml')], 1),
144-
([get_resource_path('non_parseable_yaml_file.notyaml')], 1),
145-
),
146-
)
147-
def test_validate_manifest_main(args, expected_output):
148-
assert validate_manifest_main(args) == expected_output
98+
def test_validate_manifest_main_ok():
99+
assert not validate_manifest_main(('.pre-commit-hooks.yaml',))
100+
101+
102+
def test_validate_config_main_ok():
103+
assert not validate_config_main(('.pre-commit-config.yaml',))
104+
105+
106+
def test_validate_config_old_list_format_ok(tmpdir):
107+
f = tmpdir.join('cfg.yaml')
108+
f.write('- {repo: meta, hooks: [{id: identity}]}')
109+
assert not validate_config_main((f.strpath,))
110+
111+
112+
@pytest.mark.parametrize('fn', (validate_config_main, validate_manifest_main))
113+
def test_mains_not_ok(tmpdir, fn):
114+
not_yaml = tmpdir.join('f.notyaml')
115+
not_yaml.write('{')
116+
not_schema = tmpdir.join('notconfig.yaml')
117+
not_schema.write('{}')
118+
119+
assert fn(('does-not-exist',))
120+
assert fn((not_yaml.strpath,))
121+
assert fn((not_schema.strpath,))
149122

150123

151124
@pytest.mark.parametrize(
@@ -174,8 +147,6 @@ def test_validate_manifest_main(args, expected_output):
174147
),
175148
(
176149
# A regression in 0.13.5: always_run and files are permissible
177-
# together (but meaningless). In a future version upgrade this to
178-
# an error
179150
[{
180151
'id': 'a',
181152
'name': 'b',

tests/commands/autoupdate_test.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from __future__ import unicode_literals
22

3-
import os.path
43
import pipes
5-
import shutil
64

75
import pytest
86

@@ -16,10 +14,10 @@
1614
from testing.fixtures import add_config_to_repo
1715
from testing.fixtures import make_config_from_repo
1816
from testing.fixtures import make_repo
17+
from testing.fixtures import modify_manifest
1918
from testing.fixtures import read_config
2019
from testing.fixtures import sample_local_config
2120
from testing.fixtures import write_config
22-
from testing.util import get_resource_path
2321
from testing.util import git_commit
2422

2523

@@ -275,12 +273,8 @@ def hook_disappearing_repo(tempdir_factory):
275273
path = make_repo(tempdir_factory, 'python_hooks_repo')
276274
original_rev = git.head_rev(path)
277275

278-
shutil.copy(
279-
get_resource_path('manifest_without_foo.yaml'),
280-
os.path.join(path, C.MANIFEST_FILE),
281-
)
282-
cmd_output('git', 'add', '.', cwd=path)
283-
git_commit(cwd=path)
276+
with modify_manifest(path) as manifest:
277+
manifest[0]['id'] = 'bar'
284278

285279
yield auto_namedtuple(path=path, original_rev=original_rev)
286280

tests/commands/migrate_config_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ def test_migrate_config_sha_to_rev(tmpdir):
129129
'- repo: https://github.com/pre-commit/pre-commit-hooks\n'
130130
' sha: v1.2.0\n'
131131
' hooks: []\n'
132-
'repos:\n'
133132
'- repo: https://github.com/pre-commit/pre-commit-hooks\n'
134133
' sha: v1.2.0\n'
135134
' hooks: []\n'
@@ -144,7 +143,6 @@ def test_migrate_config_sha_to_rev(tmpdir):
144143
'- repo: https://github.com/pre-commit/pre-commit-hooks\n'
145144
' rev: v1.2.0\n'
146145
' hooks: []\n'
147-
'repos:\n'
148146
'- repo: https://github.com/pre-commit/pre-commit-hooks\n'
149147
' rev: v1.2.0\n'
150148
' hooks: []\n'

0 commit comments

Comments
 (0)