Skip to content

Commit e4cf5f3

Browse files
committed
just use normal dicts in tests
1 parent 2125a4c commit e4cf5f3

File tree

7 files changed

+114
-157
lines changed

7 files changed

+114
-157
lines changed

pre_commit/clientlib.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import unicode_literals
33

44
import argparse
5-
import collections
65
import functools
76

87
import cfgv
@@ -170,7 +169,7 @@ def ordered_load_normalize_legacy_config(contents):
170169
data = ordered_load(contents)
171170
if isinstance(data, list):
172171
# TODO: Once happy, issue a deprecation warning and instructions
173-
return collections.OrderedDict([('repos', data)])
172+
return {'repos': data}
174173
else:
175174
return data
176175

testing/fixtures.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import io
66
import os.path
77
import shutil
8-
from collections import OrderedDict
98

109
from aspy.yaml import ordered_dump
1110
from aspy.yaml import ordered_load
@@ -83,30 +82,24 @@ def modify_config(path='.', commit=True):
8382

8483

8584
def config_with_local_hooks():
86-
return OrderedDict((
87-
('repo', 'local'),
88-
(
89-
'hooks', [OrderedDict((
90-
('id', 'do_not_commit'),
91-
('name', 'Block if "DO NOT COMMIT" is found'),
92-
('entry', 'DO NOT COMMIT'),
93-
('language', 'pygrep'),
94-
('files', '^(.*)$'),
95-
))],
96-
),
97-
))
85+
return {
86+
'repo': 'local',
87+
'hooks': [{
88+
'id': 'do_not_commit',
89+
'name': 'Block if "DO NOT COMMIT" is found',
90+
'entry': 'DO NOT COMMIT',
91+
'language': 'pygrep',
92+
}],
93+
}
9894

9995

10096
def make_config_from_repo(repo_path, rev=None, hooks=None, check=True):
10197
manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE))
102-
config = OrderedDict((
103-
('repo', 'file://{}'.format(repo_path)),
104-
('rev', rev or git.head_rev(repo_path)),
105-
(
106-
'hooks',
107-
hooks or [OrderedDict((('id', hook['id']),)) for hook in manifest],
108-
),
109-
))
98+
config = {
99+
'repo': 'file://{}'.format(repo_path),
100+
'rev': rev or git.head_rev(repo_path),
101+
'hooks': hooks or [{'id': hook['id']} for hook in manifest],
102+
}
110103

111104
if check:
112105
wrapped = validate({'repos': [config]}, CONFIG_SCHEMA)
@@ -126,7 +119,7 @@ def read_config(directory, config_file=C.CONFIG_FILE):
126119

127120
def write_config(directory, config, config_file=C.CONFIG_FILE):
128121
if type(config) is not list and 'repos' not in config:
129-
assert type(config) is OrderedDict
122+
assert isinstance(config, dict), config
130123
config = {'repos': [config]}
131124
with io.open(os.path.join(directory, config_file), 'w') as outfile:
132125
outfile.write(ordered_dump(config, **C.YAML_DUMP_KWARGS))

tests/clientlib_test.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pre_commit.clientlib import MigrateShaToRev
1212
from pre_commit.clientlib import validate_config_main
1313
from pre_commit.clientlib import validate_manifest_main
14+
from testing.fixtures import config_with_local_hooks
1415
from testing.util import get_resource_path
1516

1617

@@ -92,18 +93,9 @@ def test_config_valid(config_obj, expected):
9293
assert ret is expected
9394

9495

95-
def test_config_with_local_hooks_definition_fails():
96-
config_obj = {'repos': [{
97-
'repo': 'local',
98-
'rev': 'foo',
99-
'hooks': [{
100-
'id': 'do_not_commit',
101-
'name': 'Block if "DO NOT COMMIT" is found',
102-
'entry': 'DO NOT COMMIT',
103-
'language': 'pcre',
104-
'files': '^(.*)$',
105-
}],
106-
}]}
96+
def test_local_hooks_with_rev_fails():
97+
config_obj = {'repos': [config_with_local_hooks()]}
98+
config_obj['repos'][0]['rev'] = 'foo'
10799
with pytest.raises(cfgv.ValidationError):
108100
cfgv.validate(config_obj, CONFIG_SCHEMA)
109101

tests/commands/autoupdate_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os.path
44
import pipes
55
import shutil
6-
from collections import OrderedDict
76

87
import pytest
98

