@@ -89,6 +89,51 @@ def call(*_, **__):
8989 call ()
9090
9191
92+ @pytest .mark .parametrize (
93+ ('hook_type' , 'args' ),
94+ (
95+ ('pre-commit' , []),
96+ ('pre-merge-commit' , []),
97+ ('pre-push' , ['branch_name' , 'remote_name' ]),
98+ ('commit-msg' , ['.git/COMMIT_EDITMSG' ]),
99+ ('post-checkout' , ['old_head' , 'new_head' , '1' ]),
100+ # multiple choices for commit-editmsg
101+ ('prepare-commit-msg' , ['.git/COMMIT_EDITMSG' ]),
102+ ('prepare-commit-msg' , ['.git/COMMIT_EDITMSG' , 'message' ]),
103+ ('prepare-commit-msg' , ['.git/COMMIT_EDITMSG' , 'commit' , 'deadbeef' ]),
104+ ),
105+ )
106+ def test_check_args_length_ok (hook_type , args ):
107+ hook_impl ._check_args_length (hook_type , args )
108+
109+
110+ def test_check_args_length_error_too_many_plural ():
111+ with pytest .raises (SystemExit ) as excinfo :
112+ hook_impl ._check_args_length ('pre-commit' , ['run' , '--all-files' ])
113+ msg , = excinfo .value .args
114+ assert msg == (
115+ 'hook-impl for pre-commit expected 0 arguments but got 2: '
116+ "['run', '--all-files']"
117+ )
118+
119+
120+ def test_check_args_length_error_too_many_singluar ():
121+ with pytest .raises (SystemExit ) as excinfo :
122+ hook_impl ._check_args_length ('commit-msg' , [])
123+ msg , = excinfo .value .args
124+ assert msg == 'hook-impl for commit-msg expected 1 argument but got 0: []'
125+
126+
127+ def test_check_args_length_prepare_commit_msg_error ():
128+ with pytest .raises (SystemExit ) as excinfo :
129+ hook_impl ._check_args_length ('prepare-commit-msg' , [])
130+ msg , = excinfo .value .args
131+ assert msg == (
132+ 'hook-impl for prepare-commit-msg expected 1, 2, or 3 arguments '
133+ 'but got 0: []'
134+ )
135+
136+
92137def test_run_ns_pre_commit ():
93138 ns = hook_impl ._run_ns ('pre-commit' , True , (), b'' )
94139 assert ns is not None
0 commit comments