1414from shtab .main import get_main_parser , main
1515
1616SUPPORTED_SHELLS = "bash" , "zsh"
17+ fix_shell = pytest .mark .parametrize ("shell" , SUPPORTED_SHELLS )
1718
1819
1920class Bash (object ):
@@ -70,15 +71,42 @@ def test_choices():
7071 assert "" not in shtab .Required .FILE
7172
7273
73- @pytest . mark . parametrize ( "shell" , SUPPORTED_SHELLS )
74+ @fix_shell
7475def test_main (shell , caplog ):
7576 with caplog .at_level (logging .INFO ):
7677 main (["-s" , shell , "shtab.main.get_main_parser" ])
7778
7879 assert not caplog .record_tuples
7980
8081
81- @pytest .mark .parametrize ("shell" , SUPPORTED_SHELLS )
82+ @fix_shell
83+ def test_prog_override (shell , caplog , capsys ):
84+ with caplog .at_level (logging .INFO ):
85+ main (["-s" , shell , "--prog" , "foo" , "shtab.main.get_main_parser" ])
86+
87+ captured = capsys .readouterr ()
88+ assert not captured .err
89+ if shell == "bash" :
90+ assert "complete -o nospace -F _shtab_shtab foo" in captured .out
91+
92+ assert not caplog .record_tuples
93+
94+
95+ @fix_shell
96+ def test_prefix_override (shell , caplog , capsys ):
97+ with caplog .at_level (logging .INFO ):
98+ main (["-s" , shell , "--prefix" , "foo" , "shtab.main.get_main_parser" ])
99+
100+ captured = capsys .readouterr ()
101+ assert not captured .err
102+ if shell == "bash" :
103+ shell = Bash (captured .out )
104+ shell .compgen ('-W "$_shtab_foo_options_"' , "--h" , "--help" )
105+
106+ assert not caplog .record_tuples
107+
108+
109+ @fix_shell
82110def test_complete (shell , caplog ):
83111 parser = get_main_parser ()
84112 with caplog .at_level (logging .INFO ):
@@ -92,7 +120,7 @@ def test_complete(shell, caplog):
92120 assert not caplog .record_tuples
93121
94122
95- @pytest . mark . parametrize ( "shell" , SUPPORTED_SHELLS )
123+ @fix_shell
96124def test_positional_choices (shell , caplog ):
97125 parser = ArgumentParser (prog = "test" )
98126 parser .add_argument ("posA" , choices = ["one" , "two" ])
0 commit comments