Skip to content

Commit

Permalink
bump version, merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Jul 29, 2020
2 parents 2a4b038 + 03824bd commit 34dfa38
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 3 additions & 2 deletions shtab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ def recurse(parser, prefix):
),
file=fd,
)
else:
assert isinstance(sub.choices, dict)
elif isinstance(sub.choices, dict):
log.debug("subcommand:%s", cmd)
if sub.choices[cmd].add_help:
commands.append(cmd)
Expand All @@ -215,6 +214,8 @@ def recurse(parser, prefix):
)
else:
log.debug("skip:subcommand:%s", cmd)
else:
commands.append(cmd)
else:
log.debug("uncompletable:{}:{}".format(prefix, sub.dest))

Expand Down
20 changes: 18 additions & 2 deletions tests/test_shtab.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""
import logging
import subprocess
from argparse import ArgumentParser

import pytest

Expand Down Expand Up @@ -69,6 +70,14 @@ def test_choices():
assert "" not in shtab.Required.FILE


@pytest.mark.parametrize("shell", SUPPORTED_SHELLS)
def test_main(shell, caplog):
with caplog.at_level(logging.INFO):
main(["-s", shell, "shtab.main.get_main_parser"])

assert not caplog.record_tuples


@pytest.mark.parametrize("shell", SUPPORTED_SHELLS)
def test_complete(shell, caplog):
parser = get_main_parser()
Expand All @@ -84,8 +93,15 @@ def test_complete(shell, caplog):


@pytest.mark.parametrize("shell", SUPPORTED_SHELLS)
def test_main(shell, caplog):
def test_positional_choices(shell, caplog):
parser = ArgumentParser(prog="test")
parser.add_argument("posA", choices=["one", "two"])
with caplog.at_level(logging.INFO):
main(["-s", shell, "shtab.main.get_main_parser"])
completion = shtab.complete(parser, shell=shell)
print(completion)

if shell == "bash":
shell = Bash(completion)
shell.compgen('-W "$_shtab_test_commands_"', "o", "one")

assert not caplog.record_tuples

0 comments on commit 34dfa38

Please sign in to comment.