Skip to content
Myr

parametrize bool switch and flag tests

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

authored by David Lord · committed by David Lord · parent bf8c03e · Browse files · 1 file+25 added−26 removed
This commit

State

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

Trailers

  • Co-authored-by: Maximilian Wassink <wassink.maximilian@protonmail.com>

Diff stats

1 file+25 added−26 removed

  • tests:+25 added−26 removed

1 file+25 added−26 removed

modified:tests/test_basic.py+25 added-26 removed
200 unmodified lines
201 else:202 assert result.exception is None203204205def test_boolean_option(runner):206 for default in True, False:205@pytest.mark.parametrize("default", [True, False])206@pytest.mark.parametrize(207 ("args", "expect"), [(["--on"], True), (["--off"], False), ([], None)]208)209def test_boolean_switch(runner, default, args, expect):210 @click.command()211 @click.option("--on/--off", default=default)212 def cli(on):213 return on214208 @click.command()209 @click.option("--with-foo/--without-foo", default=default)210 def cli(with_foo):211 click.echo(with_foo)215 if expect is None:216 expect = default217213 result = runner.invoke(cli, ["--with-foo"])214 assert not result.exception215 assert result.output == "True\n"216 result = runner.invoke(cli, ["--without-foo"])217 assert not result.exception218 assert result.output == "False\n"219 result = runner.invoke(cli, [])220 assert not result.exception221 assert result.output == f"{default}\n"218 result = runner.invoke(cli, args, standalone_mode=False)219 assert result.return_value is expect220223 for default in True, False:221222@pytest.mark.parametrize("default", [True, False])223@pytest.mark.parametrize(("args", "expect"), [(["--f"], True), ([], False)])224def test_boolean_flag(runner, default, args, expect):225 @click.command()226 @click.option("--flag", is_flag=True, default=default)227 def cli(flag):228 click.echo(flag)225 @click.command()226 @click.option("--f", is_flag=True, default=default)227 def cli(f):228 return f229230 result = runner.invoke(cli, ["--flag"])231 assert not result.exception232 assert result.output == f"{not default}\n"233 result = runner.invoke(cli, [])234 assert not result.exception235 assert result.output == f"{default}\n"230 if default:231 expect = not expect232233 result = runner.invoke(cli, args, standalone_mode=False)234 assert result.return_value is expect235236237@pytest.mark.parametrize(238 ("value", "expect"),239 chain(240 ((x, "True") for x in ("1", "true", "t", "yes", "y", "on")),
335 unmodified lines