test_formatting.py
This file
Path
tests/test_formatting.py
352 lines · 8.8 KiB · Python
Last changed by
Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
History of this fileTake it
The walk stopped after 200 commits: lines older than 5210849 point at it.
Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 1–26why, one step back1import click234def test_basic_functionality(runner):5 @click.command()6 def cli():7 """First paragraph.89 This is a very long second10 paragraph and not correctly11 wrapped but it will be rewrapped.1213 \b14 This is15 a paragraph16 without rewrapping.1718 \b19 120 221 32223 And this is a paragraph24 that will be rewrapped again.25 """26Merge branch '7.x'David Lordbefore adoption7239794
line 27why, one step back27 result = runner.invoke(cli, ["--help"], terminal_width=60)Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 28–29why, one step back28 assert not result.exception29 assert result.output.splitlines() == [Merge branch '7.x'David Lordbefore adoption7239794
lines 30–48why, one step back30 "Usage: cli [OPTIONS]",31 "",32 " First paragraph.",33 "",34 " This is a very long second paragraph and not correctly",35 " wrapped but it will be rewrapped.",36 "",37 " This is",38 " a paragraph",39 " without rewrapping.",40 "",41 " 1",42 " 2",43 " 3",44 "",45 " And this is a paragraph that will be rewrapped again.",46 "",47 "Options:",48 " --help Show this message and exit.",Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 49–63why, one step back49 ]505152def test_wrapping_long_options_strings(runner):53 @click.group()54 def cli():55 """Top level command56 """5758 @cli.group()59 def a_very_long():60 """Second level61 """6263 @a_very_long.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 64–69why, one step back64 @click.argument("first")65 @click.argument("second")66 @click.argument("third")67 @click.argument("fourth")68 @click.argument("fifth")69 @click.argument("sixth")Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 70–75why, one step back70 def command():71 """A command.72 """7374 # 54 is chosen as a length where the second line is one character75 # longer than the maximum length.Merge branch '7.x'David Lordbefore adoption7239794
line 76why, one step back76 result = runner.invoke(cli, ["a-very-long", "command", "--help"], terminal_width=54)Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 77–78why, one step back77 assert not result.exception78 assert result.output.splitlines() == [Merge branch '7.x'David Lordbefore adoption7239794
lines 79–86why, one step back79 "Usage: cli a-very-long command [OPTIONS] FIRST SECOND",80 " THIRD FOURTH FIFTH",81 " SIXTH",82 "",83 " A command.",84 "",85 "Options:",86 " --help Show this message and exit.",Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 87–101why, one step back87 ]888990def test_wrapping_long_command_name(runner):91 @click.group()92 def cli():93 """Top level command94 """9596 @cli.group()97 def a_very_very_very_long():98 """Second level99 """100101 @a_very_very_very_long.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 102–107why, one step back102 @click.argument("first")103 @click.argument("second")104 @click.argument("third")105 @click.argument("fourth")106 @click.argument("fifth")107 @click.argument("sixth")Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 108–111why, one step back108 def command():109 """A command.110 """111Merge branch '7.x'David Lordbefore adoption7239794
lines 112–114why, one step back112 result = runner.invoke(113 cli, ["a-very-very-very-long", "command", "--help"], terminal_width=54114 )Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 115–116why, one step back115 assert not result.exception116 assert result.output.splitlines() == [Merge branch '7.x'David Lordbefore adoption7239794
lines 117–124why, one step back117 "Usage: cli a-very-very-very-long command ",118 " [OPTIONS] FIRST SECOND THIRD FOURTH FIFTH",119 " SIXTH",120 "",121 " A command.",122 "",123 "Options:",124 " --help Show this message and exit.",Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 125–134why, one step back125 ]126127128def test_formatting_empty_help_lines(runner):129 @click.command()130 def cli():131 """Top level command132133 """134Merge branch '7.x'David Lordbefore adoption7239794
line 135why, one step back135 result = runner.invoke(cli, ["--help"])Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 136–137why, one step back136 assert not result.exception137 assert result.output.splitlines() == [Merge branch '7.x'David Lordbefore adoption7239794
lines 138–145why, one step back138 "Usage: cli [OPTIONS]",139 "",140 " Top level command",141 "",142 "",143 "",144 "Options:",145 " --help Show this message and exit.",Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 146–150why, one step back146 ]147148149def test_formatting_usage_error(runner):150 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 151why, one step back151 @click.argument("arg")Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 152why, one step back152 def cmd(arg):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 153why, one step back153 click.echo(f"arg:{arg}")Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 154–157why, one step back154155 result = runner.invoke(cmd, [])156 assert result.exit_code == 2157 assert result.output.splitlines() == [Merge branch '7.x'David Lordbefore adoption7239794
lines 158–161why, one step back158 "Usage: cmd [OPTIONS] ARG",159 "Try 'cmd --help' for help.",160 "",161 "Error: Missing argument 'ARG'.",Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 162–164why, one step back162 ]163164Merge pull request #709 from sirosen/bugfix/error-hints/let-param-decideLokiHokiebefore adoption3cb9973
lines 165–169why, one step back165def test_formatting_usage_error_metavar_missing_arg(runner):166 """167 :author: @r-m-n168 Including attribution to #612169 """Merge branch '7.x'David Lordbefore adoption7239794
line 170why, one step back170Merge pull request #709 from sirosen/bugfix/error-hints/let-param-decideLokiHokiebefore adoption3cb9973
line 171why, one step back171 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 172why, one step back172 @click.argument("arg", metavar="metavar")Merge pull request #709 from sirosen/bugfix/error-hints/let-param-decideLokiHokiebefore adoption3cb9973
lines 173–178why, one step back173 def cmd(arg):174 pass175176 result = runner.invoke(cmd, [])177 assert result.exit_code == 2178 assert result.output.splitlines() == [Merge branch '7.x'David Lordbefore adoption7239794
lines 179–182why, one step back179 "Usage: cmd [OPTIONS] metavar",180 "Try 'cmd --help' for help.",181 "",182 "Error: Missing argument 'metavar'.",Merge pull request #709 from sirosen/bugfix/error-hints/let-param-decideLokiHokiebefore adoption3cb9973
lines 183–187why, one step back183 ]184185186def test_formatting_usage_error_metavar_bad_arg(runner):187 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 188why, one step back188 @click.argument("arg", type=click.INT, metavar="metavar")Merge pull request #709 from sirosen/bugfix/error-hints/let-param-decideLokiHokiebefore adoption3cb9973
lines 189–191why, one step back189 def cmd(arg):190 pass191Merge branch '7.x'David Lordbefore adoption7239794
line 192why, one step back192 result = runner.invoke(cmd, ["3.14"])Merge pull request #709 from sirosen/bugfix/error-hints/let-param-decideLokiHokiebefore adoption3cb9973
lines 193–194why, one step back193 assert result.exit_code == 2194 assert result.output.splitlines() == [Merge branch '7.x'David Lordbefore adoption7239794
lines 195–198why, one step back195 "Usage: cmd [OPTIONS] metavar",196 "Try 'cmd --help' for help.",197 "",198 "Error: Invalid value for 'metavar': 3.14 is not a valid integer",Merge pull request #709 from sirosen/bugfix/error-hints/let-param-decideLokiHokiebefore adoption3cb9973
lines 199–201why, one step back199 ]200201Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 202–207why, one step back202def test_formatting_usage_error_nested(runner):203 @click.group()204 def cmd():205 pass206207 @cmd.command()Merge branch '7.x'David Lordbefore adoption7239794
line 208why, one step back208 @click.argument("bar")Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 209why, one step back209 def foo(bar):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 210why, one step back210 click.echo(f"foo:{bar}")Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 211why, one step back211Merge branch '7.x'David Lordbefore adoption7239794
line 212why, one step back212 result = runner.invoke(cmd, ["foo"])Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 213–214why, one step back213 assert result.exit_code == 2214 assert result.output.splitlines() == [Merge branch '7.x'David Lordbefore adoption7239794
lines 215–218why, one step back215 "Usage: cmd foo [OPTIONS] BAR",216 "Try 'cmd foo --help' for help.",217 "",218 "Error: Missing argument 'BAR'.",Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 219–223why, one step back219 ]220221222def test_formatting_usage_error_no_help(runner):223 @click.command(add_help_option=False)Merge branch '7.x'David Lordbefore adoption7239794
line 224why, one step back224 @click.argument("arg")Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 225why, one step back225 def cmd(arg):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 226why, one step back226 click.echo(f"arg:{arg}")Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 227–230why, one step back227228 result = runner.invoke(cmd, [])229 assert result.exit_code == 2230 assert result.output.splitlines() == [Merge branch '7.x'David Lordbefore adoption7239794
lines 231–233why, one step back231 "Usage: cmd [OPTIONS] ARG",232 "",233 "Error: Missing argument 'ARG'.",Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 234–237why, one step back234 ]235236237def test_formatting_usage_custom_help(runner):Merge branch '7.x'David Lordbefore adoption7239794
lines 238–239why, one step back238 @click.command(context_settings=dict(help_option_names=["--man"]))239 @click.argument("arg")Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 240why, one step back240 def cmd(arg):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 241why, one step back241 click.echo(f"arg:{arg}")Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
lines 242–245why, one step back242243 result = runner.invoke(cmd, [])244 assert result.exit_code == 2245 assert result.output.splitlines() == [Merge branch '7.x'David Lordbefore adoption7239794
lines 246–249why, one step back246 "Usage: cmd [OPTIONS] ARG",247 "Try 'cmd --man' for help.",248 "",249 "Error: Missing argument 'ARG'.",Merge pull request #806 from stopthatcow/feature/790Markus Unterwaditzerbefore adoption5210849
line 250why, one step back250 ]Merge pull request #1001 from pallets/metavar_testJosiahDubbefore adoptionbd59717
line 251why, one step back251Merge branch '7.x'David Lordbefore adoption7239794
line 252why, one step back252Merge pull request #1001 from pallets/metavar_testJosiahDubbefore adoptionbd59717
lines 253–263why, one step back253def test_formatting_custom_type_metavar(runner):254 class MyType(click.ParamType):255 def get_metavar(self, param):256 return "MY_TYPE"257258 @click.command("foo")259 @click.help_option()260 @click.argument("param", type=MyType())261 def cmd(param):262 pass263Merge branch '7.x'David Lordbefore adoption7239794
line 264why, one step back264 result = runner.invoke(cmd, "--help")Merge pull request #1001 from pallets/metavar_testJosiahDubbefore adoptionbd59717
lines 265–266why, one step back265 assert not result.exception266 assert result.output.splitlines() == [Merge branch '7.x'David Lordbefore adoption7239794
lines 267–270why, one step back267 "Usage: foo [OPTIONS] MY_TYPE",268 "",269 "Options:",270 " --help Show this message and exit.",Merge pull request #1001 from pallets/metavar_testJosiahDubbefore adoptionbd59717
line 271why, one step back271 ]Merge pull request #1091 from sirosen/truncate-helpDavid Lordbefore adoption011fd62
lines 272–287why, one step back272273274def test_truncating_docstring(runner):275 @click.command()276 @click.pass_context277 def cli(ctx):278 """First paragraph.279280 This is a very long second281 paragraph and not correctly282 wrapped but it will be rewrapped.283 \f284285 :param click.core.Context ctx: Click context.286 """287Merge branch '7.x'David Lordbefore adoption7239794
line 288why, one step back288 result = runner.invoke(cli, ["--help"], terminal_width=60)Merge pull request #1091 from sirosen/truncate-helpDavid Lordbefore adoption011fd62
lines 289–290why, one step back289 assert not result.exception290 assert result.output.splitlines() == [Merge branch '7.x'David Lordbefore adoption7239794
lines 291–299why, one step back291 "Usage: cli [OPTIONS]",292 "",293 " First paragraph.",294 "",295 " This is a very long second paragraph and not correctly",296 " wrapped but it will be rewrapped.",297 "",298 "Options:",299 " --help Show this message and exit.",Merge pull request #1091 from sirosen/truncate-helpDavid Lordbefore adoption011fd62
line 300why, one step back300 ]Merge branch '7.x'David Lordbefore adoptiona438322
lines 301–308why, one step back301302303def test_global_show_default(runner):304 @click.command(context_settings=dict(show_default=True))305 @click.option("-f", "in_file", default="out.txt", help="Output file name")306 def cli():307 pass308Merge branch '7.x'David Lordbefore adoption7239794
line 309why, one step back309 result = runner.invoke(cli, ["--help"],)Merge branch '7.x'David Lordbefore adoptiona438322
line 310why, one step back310 assert result.output.splitlines() == [Merge branch '7.x'David Lordbefore adoption7239794
lines 311–315why, one step back311 "Usage: cli [OPTIONS]",312 "",313 "Options:",314 " -f TEXT Output file name [default: out.txt]",315 " --help Show this message and exit. [default: False]",Merge branch '7.x'David Lordbefore adoptiona438322
line 316why, one step back316 ]Merge branch '7.x'David Lordbefore adoption8b971f7
lines 317–319why, one step back317318319def test_formatting_usage_multiline_option_padding(runner):Merge branch '7.x'David Lordbefore adoption7239794
lines 320–321why, one step back320 @click.command("foo")321 @click.option("--bar", help="This help message will be padded if it wraps.")Merge branch '7.x'David Lordbefore adoption8b971f7
lines 322–324why, one step back322 def cli():323 pass324Merge branch '7.x'David Lordbefore adoption7239794
line 325why, one step back325 result = runner.invoke(cli, "--help", terminal_width=45)Merge branch '7.x'David Lordbefore adoption8b971f7
lines 326–327why, one step back326 assert not result.exception327 assert result.output.splitlines() == [Merge branch '7.x'David Lordbefore adoption7239794
lines 328–334why, one step back328 "Usage: foo [OPTIONS]",329 "",330 "Options:",331 " --bar TEXT This help message will be",332 " padded if it wraps.",333 "",334 " --help Show this message and exit.",Merge branch '7.x'David Lordbefore adoption8b971f7
lines 335–338why, one step back335 ]336337338def test_formatting_usage_no_option_padding(runner):Merge branch '7.x'David Lordbefore adoption7239794
lines 339–340why, one step back339 @click.command("foo")340 @click.option("--bar", help="This help message will be padded if it wraps.")Merge branch '7.x'David Lordbefore adoption8b971f7
lines 341–343why, one step back341 def cli():342 pass343Merge branch '7.x'David Lordbefore adoption7239794
line 344why, one step back344 result = runner.invoke(cli, "--help", terminal_width=80)Merge branch '7.x'David Lordbefore adoption8b971f7
lines 345–346why, one step back345 assert not result.exception346 assert result.output.splitlines() == [Merge branch '7.x'David Lordbefore adoption7239794
lines 347–351why, one step back347 "Usage: foo [OPTIONS]",348 "",349 "Options:",350 " --bar TEXT This help message will be padded if it wraps.",351 " --help Show this message and exit.",Merge branch '7.x'David Lordbefore adoption8b971f7
line 352why, one step back352 ]