Skip to content
Myr

Add test from #612 for usage error Argument format

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Adds a test that ensures that when an Argument is formatted into a usage error, its metavar is used, not its name. Additionally, repair testsuite to expect the new behavior.

authored by Stephen Rosen · committed by LokiHokie · parent 782389c · Browse files · 3 files+27 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+27 added−7 removed

  • tests:+26 added−6 removed
  • other:+1 added−1 removed

3 files+27 added−7 removed

modified:click/core.py+1 added-1 removed
1761 unmodified lines
1762 def get_usage_pieces(self, ctx):1763 return [self.make_metavar()]17641765 def get_error_hint(self, ctx):1766 return self.make_metavar()1766 return '"%s"' % self.make_metavar()17671768 def add_to_parser(self, parser, ctx):1769 parser.add_argument(dest=self.name, nargs=self.nargs,1770 obj=self)
4 unmodified lines
modified:tests/test_arguments.py+2 added-2 removed
186 unmodified lines
187 click.echo('arg:' + '|'.join(arg))188189 result = runner.invoke(cmd2, [])190 assert result.exit_code == 2191 assert 'Missing argument "arg"' in result.output191 assert 'Missing argument "ARG..."' in result.output192193194def test_missing_arg(runner):195 @click.command()
2 unmodified lines
198 click.echo('arg:' + arg)199200 result = runner.invoke(cmd, [])201 assert result.exit_code == 2202 assert 'Missing argument "arg".' in result.output202 assert 'Missing argument "ARG".' in result.output203204205def test_implicit_non_required(runner):206 @click.command()
83 unmodified lines
modified:tests/test_formatting.py+24 added-4 removed
157 unmodified lines
158 assert result.output.splitlines() == [159 'Usage: cmd [OPTIONS] ARG',160 'Try "cmd --help" for help.',161 '',162 'Error: Missing argument "arg".'162 'Error: Missing argument "ARG".'163 ]164165166def test_formatting_usage_error_metavar(runner):167 """168 :author: @r-m-n169 Including attribution to #612170 """171 @click.command()172 @click.argument('arg', metavar='metavar')173 def cmd(arg):174 pass175176 result = runner.invoke(cmd, [])177 assert result.exit_code == 2178 assert result.output.splitlines() == [179 'Usage: cmd [OPTIONS] metavar',180 'Try "cmd --help" for help.',181 '',182 'Error: Missing argument "metavar".'183 ]184185186def test_formatting_usage_error_nested(runner):187 @click.group()188 def cmd():189 pass
8 unmodified lines
198 assert result.output.splitlines() == [199 'Usage: cmd foo [OPTIONS] BAR',200 'Try "cmd foo --help" for help.',201 '',182 'Error: Missing argument "bar".'202 'Error: Missing argument "BAR".'203 ]204205206def test_formatting_usage_error_no_help(runner):
6 unmodified lines
213 assert result.exit_code == 2214 assert result.output.splitlines() == [215 'Usage: cmd [OPTIONS] ARG',216 '',197 'Error: Missing argument "arg".'217 'Error: Missing argument "ARG".'218 ]219220221def test_formatting_usage_custom_help(runner):
7 unmodified lines
229 assert result.output.splitlines() == [230 'Usage: cmd [OPTIONS] ARG',231 'Try "cmd --man" for help.',232 '',213 'Error: Missing argument "arg".'233 'Error: Missing argument "ARG".'234 ]