diff options
author | David Lord <davidism@gmail.com> | 2020-03-06 13:50:04 -0800 |
---|---|---|
committer | David Lord <davidism@gmail.com> | 2020-03-06 13:50:04 -0800 |
commit | 93ba3ba112d2f8ba7bdd8b231e510f74dd0b037e (patch) | |
tree | 409b93ee7ec2209b9e52256ed77b0292f4e49720 /tests/test_context.py | |
parent | 488739dfe0d51f415c7b20466648cc519962ecbb (diff) | |
download | click-93ba3ba112d2f8ba7bdd8b231e510f74dd0b037e.tar.gz |
apply black
Diffstat (limited to 'tests/test_context.py')
-rw-r--r-- | tests/test_context.py | 73 |
1 files changed, 39 insertions, 34 deletions
diff --git a/tests/test_context.py b/tests/test_context.py index 35933be..4d131e7 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -5,7 +5,7 @@ import click def test_ensure_context_objects(runner): class Foo(object): def __init__(self): - self.title = 'default' + self.title = "default" pass_foo = click.make_pass_decorator(Foo, ensure=True) @@ -19,15 +19,15 @@ def test_ensure_context_objects(runner): def test(foo): click.echo(foo.title) - result = runner.invoke(cli, ['test']) + result = runner.invoke(cli, ["test"]) assert not result.exception - assert result.output == 'default\n' + assert result.output == "default\n" def test_get_context_objects(runner): class Foo(object): def __init__(self): - self.title = 'default' + self.title = "default" pass_foo = click.make_pass_decorator(Foo, ensure=True) @@ -35,22 +35,22 @@ def test_get_context_objects(runner): @click.pass_context def cli(ctx): ctx.obj = Foo() - ctx.obj.title = 'test' + ctx.obj.title = "test" @cli.command() @pass_foo def test(foo): click.echo(foo.title) - result = runner.invoke(cli, ['test']) + result = runner.invoke(cli, ["test"]) assert not result.exception - assert result.output == 'test\n' + assert result.output == "test\n" def test_get_context_objects_no_ensuring(runner): class Foo(object): def __init__(self): - self.title = 'default' + self.title = "default" pass_foo = click.make_pass_decorator(Foo) @@ -58,16 +58,16 @@ def test_get_context_objects_no_ensuring(runner): @click.pass_context def cli(ctx): ctx.obj = Foo() - ctx.obj.title = 'test' + ctx.obj.title = "test" @cli.command() @pass_foo def test(foo): click.echo(foo.title) - result = runner.invoke(cli, ['test']) + result = runner.invoke(cli, ["test"]) assert not result.exception - assert result.output == 'test\n' + assert result.output == "test\n" def test_get_context_objects_missing(runner): @@ -86,11 +86,13 @@ def test_get_context_objects_missing(runner): def test(foo): click.echo(foo.title) - result = runner.invoke(cli, ['test']) + result = runner.invoke(cli, ["test"]) assert result.exception is not None assert isinstance(result.exception, RuntimeError) - assert "Managed to invoke callback without a context object " \ + assert ( + "Managed to invoke callback without a context object " "of type 'Foo' existing" in str(result.exception) + ) def test_multi_enter(runner): @@ -101,6 +103,7 @@ def test_multi_enter(runner): def cli(ctx): def callback(): called.append(True) + ctx.call_on_close(callback) with ctx: @@ -117,8 +120,8 @@ def test_global_context_object(runner): @click.pass_context def cli(ctx): assert click.get_current_context() is ctx - ctx.obj = 'FOOBAR' - assert click.get_current_context().obj == 'FOOBAR' + ctx.obj = "FOOBAR" + assert click.get_current_context().obj == "FOOBAR" assert click.get_current_context(silent=True) is None runner.invoke(cli, [], catch_exceptions=False) @@ -126,20 +129,20 @@ def test_global_context_object(runner): def test_context_meta(runner): - LANG_KEY = __name__ + '.lang' + LANG_KEY = __name__ + ".lang" def set_language(value): click.get_current_context().meta[LANG_KEY] = value def get_language(): - return click.get_current_context().meta.get(LANG_KEY, 'en_US') + return click.get_current_context().meta.get(LANG_KEY, "en_US") @click.command() @click.pass_context def cli(ctx): - assert get_language() == 'en_US' - set_language('de_DE') - assert get_language() == 'de_DE' + assert get_language() == "en_US" + set_language("de_DE") + assert get_language() == "de_DE" runner.invoke(cli, [], catch_exceptions=False) @@ -174,16 +177,16 @@ def test_pass_obj(runner): @click.group() @click.pass_context def cli(ctx): - ctx.obj = 'test' + ctx.obj = "test" @cli.command() @click.pass_obj def test(obj): click.echo(obj) - result = runner.invoke(cli, ['test']) + result = runner.invoke(cli, ["test"]) assert not result.exception - assert result.output == 'test\n' + assert result.output == "test\n" def test_close_before_pop(runner): @@ -192,17 +195,18 @@ def test_close_before_pop(runner): @click.command() @click.pass_context def cli(ctx): - ctx.obj = 'test' + ctx.obj = "test" @ctx.call_on_close def foo(): - assert click.get_current_context().obj == 'test' + assert click.get_current_context().obj == "test" called.append(True) - click.echo('aha!') + + click.echo("aha!") result = runner.invoke(cli, []) assert not result.exception - assert result.output == 'aha!\n' + assert result.output == "aha!\n" assert called == [True] @@ -211,8 +215,9 @@ 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' + title = "foocmd" pass_foo = click.make_pass_decorator(Foo) @@ -233,13 +238,13 @@ def test_make_pass_decorator_args(runner): def test2(ctx, foo): click.echo(foo.title) - result = runner.invoke(cli, ['test1']) + result = runner.invoke(cli, ["test1"]) assert not result.exception - assert result.output == 'foocmd\n' + assert result.output == "foocmd\n" - result = runner.invoke(cli, ['test2']) + result = runner.invoke(cli, ["test2"]) assert not result.exception - assert result.output == 'foocmd\n' + assert result.output == "foocmd\n" def test_exit_not_standalone(): @@ -248,11 +253,11 @@ def test_exit_not_standalone(): def cli(ctx): ctx.exit(1) - assert cli.main([], 'test_exit_not_standalone', standalone_mode=False) == 1 + assert cli.main([], "test_exit_not_standalone", standalone_mode=False) == 1 @click.command() @click.pass_context def cli(ctx): ctx.exit(0) - assert cli.main([], 'test_exit_not_standalone', standalone_mode=False) == 0 + assert cli.main([], "test_exit_not_standalone", standalone_mode=False) == 0 |