@@ -529,52 +529,37 @@ def test_lots_of_files(mock_out_store_directory, tempdir_factory):
529529 )
530530
531531
532- def test_push_hook (cap_out , repo_with_passing_hook , mock_out_store_directory ):
532+ def test_stages (cap_out , repo_with_passing_hook , mock_out_store_directory ):
533533 config = OrderedDict ((
534534 ('repo' , 'local' ),
535535 (
536- 'hooks' , (
537- OrderedDict ((
538- ('id' , 'flake8' ),
539- ('name' , 'hook 1' ),
540- ('entry' , "'{}' -m flake8" .format (sys .executable )),
541- ('language' , 'system' ),
542- ('types' , ['python' ]),
543- ('stages' , ['commit' ]),
544- )),
545- OrderedDict ((
546- ('id' , 'do_not_commit' ),
547- ('name' , 'hook 2' ),
548- ('entry' , 'DO NOT COMMIT' ),
549- ('language' , 'pygrep' ),
550- ('types' , ['text' ]),
551- ('stages' , ['push' ]),
552- )),
536+ 'hooks' , tuple (
537+ {
538+ 'id' : 'do-not-commit-{}' .format (i ),
539+ 'name' : 'hook {}' .format (i ),
540+ 'entry' : 'DO NOT COMMIT' ,
541+ 'language' : 'pygrep' ,
542+ 'stages' : [stage ],
543+ }
544+ for i , stage in enumerate (('commit' , 'push' , 'manual' ), 1 )
553545 ),
554546 ),
555547 ))
556548 add_config_to_repo (repo_with_passing_hook , config )
557549
558- open ('dummy.py' , 'a' ).close ()
559- cmd_output ('git' , 'add' , 'dummy.py' )
560-
561- _test_run (
562- cap_out ,
563- repo_with_passing_hook ,
564- {'hook_stage' : 'commit' },
565- expected_outputs = [b'hook 1' ],
566- expected_ret = 0 ,
567- stage = False ,
568- )
550+ stage_a_file ()
569551
570- _test_run (
571- cap_out ,
572- repo_with_passing_hook ,
573- {'hook_stage' : 'push' },
574- expected_outputs = [b'hook 2' ],
575- expected_ret = 0 ,
576- stage = False ,
577- )
552+ def _run_for_stage (stage ):
553+ args = run_opts (hook_stage = stage )
554+ ret , printed = _do_run (cap_out , repo_with_passing_hook , args )
555+ assert not ret , (ret , printed )
556+ # this test should only run one hook
557+ assert printed .count (b'hook ' ) == 1
558+ return printed
559+
560+ assert _run_for_stage ('commit' ).startswith (b'hook 1...' )
561+ assert _run_for_stage ('push' ).startswith (b'hook 2...' )
562+ assert _run_for_stage ('manual' ).startswith (b'hook 3...' )
578563
579564
580565def test_commit_msg_hook (cap_out , commit_msg_repo , mock_out_store_directory ):
0 commit comments