Skip to content
Myr

Merge pull request #664 from menegazzo/master

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

Add support to invoke args as string

authored by Markus Unterwaditzer · committed by GitHub · parents 702acf7, 0759c87 · Browse files · 3 files+31 added−2 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+31 added−2 removed

  • tests:+20 added−0 removed
  • other:+11 added−2 removed

3 files+31 added−2 removed

modified:click/testing.py+9 added-2 removed
1 unmodified line
2import sys3import shutil4import tempfile5import contextlib6import shlex77from ._compat import iteritems, PY28from ._compat import iteritems, PY2, string_types91011# If someone wants to vendor click, we want to ensure the12# correct package is discovered. Ideally we could use a
247 unmodified lines
260 .. versionadded:: 4.0261 The ``color`` parameter was added.262263 :param cli: the command to invoke263 :param args: the arguments to invoke264 :param args: the arguments to invoke. It may be given as an iterable265 or a string. When given as string it will be interpreted266 as a Unix shell command. More details at267 :func:`shlex.split`.268 :param input: the input data for `sys.stdin`.269 :param env: the environment overrides.270 :param catch_exceptions: Whether to catch any other exceptions than271 ``SystemExit``.
5 unmodified lines
277 with self.isolation(input=input, env=env, color=color) as out:278 exception = None279 exit_code = 0280281 if isinstance(args, string_types):282 args = shlex.split(args)283284 try:285 cli.main(args=args or (),286 prog_name=self.get_default_prog_name(cli), **extra)287 except SystemExit as e:
42 unmodified lines
modified:tests/test_testing.py+20 added
200 unmodified lines
201 assert result.exit_code == 0202 assert result.output == 'ENV=some_value\n'203204 assert os.environ == env_orig205206207@pytest.mark.parametrize('args, expected_output', [208 (None, 'bar\n'),209 ([], 'bar\n'),210 ('', 'bar\n'),211 (['--foo', 'one two'], 'one two\n'),212 ('--foo "one two"', 'one two\n'),213])214def test_args(args, expected_output):215216 @click.command()217 @click.option('--foo', default='bar')218 def cli_args(foo):219 click.echo(foo)220221 runner = CliRunner()222 result = runner.invoke(cli_args, args=args)223 assert result.exit_code == 0224 assert result.output == expected_output
modified:CHANGES+2 added
12 unmodified lines
13- Added Float Range in Types.14- `secho`'s first argument can now be `None`, like in `echo`.15- Usage errors now hint at the `--help` option.16- ``launch`` now works properly under Cygwin. See #650.17- `CliRunner.invoke` now may receive `args` as a string representing18 a Unix shell command. See #664.1920Version 6.721-----------22
341 unmodified lines