55import os .path
66import subprocess
77import sys
8- from collections import OrderedDict
98
109import pytest
1110
@@ -521,21 +520,19 @@ def test_lots_of_files(store, tempdir_factory):
521520
522521
523522def 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
572569def 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
610605def 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
640632def 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
668658def 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
812796def 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 (
0 commit comments