summaryrefslogtreecommitdiff
path: root/tests/test_context.py
diff options
context:
space:
mode:
authorStephen Rosen <sirosen@globus.org>2018-08-11 02:00:34 +0000
committerStephen Rosen <sirosen@globus.org>2018-08-11 02:01:18 +0000
commit0aeb6df39f0c343189625035d9a54a5f9c8da730 (patch)
tree8abc54bd0bbb4cffd26853e7fe2e78276479e230 /tests/test_context.py
parent206976869afe314646c9adbd243dd6108ba434ba (diff)
downloadclick-0aeb6df39f0c343189625035d9a54a5f9c8da730.tar.gz
Add test for make_pass_decorator arg handling
This adds a simple test case which ensures that `make_pass_decorator` doesn't consume arguments if it's called out of order.
Diffstat (limited to 'tests/test_context.py')
-rw-r--r--tests/test_context.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/test_context.py b/tests/test_context.py
index cbf9b98..3b07cc8 100644
--- a/tests/test_context.py
+++ b/tests/test_context.py
@@ -203,3 +203,39 @@ def test_close_before_pop(runner):
assert not result.exception
assert result.output == 'aha!\n'
assert called == [True]
+
+
+def test_make_pass_decorator_args(runner):
+ """
+ Test to check that make_pass_decorator doesn't consume arguments based on
+ invocation order.
+ """
+ class Foo(object):
+ title = 'foocmd'
+
+ pass_foo = click.make_pass_decorator(Foo)
+
+ @click.group()
+ @click.pass_context
+ def cli(ctx):
+ ctx.obj = Foo()
+
+ @cli.command()
+ @click.pass_context
+ @pass_foo
+ def test1(foo, ctx):
+ click.echo(foo.title)
+
+ @cli.command()
+ @pass_foo
+ @click.pass_context
+ def test2(ctx, foo):
+ click.echo(foo.title)
+
+ result = runner.invoke(cli, ['test1'])
+ assert not result.exception
+ assert result.output == 'foocmd\n'
+
+ result = runner.invoke(cli, ['test2'])
+ assert not result.exception
+ assert result.output == 'foocmd\n'