summaryrefslogtreecommitdiff
path: root/tests/test_commands.py
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2020-03-06 13:50:04 -0800
committerDavid Lord <davidism@gmail.com>2020-03-06 13:50:04 -0800
commit93ba3ba112d2f8ba7bdd8b231e510f74dd0b037e (patch)
tree409b93ee7ec2209b9e52256ed77b0292f4e49720 /tests/test_commands.py
parent488739dfe0d51f415c7b20466648cc519962ecbb (diff)
downloadclick-93ba3ba112d2f8ba7bdd8b231e510f74dd0b037e.tar.gz
apply black
Diffstat (limited to 'tests/test_commands.py')
-rw-r--r--tests/test_commands.py168
1 files changed, 88 insertions, 80 deletions
diff --git a/tests/test_commands.py b/tests/test_commands.py
index aa96e71..d53b724 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -11,33 +11,33 @@ def test_other_command_invoke(runner):
return ctx.invoke(other_cmd, arg=42)
@click.command()
- @click.argument('arg', type=click.INT)
+ @click.argument("arg", type=click.INT)
def other_cmd(arg):
click.echo(arg)
result = runner.invoke(cli, [])
assert not result.exception
- assert result.output == '42\n'
+ assert result.output == "42\n"
def test_other_command_forward(runner):
cli = click.Group()
@cli.command()
- @click.option('--count', default=1)
+ @click.option("--count", default=1)
def test(count):
- click.echo('Count: %d' % count)
+ click.echo("Count: %d" % count)
@cli.command()
- @click.option('--count', default=1)
+ @click.option("--count", default=1)
@click.pass_context
def dist(ctx, count):
ctx.forward(test)
ctx.invoke(test, count=42)
- result = runner.invoke(cli, ['dist'])
+ result = runner.invoke(cli, ["dist"])
assert not result.exception
- assert result.output == 'Count: 1\nCount: 42\n'
+ assert result.output == "Count: 1\nCount: 42\n"
def test_auto_shorthelp(runner):
@@ -58,13 +58,17 @@ def test_auto_shorthelp(runner):
"""This is a long text that is too long to show as short help
and will be truncated instead."""
- result = runner.invoke(cli, ['--help'])
- assert re.search(
- r'Commands:\n\s+'
- r'long\s+This is a long text that is too long to show as short help\.\.\.\n\s+'
- r'short\s+This is a short text\.\n\s+'
- r'special-chars\s+Login and store the token in ~/.netrc\.\s*',
- result.output) is not None
+ result = runner.invoke(cli, ["--help"])
+ assert (
+ re.search(
+ r"Commands:\n\s+"
+ r"long\s+This is a long text that is too long to show as short help\.\.\.\n\s+"
+ r"short\s+This is a short text\.\n\s+"
+ r"special-chars\s+Login and store the token in ~/.netrc\.\s*",
+ result.output,
+ )
+ is not None
+ )
def test_no_args_is_help(runner):
@@ -74,7 +78,7 @@ def test_no_args_is_help(runner):
result = runner.invoke(cli, [])
assert result.exit_code == 0
- assert 'Show this message and exit.' in result.output
+ assert "Show this message and exit." in result.output
def test_default_maps(runner):
@@ -83,43 +87,41 @@ def test_default_maps(runner):
pass
@cli.command()
- @click.option('--name', default='normal')
+ @click.option("--name", default="normal")
def foo(name):
click.echo(name)
- result = runner.invoke(cli, ['foo'], default_map={
- 'foo': {'name': 'changed'}
- })
+ result = runner.invoke(cli, ["foo"], default_map={"foo": {"name": "changed"}})
assert not result.exception
- assert result.output == 'changed\n'
+ assert result.output == "changed\n"
def test_group_with_args(runner):
@click.group()
- @click.argument('obj')
+ @click.argument("obj")
def cli(obj):
- click.echo('obj=%s' % obj)
+ click.echo("obj=%s" % obj)
@cli.command()
def move():
- click.echo('move')
+ click.echo("move")
result = runner.invoke(cli, [])
assert result.exit_code == 0
- assert 'Show this message and exit.' in result.output
+ assert "Show this message and exit." in result.output
- result = runner.invoke(cli, ['obj1'])
+ result = runner.invoke(cli, ["obj1"])
assert result.exit_code == 2
- assert 'Error: Missing command.' in result.output
+ assert "Error: Missing command." in result.output
- result = runner.invoke(cli, ['obj1', '--help'])
+ result = runner.invoke(cli, ["obj1", "--help"])
assert result.exit_code == 0
- assert 'Show this message and exit.' in result.output
+ assert "Show this message and exit." in result.output
- result = runner.invoke(cli, ['obj1', 'move'])
+ result = runner.invoke(cli, ["obj1", "move"])
assert result.exit_code == 0
- assert result.output == 'obj=obj1\nmove\n'
+ assert result.output == "obj=obj1\nmove\n"
def test_base_command(runner):
@@ -130,7 +132,6 @@ def test_base_command(runner):
pass
class OptParseCommand(click.BaseCommand):
-
def __init__(self, name, parser, callback):
click.BaseCommand.__init__(self, name)
self.parser = parser
@@ -153,58 +154,67 @@ def test_base_command(runner):
def invoke(self, ctx):
ctx.invoke(self.callback, ctx.args, **ctx.params)
- parser = optparse.OptionParser(usage='Usage: foo test [OPTIONS]')
- parser.add_option("-f", "--file", dest="filename",
- help="write report to FILE", metavar="FILE")
- parser.add_option("-q", "--quiet",
- action="store_false", dest="verbose", default=True,
- help="don't print status messages to stdout")
+ parser = optparse.OptionParser(usage="Usage: foo test [OPTIONS]")
+ parser.add_option(
+ "-f", "--file", dest="filename", help="write report to FILE", metavar="FILE"
+ )
+ parser.add_option(
+ "-q",
+ "--quiet",
+ action="store_false",
+ dest="verbose",
+ default=True,
+ help="don't print status messages to stdout",
+ )
def test_callback(args, filename, verbose):
- click.echo(' '.join(args))
+ click.echo(" ".join(args))
click.echo(filename)
click.echo(verbose)
- cli.add_command(OptParseCommand('test', parser, test_callback))
- result = runner.invoke(cli, ['test', '-f', 'test.txt', '-q',
- 'whatever.txt', 'whateverelse.txt'])
+ cli.add_command(OptParseCommand("test", parser, test_callback))
+
+ result = runner.invoke(
+ cli, ["test", "-f", "test.txt", "-q", "whatever.txt", "whateverelse.txt"]
+ )
assert not result.exception
assert result.output.splitlines() == [
- 'whatever.txt whateverelse.txt',
- 'test.txt',
- 'False',
+ "whatever.txt whateverelse.txt",
+ "test.txt",
+ "False",
]
- result = runner.invoke(cli, ['test', '--help'])
+ result = runner.invoke(cli, ["test", "--help"])
assert not result.exception
assert result.output.splitlines() == [
- 'Usage: foo test [OPTIONS]',
- '',
- 'Options:',
- ' -h, --help show this help message and exit',
- ' -f FILE, --file=FILE write report to FILE',
- ' -q, --quiet don\'t print status messages to stdout',
+ "Usage: foo test [OPTIONS]",
+ "",
+ "Options:",
+ " -h, --help show this help message and exit",
+ " -f FILE, --file=FILE write report to FILE",
+ " -q, --quiet don't print status messages to stdout",
]
def test_object_propagation(runner):
for chain in False, True:
+
@click.group(chain=chain)
- @click.option('--debug/--no-debug', default=False)
+ @click.option("--debug/--no-debug", default=False)
@click.pass_context
def cli(ctx, debug):
if ctx.obj is None:
ctx.obj = {}
- ctx.obj['DEBUG'] = debug
+ ctx.obj["DEBUG"] = debug
@cli.command()
@click.pass_context
def sync(ctx):
- click.echo('Debug is %s' % (ctx.obj['DEBUG'] and 'on' or 'off'))
+ click.echo("Debug is %s" % (ctx.obj["DEBUG"] and "on" or "off"))
- result = runner.invoke(cli, ['sync'])
+ result = runner.invoke(cli, ["sync"])
assert result.exception is None
- assert result.output == 'Debug is off\n'
+ assert result.output == "Debug is off\n"
def test_other_command_invoke_with_defaults(runner):
@@ -214,15 +224,15 @@ def test_other_command_invoke_with_defaults(runner):
return ctx.invoke(other_cmd)
@click.command()
- @click.option('--foo', type=click.INT, default=42)
+ @click.option("--foo", type=click.INT, default=42)
@click.pass_context
def other_cmd(ctx, foo):
- assert ctx.info_name == 'other-cmd'
+ assert ctx.info_name == "other-cmd"
click.echo(foo)
result = runner.invoke(cli, [])
assert not result.exception
- assert result.output == '42\n'
+ assert result.output == "42\n"
def test_invoked_subcommand(runner):
@@ -230,39 +240,37 @@ def test_invoked_subcommand(runner):
@click.pass_context
def cli(ctx):
if ctx.invoked_subcommand is None:
- click.echo('no subcommand, use default')
+ click.echo("no subcommand, use default")
ctx.invoke(sync)
else:
- click.echo('invoke subcommand')
+ click.echo("invoke subcommand")
@cli.command()
def sync():
- click.echo('in subcommand')
+ click.echo("in subcommand")
- result = runner.invoke(cli, ['sync'])
+ result = runner.invoke(cli, ["sync"])
assert not result.exception
- assert result.output == 'invoke subcommand\nin subcommand\n'
+ 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'
+ assert result.output == "no subcommand, use default\nin subcommand\n"
def test_unprocessed_options(runner):
- @click.command(context_settings=dict(
- ignore_unknown_options=True
- ))
- @click.argument('args', nargs=-1, type=click.UNPROCESSED)
- @click.option('--verbose', '-v', count=True)
+ @click.command(context_settings=dict(ignore_unknown_options=True))
+ @click.argument("args", nargs=-1, type=click.UNPROCESSED)
+ @click.option("--verbose", "-v", count=True)
def cli(verbose, args):
- click.echo('Verbosity: %s' % verbose)
- click.echo('Args: %s' % '|'.join(args))
+ click.echo("Verbosity: %s" % verbose)
+ click.echo("Args: %s" % "|".join(args))
- result = runner.invoke(cli, ['-foo', '-vvvvx', '--muhaha', 'x', 'y', '-x'])
+ result = runner.invoke(cli, ["-foo", "-vvvvx", "--muhaha", "x", "y", "-x"])
assert not result.exception
assert result.output.splitlines() == [
- 'Verbosity: 4',
- 'Args: -foo|-x|--muhaha|x|y|-x',
+ "Verbosity: 4",
+ "Args: -foo|-x|--muhaha|x|y|-x",
]
@@ -272,15 +280,15 @@ def test_deprecated_in_help_messages(runner):
"""CLI HELP"""
pass
- result = runner.invoke(cmd_with_help, ['--help'])
- assert '(DEPRECATED)' in result.output
+ result = runner.invoke(cmd_with_help, ["--help"])
+ assert "(DEPRECATED)" in result.output
@click.command(deprecated=True)
def cmd_without_help():
pass
- result = runner.invoke(cmd_without_help, ['--help'])
- assert '(DEPRECATED)' in result.output
+ result = runner.invoke(cmd_without_help, ["--help"])
+ assert "(DEPRECATED)" in result.output
def test_deprecated_in_invocation(runner):
@@ -289,4 +297,4 @@ def test_deprecated_in_invocation(runner):
debug()
result = runner.invoke(deprecated_cmd)
- assert 'DeprecationWarning:' in result.output
+ assert "DeprecationWarning:" in result.output