Skip to content

Commit 5f72e7e

Browse files
committed
tests: add --prog, --prefix, tidy
1 parent db0df6f commit 5f72e7e

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

tests/test_shtab.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from shtab.main import get_main_parser, main
1515

1616
SUPPORTED_SHELLS = "bash", "zsh"
17+
fix_shell = pytest.mark.parametrize("shell", SUPPORTED_SHELLS)
1718

1819

1920
class 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
7475
def 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
82110
def 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
96124
def test_positional_choices(shell, caplog):
97125
parser = ArgumentParser(prog="test")
98126
parser.add_argument("posA", choices=["one", "two"])

0 commit comments

Comments
 (0)