11from __future__ import absolute_import
22from __future__ import unicode_literals
33
4+ import pytest
5+
46from pre_commit_hooks .no_commit_to_branch import is_on_branch
57from pre_commit_hooks .no_commit_to_branch import main
68from pre_commit_hooks .util import cmd_output
911def test_other_branch (temp_git_dir ):
1012 with temp_git_dir .as_cwd ():
1113 cmd_output ('git' , 'checkout' , '-b' , 'anotherbranch' )
12- assert is_on_branch ('master' ) is False
14+ assert is_on_branch (( 'master' ,) ) is False
1315
1416
1517def test_multi_branch (temp_git_dir ):
1618 with temp_git_dir .as_cwd ():
1719 cmd_output ('git' , 'checkout' , '-b' , 'another/branch' )
18- assert is_on_branch ('master' ) is False
20+ assert is_on_branch (( 'master' ,) ) is False
1921
2022
2123def test_multi_branch_fail (temp_git_dir ):
2224 with temp_git_dir .as_cwd ():
2325 cmd_output ('git' , 'checkout' , '-b' , 'another/branch' )
24- assert is_on_branch ('another/branch' ) is True
26+ assert is_on_branch (( 'another/branch' ,) ) is True
2527
2628
2729def test_master_branch (temp_git_dir ):
2830 with temp_git_dir .as_cwd ():
29- assert is_on_branch ('master' ) is True
31+ assert is_on_branch (( 'master' ,) ) is True
3032
3133
3234def test_main_branch_call (temp_git_dir ):
@@ -35,6 +37,13 @@ def test_main_branch_call(temp_git_dir):
3537 assert main (('--branch' , 'other' )) == 1
3638
3739
40+ @pytest .mark .parametrize ('branch_name' , ('b1' , 'b2' ))
41+ def test_forbid_multiple_branches (temp_git_dir , branch_name ):
42+ with temp_git_dir .as_cwd ():
43+ cmd_output ('git' , 'checkout' , '-b' , branch_name )
44+ assert main (('--branch' , 'b1' , '--branch' , 'b2' ))
45+
46+
3847def test_main_default_call (temp_git_dir ):
3948 with temp_git_dir .as_cwd ():
4049 cmd_output ('git' , 'checkout' , '-b' , 'anotherbranch' )
0 commit comments