Skip to content

Commit

Permalink
'Refactored by Sourcery'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcery AI committed Nov 18, 2022
1 parent 3b16403 commit 626061d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions shtab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ def recurse(parser, prefix):
new_nargs,
) = recurse(
positional.choices[choice],
prefix + "_" + wordify(choice),
f"{prefix}_{wordify(choice)}",
)

sub_subparsers.extend(new_subparsers)
sub_option_strings.extend(new_option_strings)
sub_compgens.extend(new_compgens)
Expand Down Expand Up @@ -541,7 +542,7 @@ def recurse(parser, prefix, paths=None):
format_positional(opt) for opt in subparser._get_positional_actions()
if not isinstance(opt.choices, dict) if opt.help != SUPPRESS)

new_pref = prefix + "_" + wordify(cmd)
new_pref = f"{prefix}_{wordify(cmd)}"
options = all_commands[new_pref] = {
"cmd": cmd, "help": (subparser.description or "").strip().split("\n")[0],
"arguments": arguments, "paths": [*paths, cmd]}
Expand Down
11 changes: 7 additions & 4 deletions tests/test_shtab.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ def test(self, cmd="1", failure_message=""):
proc = subprocess.Popen([
"bash", "-o", "pipefail", "-ec", "{init}[[ {cmd} ]]".format(init=init, cmd=cmd)])
stdout, stderr = proc.communicate()
assert (0 == proc.wait() and not stdout and not stderr), """\
assert (
proc.wait() == 0 and not stdout and not stderr
), """\
{}
{}
=== stdout ===
{}=== stderr ===
{}""".format(failure_message, cmd, stdout or "", stderr or "")
{}""".format(
failure_message, cmd, stdout or "", stderr or ""
)

def compgen(self, compgen_cmd, word, expected_completions, failure_message=""):
self.test(
'"$(echo $(compgen {} -- "{}"))" = "{}"'.format(compgen_cmd, word,
expected_completions),
f'"$(echo $(compgen {compgen_cmd} -- "{word}"))" = "{expected_completions}"',
failure_message,
)

Expand Down

0 comments on commit 626061d

Please sign in to comment.