summaryrefslogtreecommitdiff
path: root/tests/test_commands.py
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2014-08-22 09:10:21 +0200
committerArmin Ronacher <armin.ronacher@active-4.com>2014-08-22 09:10:21 +0200
commit5fc29baf75897d594fe06ba085955d8068e22554 (patch)
tree0e5b2d9ccb5ba0884525be01ab13b455abddd4bd /tests/test_commands.py
parent04f795c3c726737a2fcecc8c65bd36a00a6d04ea (diff)
downloadclick-5fc29baf75897d594fe06ba085955d8068e22554.tar.gz
Fixed `invoked_subcommand`.
This is actually a very painful commit to make because it has to change behavior. On the bright side, this has actually been broken from 3.1 and people have not noticed much yet, so maybe it's not a big deal. The docs also kinda left out the invoked subcommands bit so I presume it is fine. This fixes #205
Diffstat (limited to 'tests/test_commands.py')
-rw-r--r--tests/test_commands.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/test_commands.py b/tests/test_commands.py
index 24118ed..7c8b453 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -229,3 +229,26 @@ def test_other_command_invoke_with_defaults(runner):
result = runner.invoke(cli, [])
assert not result.exception
assert result.output == '42\n'
+
+
+def test_invoked_subcommand(runner):
+ @click.group(invoke_without_command=True)
+ @click.pass_context
+ def cli(ctx):
+ if ctx.invoked_subcommand is None:
+ click.echo('no subcommand, use default')
+ ctx.invoke(sync)
+ else:
+ click.echo('invoke subcommand')
+
+ @cli.command()
+ def sync():
+ click.echo('in subcommand')
+
+ result = runner.invoke(cli, ['sync'])
+ assert not result.exception
+ assert result.output == 'invoke subcommand\nin subcommand\n'
+
+ result = runner.invoke(cli)
+ assert not result.exception
+ assert result.output == 'no subcommand, use default\nin subcommand\n'