Skip to content
Myr

test_defaults.py

This file

Path

tests/test_defaults.py

86 lines · 2.5 KiB · Python

Last changed by

Merge branch '8.1.x'David Lordbefore adoption99015e1

History of this file

Take it

The walk stopped after 200 commits: lines older than 317d699 point at it.

Merge pull request #2054 from pallets/dependabot/pip/sphinx-tabs-3.2.0David Lordbefore adoption317d699

lines 1–7why, one step back
1import click
234def test_basic_defaults(runner):5 @click.command()6 @click.option("--foo", default=42, type=click.FLOAT)7 def cli(foo):

use ruff lint and format (#2658)David Lordbefore adoption1a3baf7

line 8why, one step back
8 assert isinstance(foo, float)

Merge pull request #2054 from pallets/dependabot/pip/sphinx-tabs-3.2.0David Lordbefore adoption317d699

lines 9–20why, one step back
9 click.echo(f"FOO:[{foo}]")
1011 result = runner.invoke(cli, [])12 assert not result.exception13 assert "FOO:[42.0]" in result.output141516def test_multiple_defaults(runner):17 @click.command()18 @click.option("--foo", default=[23, 42], type=click.FLOAT, multiple=True)19 def cli(foo):20 for item in foo:

use ruff lint and format (#2658)David Lordbefore adoption1a3baf7

line 21why, one step back
21 assert isinstance(item, float)

Merge pull request #2054 from pallets/dependabot/pip/sphinx-tabs-3.2.0David Lordbefore adoption317d699

lines 22–40why, one step back
22 click.echo(item)
2324 result = runner.invoke(cli, [])25 assert not result.exception26 assert result.output.splitlines() == ["23.0", "42.0"]272829def test_nargs_plus_multiple(runner):30 @click.command()31 @click.option(32 "--arg", default=((1, 2), (3, 4)), nargs=2, multiple=True, type=click.INT33 )34 def cli(arg):35 for a, b in arg:36 click.echo(f"<{a:d}|{b:d}>")3738 result = runner.invoke(cli, [])39 assert not result.exception40 assert result.output.splitlines() == ["<1|2>", "<3|4>"]

Merge branch '8.1.x'David Lordbefore adoptiond9af5cf

lines 41–61why, one step back
41
4243def test_multiple_flag_default(runner):44 """Default default for flags when multiple=True should be empty tuple."""4546 @click.command47 # flag due to secondary token48 @click.option("-y/-n", multiple=True)49 # flag due to is_flag50 @click.option("-f", is_flag=True, multiple=True)51 # flag due to flag_value52 @click.option("-v", "v", flag_value=1, multiple=True)53 @click.option("-q", "v", flag_value=-1, multiple=True)54 def cli(y, f, v):55 return y, f, v5657 result = runner.invoke(cli, standalone_mode=False)58 assert result.return_value == ((), (), ())5960 result = runner.invoke(cli, ["-y", "-n", "-f", "-v", "-q"], standalone_mode=False)61 assert result.return_value == ((True, False), (True,), (1, -1))

Merge branch '8.1.x'David Lordbefore adoption99015e1

lines 62–86why, one step back
62
6364def test_flag_default_map(runner):65 """test flag with default map"""6667 @click.group()68 def cli():69 pass7071 @cli.command()72 @click.option("--name/--no-name", is_flag=True, show_default=True, help="name flag")73 def foo(name):74 click.echo(name)7576 result = runner.invoke(cli, ["foo"])77 assert "False" in result.output7879 result = runner.invoke(cli, ["foo", "--help"])80 assert "default: no-name" in result.output8182 result = runner.invoke(cli, ["foo"], default_map={"foo": {"name": True}})83 assert "True" in result.output8485 result = runner.invoke(cli, ["foo", "--help"], default_map={"foo": {"name": True}})86 assert "default: name" in result.output