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_formatting.py | |
| parent | 488739dfe0d51f415c7b20466648cc519962ecbb (diff) | |
| download | click-93ba3ba112d2f8ba7bdd8b231e510f74dd0b037e.tar.gz | |
apply black
Diffstat (limited to 'tests/test_formatting.py')
| -rw-r--r-- | tests/test_formatting.py | 264 |
1 files changed, 133 insertions, 131 deletions
diff --git a/tests/test_formatting.py b/tests/test_formatting.py index e4d2571..30ab288 100644 --- a/tests/test_formatting.py +++ b/tests/test_formatting.py @@ -25,28 +25,28 @@ def test_basic_functionality(runner): that will be rewrapped again. """ - result = runner.invoke(cli, ['--help'], terminal_width=60) + result = runner.invoke(cli, ["--help"], terminal_width=60) assert not result.exception assert result.output.splitlines() == [ - 'Usage: cli [OPTIONS]', - '', - ' First paragraph.', - '', - ' This is a very long second paragraph and not correctly', - ' wrapped but it will be rewrapped.', - '', - ' This is', - ' a paragraph', - ' without rewrapping.', - '', - ' 1', - ' 2', - ' 3', - '', - ' And this is a paragraph that will be rewrapped again.', - '', - 'Options:', - ' --help Show this message and exit.', + "Usage: cli [OPTIONS]", + "", + " First paragraph.", + "", + " This is a very long second paragraph and not correctly", + " wrapped but it will be rewrapped.", + "", + " This is", + " a paragraph", + " without rewrapping.", + "", + " 1", + " 2", + " 3", + "", + " And this is a paragraph that will be rewrapped again.", + "", + "Options:", + " --help Show this message and exit.", ] @@ -62,30 +62,29 @@ def test_wrapping_long_options_strings(runner): """ @a_very_long.command() - @click.argument('first') - @click.argument('second') - @click.argument('third') - @click.argument('fourth') - @click.argument('fifth') - @click.argument('sixth') + @click.argument("first") + @click.argument("second") + @click.argument("third") + @click.argument("fourth") + @click.argument("fifth") + @click.argument("sixth") def command(): """A command. """ # 54 is chosen as a length where the second line is one character # longer than the maximum length. - result = runner.invoke(cli, ['a-very-long', 'command', '--help'], - terminal_width=54) + result = runner.invoke(cli, ["a-very-long", "command", "--help"], terminal_width=54) assert not result.exception assert result.output.splitlines() == [ - 'Usage: cli a-very-long command [OPTIONS] FIRST SECOND', - ' THIRD FOURTH FIFTH', - ' SIXTH', - '', - ' A command.', - '', - 'Options:', - ' --help Show this message and exit.', + "Usage: cli a-very-long command [OPTIONS] FIRST SECOND", + " THIRD FOURTH FIFTH", + " SIXTH", + "", + " A command.", + "", + "Options:", + " --help Show this message and exit.", ] @@ -101,28 +100,29 @@ def test_wrapping_long_command_name(runner): """ @a_very_very_very_long.command() - @click.argument('first') - @click.argument('second') - @click.argument('third') - @click.argument('fourth') - @click.argument('fifth') - @click.argument('sixth') + @click.argument("first") + @click.argument("second") + @click.argument("third") + @click.argument("fourth") + @click.argument("fifth") + @click.argument("sixth") def command(): """A command. """ - result = runner.invoke(cli, ['a-very-very-very-long', 'command', '--help'], - terminal_width=54) + result = runner.invoke( + cli, ["a-very-very-very-long", "command", "--help"], terminal_width=54 + ) assert not result.exception assert result.output.splitlines() == [ - 'Usage: cli a-very-very-very-long command ', - ' [OPTIONS] FIRST SECOND THIRD FOURTH FIFTH', - ' SIXTH', - '', - ' A command.', - '', - 'Options:', - ' --help Show this message and exit.', + "Usage: cli a-very-very-very-long command ", + " [OPTIONS] FIRST SECOND THIRD FOURTH FIFTH", + " SIXTH", + "", + " A command.", + "", + "Options:", + " --help Show this message and exit.", ] @@ -133,33 +133,33 @@ def test_formatting_empty_help_lines(runner): """ - result = runner.invoke(cli, ['--help']) + result = runner.invoke(cli, ["--help"]) assert not result.exception assert result.output.splitlines() == [ - 'Usage: cli [OPTIONS]', - '', - ' Top level command', - '', - '', - '', - 'Options:', - ' --help Show this message and exit.', + "Usage: cli [OPTIONS]", + "", + " Top level command", + "", + "", + "", + "Options:", + " --help Show this message and exit.", ] def test_formatting_usage_error(runner): @click.command() - @click.argument('arg') + @click.argument("arg") def cmd(arg): - click.echo('arg:' + arg) + click.echo("arg:" + arg) result = runner.invoke(cmd, []) assert result.exit_code == 2 assert result.output.splitlines() == [ - 'Usage: cmd [OPTIONS] ARG', + "Usage: cmd [OPTIONS] ARG", 'Try "cmd --help" for help.', - '', - 'Error: Missing argument "ARG".' + "", + 'Error: Missing argument "ARG".', ] @@ -168,34 +168,35 @@ def test_formatting_usage_error_metavar_missing_arg(runner): :author: @r-m-n Including attribution to #612 """ + @click.command() - @click.argument('arg', metavar='metavar') + @click.argument("arg", metavar="metavar") def cmd(arg): pass result = runner.invoke(cmd, []) assert result.exit_code == 2 assert result.output.splitlines() == [ - 'Usage: cmd [OPTIONS] metavar', + "Usage: cmd [OPTIONS] metavar", 'Try "cmd --help" for help.', - '', - 'Error: Missing argument "metavar".' + "", + 'Error: Missing argument "metavar".', ] def test_formatting_usage_error_metavar_bad_arg(runner): @click.command() - @click.argument('arg', type=click.INT, metavar='metavar') + @click.argument("arg", type=click.INT, metavar="metavar") def cmd(arg): pass - result = runner.invoke(cmd, ['3.14']) + result = runner.invoke(cmd, ["3.14"]) assert result.exit_code == 2 assert result.output.splitlines() == [ - 'Usage: cmd [OPTIONS] metavar', + "Usage: cmd [OPTIONS] metavar", 'Try "cmd --help" for help.', - '', - 'Error: Invalid value for "metavar": 3.14 is not a valid integer' + "", + 'Error: Invalid value for "metavar": 3.14 is not a valid integer', ] @@ -205,50 +206,51 @@ def test_formatting_usage_error_nested(runner): pass @cmd.command() - @click.argument('bar') + @click.argument("bar") def foo(bar): - click.echo('foo:' + bar) + click.echo("foo:" + bar) - result = runner.invoke(cmd, ['foo']) + result = runner.invoke(cmd, ["foo"]) assert result.exit_code == 2 assert result.output.splitlines() == [ - 'Usage: cmd foo [OPTIONS] BAR', + "Usage: cmd foo [OPTIONS] BAR", 'Try "cmd foo --help" for help.', - '', - 'Error: Missing argument "BAR".' + "", + 'Error: Missing argument "BAR".', ] def test_formatting_usage_error_no_help(runner): @click.command(add_help_option=False) - @click.argument('arg') + @click.argument("arg") def cmd(arg): - click.echo('arg:' + arg) + click.echo("arg:" + arg) result = runner.invoke(cmd, []) assert result.exit_code == 2 assert result.output.splitlines() == [ - 'Usage: cmd [OPTIONS] ARG', - '', - 'Error: Missing argument "ARG".' + "Usage: cmd [OPTIONS] ARG", + "", + 'Error: Missing argument "ARG".', ] def test_formatting_usage_custom_help(runner): - @click.command(context_settings=dict(help_option_names=['--man'])) - @click.argument('arg') + @click.command(context_settings=dict(help_option_names=["--man"])) + @click.argument("arg") def cmd(arg): - click.echo('arg:' + arg) + click.echo("arg:" + arg) result = runner.invoke(cmd, []) assert result.exit_code == 2 assert result.output.splitlines() == [ - 'Usage: cmd [OPTIONS] ARG', + "Usage: cmd [OPTIONS] ARG", 'Try "cmd --man" for help.', - '', - 'Error: Missing argument "ARG".' + "", + 'Error: Missing argument "ARG".', ] + def test_formatting_custom_type_metavar(runner): class MyType(click.ParamType): def get_metavar(self, param): @@ -260,13 +262,13 @@ def test_formatting_custom_type_metavar(runner): def cmd(param): pass - result = runner.invoke(cmd, '--help') + result = runner.invoke(cmd, "--help") assert not result.exception assert result.output.splitlines() == [ - 'Usage: foo [OPTIONS] MY_TYPE', - '', - 'Options:', - ' --help Show this message and exit.' + "Usage: foo [OPTIONS] MY_TYPE", + "", + "Options:", + " --help Show this message and exit.", ] @@ -284,18 +286,18 @@ def test_truncating_docstring(runner): :param click.core.Context ctx: Click context. """ - result = runner.invoke(cli, ['--help'], terminal_width=60) + result = runner.invoke(cli, ["--help"], terminal_width=60) assert not result.exception assert result.output.splitlines() == [ - 'Usage: cli [OPTIONS]', - '', - ' First paragraph.', - '', - ' This is a very long second paragraph and not correctly', - ' wrapped but it will be rewrapped.', - '', - 'Options:', - ' --help Show this message and exit.', + "Usage: cli [OPTIONS]", + "", + " First paragraph.", + "", + " This is a very long second paragraph and not correctly", + " wrapped but it will be rewrapped.", + "", + "Options:", + " --help Show this message and exit.", ] @@ -305,47 +307,47 @@ def test_global_show_default(runner): def cli(): pass - result = runner.invoke(cli, ['--help'],) + result = runner.invoke(cli, ["--help"],) assert result.output.splitlines() == [ - 'Usage: cli [OPTIONS]', - '', - 'Options:', - ' -f TEXT Output file name [default: out.txt]', - ' --help Show this message and exit. [default: False]' + "Usage: cli [OPTIONS]", + "", + "Options:", + " -f TEXT Output file name [default: out.txt]", + " --help Show this message and exit. [default: False]", ] def test_formatting_usage_multiline_option_padding(runner): - @click.command('foo') - @click.option('--bar', help='This help message will be padded if it wraps.') + @click.command("foo") + @click.option("--bar", help="This help message will be padded if it wraps.") def cli(): pass - result = runner.invoke(cli, '--help', terminal_width=45) + result = runner.invoke(cli, "--help", terminal_width=45) assert not result.exception assert result.output.splitlines() == [ - 'Usage: foo [OPTIONS]', - '', - 'Options:', - ' --bar TEXT This help message will be', - ' padded if it wraps.', - '', - ' --help Show this message and exit.' + "Usage: foo [OPTIONS]", + "", + "Options:", + " --bar TEXT This help message will be", + " padded if it wraps.", + "", + " --help Show this message and exit.", ] def test_formatting_usage_no_option_padding(runner): - @click.command('foo') - @click.option('--bar', help='This help message will be padded if it wraps.') + @click.command("foo") + @click.option("--bar", help="This help message will be padded if it wraps.") def cli(): pass - result = runner.invoke(cli, '--help', terminal_width=80) + result = runner.invoke(cli, "--help", terminal_width=80) assert not result.exception assert result.output.splitlines() == [ - 'Usage: foo [OPTIONS]', - '', - 'Options:', - ' --bar TEXT This help message will be padded if it wraps.', - ' --help Show this message and exit.' + "Usage: foo [OPTIONS]", + "", + "Options:", + " --bar TEXT This help message will be padded if it wraps.", + " --help Show this message and exit.", ] |