@@ -290,7 +289,7 @@ def test_hook_disppearing_repo_raises(hook_disappearing_repo, store):
290289
config = make_config_from_repo(
291290
hook_disappearing_repo.path,
292291
rev=hook_disappearing_repo.original_rev,
293-
hooks=[OrderedDict((('id', 'foo'),))],
292+
hooks=[{'id': 'foo'}],
294293
)
295294
with pytest.raises(RepositoryCannotBeUpdatedError):
296295
_update_repo(config, store, tags_only=False)
@@ -302,7 +301,7 @@ def test_autoupdate_hook_disappearing_repo(
302301
config = make_config_from_repo(
303302
hook_disappearing_repo.path,
304303
rev=hook_disappearing_repo.original_rev,
305-
hooks=[OrderedDict((('id', 'foo'),))],
304+
hooks=[{'id': 'foo'}],
306305
check=False,
307306
)
308307
write_config('.', config)

tests/commands/run_test.py

Lines changed: 71 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import os.path
66
import subprocess
77
import sys
8-
from collections import OrderedDict
98

109
import pytest
1110

@@ -521,21 +520,19 @@ def test_lots_of_files(store, tempdir_factory):
521520

522521

523522
def test_stages(cap_out, store, repo_with_passing_hook):
524-
config = OrderedDict((
525-
('repo', 'local'),
526-
(
527-
'hooks', tuple(
528-
{
529-
'id': 'do-not-commit-{}'.format(i),
530-
'name': 'hook {}'.format(i),
531-
'entry': 'DO NOT COMMIT',
532-
'language': 'pygrep',
533-
'stages': [stage],
534-
}
535-
for i, stage in enumerate(('commit', 'push', 'manual'), 1)
536-
),
537-
),
538-
))
523+
config = {
524+
'repo': 'local',
525+
'hooks': [
526+
{
527+
'id': 'do-not-commit-{}'.format(i),
528+
'name': 'hook {}'.format(i),
529+
'entry': 'DO NOT COMMIT',
530+
'language': 'pygrep',
531+
'stages': [stage],
532+
}
533+
for i, stage in enumerate(('commit', 'push', 'manual'), 1)
534+
],
535+
}
539536
add_config_to_repo(repo_with_passing_hook, config)
540537

541538
stage_a_file()
@@ -570,26 +567,24 @@ def test_commit_msg_hook(cap_out, store, commit_msg_repo):
570567

571568

572569
def test_local_hook_passes(cap_out, store, repo_with_passing_hook):
573-
config = OrderedDict((
574-
('repo', 'local'),
575-
(
576-
'hooks', (
577-
OrderedDict((
578-
('id', 'flake8'),
579-
('name', 'flake8'),
580-
('entry', "'{}' -m flake8".format(sys.executable)),
581-
('language', 'system'),
582-
('files', r'\.py$'),
583-
)), OrderedDict((
584-
('id', 'do_not_commit'),
585-
('name', 'Block if "DO NOT COMMIT" is found'),
586-
('entry', 'DO NOT COMMIT'),
587-
('language', 'pygrep'),
588-
('files', '^(.*)$'),
589-
)),
590-
),
591-
),
592-
))
570+
config = {
571+
'repo': 'local',
572+
'hooks': [
573+
{
574+
'id': 'flake8',
575+
'name': 'flake8',
576+
'entry': "'{}' -m flake8".format(sys.executable),
577+
'language': 'system',
578+
'files': r'\.py$',
579+
},
580+
{
581+
'id': 'do_not_commit',
582+
'name': 'Block if "DO NOT COMMIT" is found',
583+
'entry': 'DO NOT COMMIT',
584+
'language': 'pygrep',
585+
},
586+
],
587+
}
593588
add_config_to_repo(repo_with_passing_hook, config)
594589

595590
with io.open('dummy.py', 'w') as staged_file:
@@ -608,18 +603,15 @@ def test_local_hook_passes(cap_out, store, repo_with_passing_hook):
608603

609604

610605
def test_local_hook_fails(cap_out, store, repo_with_passing_hook):
611-
config = OrderedDict((
612-
('repo', 'local'),
613-
(
614-
'hooks', [OrderedDict((
615-
('id', 'no-todo'),
616-
('name', 'No TODO'),
617-
('entry', 'sh -c "! grep -iI todo $@" --'),
618-
('language', 'system'),
619-
('files', ''),
620-
))],
621-
),
622-
))
606+
config = {
607+
'repo': 'local',
608+
'hooks': [{
609+
'id': 'no-todo',
610+
'name': 'No TODO',
611+
'entry': 'sh -c "! grep -iI todo $@" --',
612+
'language': 'system',
613+
}],
614+
}
623615
add_config_to_repo(repo_with_passing_hook, config)
624616

625617
with io.open('dummy.py', 'w') as staged_file:
@@ -638,17 +630,15 @@ def test_local_hook_fails(cap_out, store, repo_with_passing_hook):
638630

639631

640632
def test_pcre_deprecation_warning(cap_out, store, repo_with_passing_hook):
641-
config = OrderedDict((
642-
('repo', 'local'),
643-
(
644-
'hooks', [OrderedDict((
645-
('id', 'pcre-hook'),
646-
('name', 'pcre-hook'),
647-
('language', 'pcre'),
648-
('entry', '.'),
649-
))],
650-
),
651-
))
633+
config = {
634+
'repo': 'local',
635+
'hooks': [{
636+
'id': 'pcre-hook',
637+
'name': 'pcre-hook',
638+
'language': 'pcre',
639+
'entry': '.',
640+
}],
641+
}
652642
add_config_to_repo(repo_with_passing_hook, config)
653643

654644
_test_run(
@@ -666,16 +656,10 @@ def test_pcre_deprecation_warning(cap_out, store, repo_with_passing_hook):
666656

667657

668658
def test_meta_hook_passes(cap_out, store, repo_with_passing_hook):
669-
config = OrderedDict((
670-
('repo', 'meta'),
671-
(
672-
'hooks', (
673-
OrderedDict((
674-
('id', 'check-useless-excludes'),
675-
)),
676-
),
677-
),
678-
))
659+
config = {
660+
'repo': 'meta',
661+
'hooks': [{'id': 'check-useless-excludes'}],
662+
}
679663
add_config_to_repo(repo_with_passing_hook, config)
680664

681665
_test_run(
@@ -810,25 +794,24 @@ def test_include_exclude_exclude_removes_files(some_filenames):
810794

811795

812796
def test_args_hook_only(cap_out, store, repo_with_passing_hook):
813-
config = OrderedDict((
814-
('repo', 'local'),
815-
(
816-
'hooks', (
817-
OrderedDict((
818-
('id', 'flake8'),
819-
('name', 'flake8'),
820-
('entry', "'{}' -m flake8".format(sys.executable)),
821-
('language', 'system'),
822-
('stages', ['commit']),
823-
)), OrderedDict((
824-
('id', 'do_not_commit'),
825-
('name', 'Block if "DO NOT COMMIT" is found'),
826-
('entry', 'DO NOT COMMIT'),
827-
('language', 'pygrep'),
828-
)),
829-
),
830-
),
831-
))
797+
config = {
798+
'repo': 'local',
799+
'hooks': [
800+
{
801+
'id': 'flake8',
802+
'name': 'flake8',
803+
'entry': "'{}' -m flake8".format(sys.executable),
804+
'language': 'system',
805+
'stages': ['commit'],
806+
},
807+
{
808+
'id': 'do_not_commit',
809+
'name': 'Block if "DO NOT COMMIT" is found',
810+
'entry': 'DO NOT COMMIT',
811+
'language': 'pygrep',
812+
},
813+
],
814+
}
832815
add_config_to_repo(repo_with_passing_hook, config)
833816
stage_a_file()
834817
ret, printed = _do_run(

tests/conftest.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import absolute_import
22
from __future__ import unicode_literals
33

4-
import collections
54
import functools
65
import io
76
import logging
@@ -120,19 +119,16 @@ def in_conflicting_submodule(tempdir_factory):
120119
@pytest.fixture
121120
def commit_msg_repo(tempdir_factory):
122121
path = git_dir(tempdir_factory)
123-
config = collections.OrderedDict((
124-
('repo', 'local'),
125-
(
126-
'hooks',
127-
[collections.OrderedDict((
128-
('id', 'must-have-signoff'),
129-
('name', 'Must have "Signed off by:"'),
130-
('entry', 'grep -q "Signed off by:"'),
131-
('language', 'system'),
132-
('stages', ['commit-msg']),
133-
))],
134-
),
135-
))
122+
config = {
123+
'repo': 'local',
124+
'hooks': [{
125+
'id': 'must-have-signoff',
126+
'name': 'Must have "Signed off by:"',
127+
'entry': 'grep -q "Signed off by:"',
128+
'language': 'system',
129+
'stages': ['commit-msg'],
130+
}],
131+
}
136132
write_config(path, config)
137133
with cwd(path):
138134
cmd_output('git', 'add', '.')

0 commit comments

Comments
 (0)