test_options.py
This file
Path
tests/test_options.py
572 lines · 16.5 KiB · Python
Last changed by
Merge pull request #1594 from MLH-Fellowship/duplicate-boolean-flagsDavid Lordbefore adoptiondfb842d
History of this fileTake it
The walk stopped after 200 commits: lines older than a72baa4 point at it.
Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 1why, one step back1import osMerge branch '7.x'David Lordbefore adoption7239794
lines 2–3why, one step back2import re3Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 4–5why, one step back4import pytest5Merge branch '7.x'David Lordbefore adoption7239794
line 6why, one step back6import clickMerge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 7–10why, one step back789def test_prefixes(runner):10 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 11–12why, one step back11 @click.option("++foo", is_flag=True, help="das foo")12 @click.option("--bar", is_flag=True, help="das bar")Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 13why, one step back13 def cli(foo, bar):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 14why, one step back14 click.echo(f"foo={foo} bar={bar}")Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 15why, one step back15Merge branch '7.x'David Lordbefore adoption7239794
line 16why, one step back16 result = runner.invoke(cli, ["++foo", "--bar"])Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 17why, one step back17 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 18why, one step back18 assert result.output == "foo=True bar=True\n"Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 19why, one step back19Merge branch '7.x'David Lordbefore adoption7239794
lines 20–22why, one step back20 result = runner.invoke(cli, ["--help"])21 assert re.search(r"\+\+foo\s+das foo", result.output) is not None22 assert re.search(r"--bar\s+das bar", result.output) is not NoneMerge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 23–25why, one step back232425def test_invalid_option(runner):Merge branch '7.x'David Lordbefore adoption7239794
lines 26–27why, one step back26 with pytest.raises(TypeError, match="name was passed"):27Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 28why, one step back28 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 29why, one step back29 @click.option("foo")Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 30–34why, one step back30 def cli(foo):31 pass323334def test_invalid_nargs(runner):Merge branch '7.x'David Lordbefore adoption7239794
lines 35–36why, one step back35 with pytest.raises(TypeError, match="nargs < 0"):36Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 37why, one step back37 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 38why, one step back38 @click.option("--foo", nargs=-1)Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 39–44why, one step back39 def cli(foo):40 pass414243def test_nargs_tup_composite_mult(runner):44 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 45why, one step back45 @click.option("--item", type=(str, int), multiple=True)Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 46why, one step back46 def copy(item):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
lines 47–48why, one step back47 for name, id in item:48 click.echo(f"name={name} id={id:d}")Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 49why, one step back49Merge branch '7.x'David Lordbefore adoption7239794
line 50why, one step back50 result = runner.invoke(copy, ["--item", "peter", "1", "--item", "max", "2"])Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 51why, one step back51 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 52why, one step back52 assert result.output.splitlines() == ["name=peter id=1", "name=max id=2"]Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 53–56why, one step back535455def test_counting(runner):56 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 57why, one step back57 @click.option("-v", count=True, help="Verbosity", type=click.IntRange(0, 3))Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 58why, one step back58 def cli(v):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 59why, one step back59 click.echo(f"verbosity={v:d}")Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 60why, one step back60Merge branch '7.x'David Lordbefore adoption7239794
line 61why, one step back61 result = runner.invoke(cli, ["-vvv"])Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 62why, one step back62 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 63why, one step back63 assert result.output == "verbosity=3\n"Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 64why, one step back64Merge branch '7.x'David Lordbefore adoption7239794
line 65why, one step back65 result = runner.invoke(cli, ["-vvvv"])Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 66why, one step back66 assert result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
lines 67–68why, one step back67 assert (68 "Invalid value for '-v': 4 is not in the valid range of 0 to 3."Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 69why, one step back69 in result.outputMerge branch '7.x'David Lordbefore adoption7239794
line 70why, one step back70 )Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 71–73why, one step back7172 result = runner.invoke(cli, [])73 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 74why, one step back74 assert result.output == "verbosity=0\n"Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 75why, one step back75Merge branch '7.x'David Lordbefore adoption7239794
lines 76–77why, one step back76 result = runner.invoke(cli, ["--help"])77 assert re.search(r"-v\s+Verbosity", result.output) is not NoneMerge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 78–79why, one step back7879Merge branch '7.x'David Lordbefore adoption7239794
line 80why, one step back80@pytest.mark.parametrize("unknown_flag", ["--foo", "-f"])Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 81–87why, one step back81def test_unknown_options(runner, unknown_flag):82 @click.command()83 def cli():84 pass8586 result = runner.invoke(cli, [unknown_flag])87 assert result.exceptionMerge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 88why, one step back88 assert f"no such option: {unknown_flag}" in result.outputMerge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 89–92why, one step back899091def test_multiple_required(runner):92 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 93why, one step back93 @click.option("-m", "--message", multiple=True, required=True)Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 94why, one step back94 def cli(message):Merge branch '7.x'David Lordbefore adoption7239794
line 95why, one step back95 click.echo("\n".join(message))Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 96why, one step back96Merge branch '7.x'David Lordbefore adoption7239794
line 97why, one step back97 result = runner.invoke(cli, ["-m", "foo", "-mbar"])Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 98why, one step back98 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 99why, one step back99 assert result.output == "foo\nbar\n"Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 100–102why, one step back100101 result = runner.invoke(cli, [])102 assert result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 103why, one step back103 assert "Error: Missing option '-m' / '--message'." in result.outputMerge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 104–105why, one step back104105Merge branch '7.x'David Lordbefore adoption2269786
lines 106–107why, one step back106def test_empty_envvar(runner):107 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 108why, one step back108 @click.option("--mypath", type=click.Path(exists=True), envvar="MYPATH")Merge branch '7.x'David Lordbefore adoption2269786
line 109why, one step back109 def cli(mypath):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 110why, one step back110 click.echo(f"mypath: {mypath}")Merge branch '7.x'David Lordbefore adoption2269786
line 111why, one step back111Merge branch '7.x'David Lordbefore adoption7239794
line 112why, one step back112 result = runner.invoke(cli, [], env={"MYPATH": ""})Merge branch '7.x'David Lordbefore adoption2269786
line 113why, one step back113 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 114why, one step back114 assert result.output == "mypath: None\n"Merge branch '7.x'David Lordbefore adoption2269786
lines 115–116why, one step back115116Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 117–118why, one step back117def test_multiple_envvar(runner):118 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 119why, one step back119 @click.option("--arg", multiple=True)Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 120why, one step back120 def cmd(arg):Merge branch '7.x'David Lordbefore adoption7239794
line 121why, one step back121 click.echo("|".join(arg))Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 122why, one step back122Merge branch '7.x'David Lordbefore adoption7239794
lines 123–125why, one step back123 result = runner.invoke(124 cmd, [], auto_envvar_prefix="TEST", env={"TEST_ARG": "foo bar baz"}125 )Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 126why, one step back126 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 127why, one step back127 assert result.output == "foo|bar|baz\n"Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 128–129why, one step back128129 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 130why, one step back130 @click.option("--arg", multiple=True, envvar="X")Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 131why, one step back131 def cmd(arg):Merge branch '7.x'David Lordbefore adoption7239794
line 132why, one step back132 click.echo("|".join(arg))Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 133why, one step back133Merge branch '7.x'David Lordbefore adoption7239794
line 134why, one step back134 result = runner.invoke(cmd, [], env={"X": "foo bar baz"})Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 135why, one step back135 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 136why, one step back136 assert result.output == "foo|bar|baz\n"Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 137–138why, one step back137138 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 139why, one step back139 @click.option("--arg", multiple=True, type=click.Path())Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 140why, one step back140 def cmd(arg):Merge branch '7.x'David Lordbefore adoption7239794
line 141why, one step back141 click.echo("|".join(arg))Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 142why, one step back142Merge branch '7.x'David Lordbefore adoption7239794
lines 143–146why, one step back143 result = runner.invoke(144 cmd,145 [],146 auto_envvar_prefix="TEST",Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 147why, one step back147 env={"TEST_ARG": f"foo{os.path.pathsep}bar"},Merge branch '7.x'David Lordbefore adoption7239794
line 148why, one step back148 )Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 149why, one step back149 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 150why, one step back150 assert result.output == "foo|bar\n"Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 151–154why, one step back151152153def test_multiple_default_help(runner):154 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 155–156why, one step back155 @click.option("--arg1", multiple=True, default=("foo", "bar"), show_default=True)156 @click.option("--arg2", multiple=True, default=(1, 2), type=int, show_default=True)Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 157–159why, one step back157 def cmd(arg, arg2):158 pass159Merge branch '7.x'David Lordbefore adoption7239794
line 160why, one step back160 result = runner.invoke(cmd, ["--help"])Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 161why, one step back161 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
lines 162–163why, one step back162 assert "foo, bar" in result.output163 assert "1, 2" in result.outputMerge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 164–167why, one step back164165166def test_multiple_default_type(runner):167 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 168–169why, one step back168 @click.option("--arg1", multiple=True, default=("foo", "bar"))169 @click.option("--arg2", multiple=True, default=(1, "a"))Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 170why, one step back170 def cmd(arg1, arg2):Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
lines 171–172why, one step back171 assert all(isinstance(e[0], str) for e in arg1)172 assert all(isinstance(e[1], str) for e in arg1)Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 173–174why, one step back173174 assert all(isinstance(e[0], int) for e in arg2)Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 175why, one step back175 assert all(isinstance(e[1], str) for e in arg2)Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 176why, one step back176Merge branch '7.x'David Lordbefore adoption7239794
lines 177–179why, one step back177 result = runner.invoke(178 cmd, "--arg1 a b --arg1 test 1 --arg2 2 two --arg2 4 four".split()179 )Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 180–181why, one step back180 assert not result.exception181Merge branch '7.x'David Lordbefore adoption7239794
line 182why, one step back182Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 183–184why, one step back183def test_dynamic_default_help_unset(runner):184 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 185–190why, one step back185 @click.option(186 "--username",187 prompt=True,188 default=lambda: os.environ.get("USER", ""),189 show_default=True,190 )Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 191–192why, one step back191 def cmd(username):192 print("Hello,", username)Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 193why, one step back193Merge branch '7.x'David Lordbefore adoption7239794
line 194why, one step back194 result = runner.invoke(cmd, ["--help"])Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 195why, one step back195 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
lines 196–198why, one step back196 assert "--username" in result.output197 assert "lambda" not in result.output198 assert "(dynamic)" in result.outputMerge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 199why, one step back199Merge branch '7.x'David Lordbefore adoption7239794
line 200why, one step back200Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 201–202why, one step back201def test_dynamic_default_help_text(runner):202 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
lines 203–208why, one step back203 @click.option(204 "--username",205 prompt=True,206 default=lambda: os.environ.get("USER", ""),207 show_default="current user",208 )Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
lines 209–211why, one step back209 def cmd(username):210 print("Hello,", username)211Merge branch '7.x'David Lordbefore adoption7239794
line 212why, one step back212 result = runner.invoke(cmd, ["--help"])Merge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 213why, one step back213 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
lines 214–216why, one step back214 assert "--username" in result.output215 assert "lambda" not in result.output216 assert "(current user)" in result.outputMerge pull request #996 from dougharris/lambda-844-547Dan Sullybefore adoptionbc53a96
line 217why, one step back217Merge pull request #1105 from sirosen/bugfix/autoenv-uppercaseDavid Lordbefore adoption3e17a3d
line 218why, one step back218Merge pull request #1586 from IamCathal/coc-intrangepreviewDavid Lordbefore adoptione8de91d
lines 219–228why, one step back219def test_intrange_default_help_text(runner):220 @click.command()221 @click.option("--count", type=click.IntRange(1, 32), show_default=True, default=1)222 def cmd(arg):223 click.echo(arg)224225 result = runner.invoke(cmd, ["--help"])226 assert "1-32 inclusive" in result.output227228Merge pull request #1105 from sirosen/bugfix/autoenv-uppercaseDavid Lordbefore adoption3e17a3d
lines 229–230why, one step back229def test_toupper_envvar_prefix(runner):230 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 231why, one step back231 @click.option("--arg")Merge pull request #1105 from sirosen/bugfix/autoenv-uppercaseDavid Lordbefore adoption3e17a3d
lines 232–234why, one step back232 def cmd(arg):233 click.echo(arg)234Merge branch '7.x'David Lordbefore adoption7239794
line 235why, one step back235 result = runner.invoke(cmd, [], auto_envvar_prefix="test", env={"TEST_ARG": "foo"})Merge pull request #1105 from sirosen/bugfix/autoenv-uppercaseDavid Lordbefore adoption3e17a3d
line 236why, one step back236 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 237why, one step back237 assert result.output == "foo\n"Merge pull request #1105 from sirosen/bugfix/autoenv-uppercaseDavid Lordbefore adoption3e17a3d
lines 238–239why, one step back238239Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 240–241why, one step back240def test_nargs_envvar(runner):241 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 242why, one step back242 @click.option("--arg", nargs=2)Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 243why, one step back243 def cmd(arg):Merge branch '7.x'David Lordbefore adoption7239794
line 244why, one step back244 click.echo("|".join(arg))Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 245why, one step back245Merge branch '7.x'David Lordbefore adoption7239794
lines 246–248why, one step back246 result = runner.invoke(247 cmd, [], auto_envvar_prefix="TEST", env={"TEST_ARG": "foo bar"}248 )Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 249why, one step back249 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 250why, one step back250 assert result.output == "foo|bar\n"Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 251–252why, one step back251252 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 253why, one step back253 @click.option("--arg", nargs=2, multiple=True)Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 254–255why, one step back254 def cmd(arg):255 for item in arg:Merge branch '7.x'David Lordbefore adoption7239794
line 256why, one step back256 click.echo("|".join(item))Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 257why, one step back257Merge branch '7.x'David Lordbefore adoption7239794
lines 258–260why, one step back258 result = runner.invoke(259 cmd, [], auto_envvar_prefix="TEST", env={"TEST_ARG": "x 1 y 2"}260 )Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 261why, one step back261 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 262why, one step back262 assert result.output == "x|1\ny|2\n"Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 263–264why, one step back263264Merge pull request #710 from iffy/show_envvarDan Sullybefore adoption961a441
lines 265–266why, one step back265def test_show_envvar(runner):266 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 267why, one step back267 @click.option("--arg1", envvar="ARG1", show_envvar=True)Merge pull request #710 from iffy/show_envvarDan Sullybefore adoption961a441
lines 268–270why, one step back268 def cmd(arg):269 pass270Merge branch '7.x'David Lordbefore adoption7239794
line 271why, one step back271 result = runner.invoke(cmd, ["--help"])Merge pull request #710 from iffy/show_envvarDan Sullybefore adoption961a441
line 272why, one step back272 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 273why, one step back273 assert "ARG1" in result.outputMerge pull request #710 from iffy/show_envvarDan Sullybefore adoption961a441
lines 274–277why, one step back274275276def test_show_envvar_auto_prefix(runner):277 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 278why, one step back278 @click.option("--arg1", show_envvar=True)Merge pull request #710 from iffy/show_envvarDan Sullybefore adoption961a441
lines 279–281why, one step back279 def cmd(arg):280 pass281Merge branch '7.x'David Lordbefore adoption7239794
line 282why, one step back282 result = runner.invoke(cmd, ["--help"], auto_envvar_prefix="TEST")Merge pull request #710 from iffy/show_envvarDan Sullybefore adoption961a441
line 283why, one step back283 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 284why, one step back284 assert "TEST_ARG1" in result.outputMerge pull request #710 from iffy/show_envvarDan Sullybefore adoption961a441
lines 285–286why, one step back285286Merge branch '7.x'David Lordbefore adoption8b971f7
lines 287–292why, one step back287def test_show_envvar_auto_prefix_dash_in_command(runner):288 @click.group()289 def cli():290 pass291292 @cli.command()Merge branch '7.x'David Lordbefore adoption7239794
line 293why, one step back293 @click.option("--baz", show_envvar=True)Merge branch '7.x'David Lordbefore adoption8b971f7
lines 294–296why, one step back294 def foo_bar(baz):295 pass296Merge branch '7.x'David Lordbefore adoption7239794
line 297why, one step back297 result = runner.invoke(cli, ["foo-bar", "--help"], auto_envvar_prefix="TEST")Merge branch '7.x'David Lordbefore adoption8b971f7
line 298why, one step back298 assert not result.exceptionMerge branch '7.x'David Lordbefore adoption7239794
line 299why, one step back299 assert "TEST_FOO_BAR_BAZ" in result.outputMerge branch '7.x'David Lordbefore adoption8b971f7
lines 300–301why, one step back300301Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 302why, one step back302def test_custom_validation(runner):Merge branch '6.x-maintenance'Armin Ronacherbefore adoption7404b06
line 303why, one step back303 def validate_pos_int(ctx, param, value):Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 304why, one step back304 if value < 0:Merge branch '7.x'David Lordbefore adoption7239794
line 305why, one step back305 raise click.BadParameter("Value needs to be positive")Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 306–308why, one step back306 return value307308 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 309why, one step back309 @click.option("--foo", callback=validate_pos_int, default=1)Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 310–312why, one step back310 def cmd(foo):311 click.echo(foo)312Merge branch '7.x'David Lordbefore adoption7239794
lines 313–314why, one step back313 result = runner.invoke(cmd, ["--foo", "-1"])314 assert "Invalid value for '--foo': Value needs to be positive" in result.outputMerge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 315why, one step back315Merge branch '7.x'David Lordbefore adoption7239794
lines 316–317why, one step back316 result = runner.invoke(cmd, ["--foo", "42"])317 assert result.output == "42\n"Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 318–321why, one step back318319320def test_winstyle_options(runner):321 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 322why, one step back322 @click.option("/debug;/no-debug", help="Enables or disables debug mode.")Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 323–325why, one step back323 def cmd(debug):324 click.echo(debug)325Merge branch '7.x'David Lordbefore adoption7239794
lines 326–334why, one step back326 result = runner.invoke(cmd, ["/debug"], help_option_names=["/?"])327 assert result.output == "True\n"328 result = runner.invoke(cmd, ["/no-debug"], help_option_names=["/?"])329 assert result.output == "False\n"330 result = runner.invoke(cmd, [], help_option_names=["/?"])331 assert result.output == "False\n"332 result = runner.invoke(cmd, ["/?"], help_option_names=["/?"])333 assert "/debug; /no-debug Enables or disables debug mode." in result.output334 assert "/? Show this message and exit." in result.outputMerge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 335–338why, one step back335336337def test_legacy_options(runner):338 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 339why, one step back339 @click.option("-whatever")Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 340–342why, one step back340 def cmd(whatever):341 click.echo(whatever)342Merge branch '7.x'David Lordbefore adoption7239794
lines 343–346why, one step back343 result = runner.invoke(cmd, ["-whatever", "42"])344 assert result.output == "42\n"345 result = runner.invoke(cmd, ["-whatever=23"])346 assert result.output == "23\n"Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 347–348why, one step back347348Merge branch '7.x'David Lordbefore adoption2269786
lines 349–352why, one step back349def test_missing_option_string_cast():350 ctx = click.Context(click.Command(""))351352 with pytest.raises(click.MissingParameter) as excinfo:Merge branch '7.x'David Lordbefore adoption7239794
line 353why, one step back353 click.Option(["-a"], required=True).full_process_value(ctx, None)Merge branch '7.x'David Lordbefore adoption2269786
lines 354–357why, one step back354355 assert str(excinfo.value) == "missing parameter: a"356357Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 358–359why, one step back358def test_missing_choice(runner):359 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 360why, one step back360 @click.option("--foo", type=click.Choice(["foo", "bar"]), required=True)Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 361–365why, one step back361 def cmd(foo):362 click.echo(foo)363364 result = runner.invoke(cmd)365 assert result.exit_code == 2Merge branch '7.x'David Lordbefore adoption7239794
lines 366–370why, one step back366 error, separator, choices = result.output.partition("Choose from")367 assert "Error: Missing option '--foo'. " in error368 assert "Choose from" in separator369 assert "foo" in choices370 assert "bar" in choicesMerge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 371–372why, one step back371372Merge pull request #887 from sirosen/feature/case-insensitive-choiceZachery Birbefore adoptionc70d463
lines 373–374why, one step back373def test_case_insensitive_choice(runner):374 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 375why, one step back375 @click.option("--foo", type=click.Choice(["Orange", "Apple"], case_sensitive=False))Merge pull request #887 from sirosen/feature/case-insensitive-choiceZachery Birbefore adoptionc70d463
lines 376–378why, one step back376 def cmd(foo):377 click.echo(foo)378Merge branch '7.x'David Lordbefore adoption7239794
line 379why, one step back379 result = runner.invoke(cmd, ["--foo", "apple"])Merge pull request #887 from sirosen/feature/case-insensitive-choiceZachery Birbefore adoptionc70d463
line 380why, one step back380 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 381why, one step back381 assert result.output == "Apple\n"Merge pull request #887 from sirosen/feature/case-insensitive-choiceZachery Birbefore adoptionc70d463
line 382why, one step back382Merge branch '7.x'David Lordbefore adoption7239794
line 383why, one step back383 result = runner.invoke(cmd, ["--foo", "oRANGe"])Merge pull request #887 from sirosen/feature/case-insensitive-choiceZachery Birbefore adoptionc70d463
line 384why, one step back384 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 385why, one step back385 assert result.output == "Orange\n"Merge pull request #887 from sirosen/feature/case-insensitive-choiceZachery Birbefore adoptionc70d463
line 386why, one step back386Merge branch '7.x'David Lordbefore adoption7239794
line 387why, one step back387 result = runner.invoke(cmd, ["--foo", "Apple"])Merge pull request #887 from sirosen/feature/case-insensitive-choiceZachery Birbefore adoptionc70d463
line 388why, one step back388 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 389why, one step back389 assert result.output == "Apple\n"Merge pull request #887 from sirosen/feature/case-insensitive-choiceZachery Birbefore adoptionc70d463
lines 390–391why, one step back390391 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 392why, one step back392 @click.option("--foo", type=click.Choice(["Orange", "Apple"]))Merge pull request #887 from sirosen/feature/case-insensitive-choiceZachery Birbefore adoptionc70d463
lines 393–395why, one step back393 def cmd2(foo):394 click.echo(foo)395Merge branch '7.x'David Lordbefore adoption7239794
line 396why, one step back396 result = runner.invoke(cmd2, ["--foo", "apple"])Merge pull request #887 from sirosen/feature/case-insensitive-choiceZachery Birbefore adoptionc70d463
lines 397–398why, one step back397 assert result.exit_code == 2398Merge branch '7.x'David Lordbefore adoption7239794
line 399why, one step back399 result = runner.invoke(cmd2, ["--foo", "oRANGe"])Merge pull request #887 from sirosen/feature/case-insensitive-choiceZachery Birbefore adoptionc70d463
lines 400–401why, one step back400 assert result.exit_code == 2401Merge branch '7.x'David Lordbefore adoption7239794
line 402why, one step back402 result = runner.invoke(cmd2, ["--foo", "Apple"])Merge pull request #887 from sirosen/feature/case-insensitive-choiceZachery Birbefore adoptionc70d463
line 403why, one step back403 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption11abf2b
lines 404–407why, one step back404405406def test_case_insensitive_choice_returned_exactly(runner):407 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 408why, one step back408 @click.option("--foo", type=click.Choice(["Orange", "Apple"], case_sensitive=False))Merge branch '7.x'David Lordbefore adoption11abf2b
lines 409–411why, one step back409 def cmd(foo):410 click.echo(foo)411Merge branch '7.x'David Lordbefore adoption7239794
line 412why, one step back412 result = runner.invoke(cmd, ["--foo", "apple"])Merge branch '7.x'David Lordbefore adoption11abf2b
line 413why, one step back413 assert result.exit_code == 0Merge branch '7.x'David Lordbefore adoption7239794
line 414why, one step back414 assert result.output == "Apple\n"Merge pull request #887 from sirosen/feature/case-insensitive-choiceZachery Birbefore adoptionc70d463
lines 415–416why, one step back415416Merge branch '7.x'David Lordbefore adoption8b971f7
line 417why, one step back417def test_option_help_preserve_paragraphs(runner):Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 418why, one step back418 @click.command()Merge branch '7.x'David Lordbefore adoption8b971f7
lines 419–423why, one step back419 @click.option(420 "-C",421 "--config",422 type=click.Path(),423 help="""Configuration file to use.Merge branch '7.x'David Lordbefore adoption7239794
line 424why, one step back424Merge branch '7.x'David Lordbefore adoption8b971f7
lines 425–430why, one step back425 If not given, the environment variable CONFIG_FILE is consulted426 and used if set. If neither are given, a default configuration427 file is loaded.""",428 )429 def cmd(config):430 passMerge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 431why, one step back431Merge branch '7.x'David Lordbefore adoption7239794
line 432why, one step back432 result = runner.invoke(cmd, ["--help"],)Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 433why, one step back433 assert result.exit_code == 0Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
line 434why, one step back434 i = " " * 21Merge branch '7.x'David Lordbefore adoption8b971f7
lines 435–436why, one step back435 assert (436 " -C, --config PATH Configuration file to use.\n"Merge pull request #1532 from pallets/drop-python2David Lordbefore adoption97de2c9
lines 437–440why, one step back437 f"{i}\n"438 f"{i}If not given, the environment variable CONFIG_FILE is\n"439 f"{i}consulted and used if set. If neither are given, a default\n"440 f"{i}configuration file is loaded."Merge branch '7.x'David Lordbefore adoption8b971f7
line 441why, one step back441 ) in result.outputMerge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
line 442why, one step back442Merge branch '7.x'David Lordbefore adoption7239794
line 443why, one step back443Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 444–446why, one step back444def test_argument_custom_class(runner):445 class CustomArgument(click.Argument):446 def get_default(self, ctx):Merge branch '7.x'David Lordbefore adoption7239794
lines 447–448why, one step back447 """a dumb override of a default value for testing"""448 return "I am a default"Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 449–450why, one step back449450 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 451why, one step back451 @click.argument("testarg", cls=CustomArgument, default="you wont see me")Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 452–455why, one step back452 def cmd(testarg):453 click.echo(testarg)454455 result = runner.invoke(cmd)Merge branch '7.x'David Lordbefore adoption7239794
lines 456–457why, one step back456 assert "I am a default" in result.output457 assert "you wont see me" not in result.outputMerge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 458–462why, one step back458459460def test_option_custom_class(runner):461 class CustomOption(click.Option):462 def get_help_record(self, ctx):Merge branch '7.x'David Lordbefore adoption7239794
lines 463–464why, one step back463 """a dumb override of a help text for testing"""464 return ("--help", "I am a help text")Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 465–466why, one step back465466 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 467why, one step back467 @click.option("--testoption", cls=CustomOption, help="you wont see me")Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 468–470why, one step back468 def cmd(testoption):469 click.echo(testoption)470Merge branch '7.x'David Lordbefore adoption7239794
lines 471–473why, one step back471 result = runner.invoke(cmd, ["--help"])472 assert "I am a help text" in result.output473 assert "you wont see me" not in result.outputMerge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 474–475why, one step back474475Merge pull request #994 from dsully/issue-926David Lordbefore adoption1ea6a75
lines 476–480why, one step back476def test_option_custom_class_reusable(runner):477 """Ensure we can reuse a custom class option. See Issue #926"""478479 class CustomOption(click.Option):480 def get_help_record(self, ctx):Merge branch '7.x'David Lordbefore adoption7239794
lines 481–482why, one step back481 """a dumb override of a help text for testing"""482 return ("--help", "I am a help text")Merge pull request #994 from dsully/issue-926David Lordbefore adoption1ea6a75
lines 483–484why, one step back483484 # Assign to a variable to re-use the decorator.Merge branch '7.x'David Lordbefore adoption7239794
line 485why, one step back485 testoption = click.option("--testoption", cls=CustomOption, help="you wont see me")Merge pull request #994 from dsully/issue-926David Lordbefore adoption1ea6a75
lines 486–499why, one step back486487 @click.command()488 @testoption489 def cmd1(testoption):490 click.echo(testoption)491492 @click.command()493 @testoption494 def cmd2(testoption):495 click.echo(testoption)496497 # Both of the commands should have the --help option now.498 for cmd in (cmd1, cmd2):499Merge branch '7.x'David Lordbefore adoption7239794
lines 500–502why, one step back500 result = runner.invoke(cmd, ["--help"])501 assert "I am a help text" in result.output502 assert "you wont see me" not in result.outputMerge branch '7.x'David Lordbefore adoption2269786
lines 503–506why, one step back503504505def test_bool_flag_with_type(runner):506 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 507why, one step back507 @click.option("--shout/--no-shout", default=False, type=bool)Merge branch '7.x'David Lordbefore adoption2269786
lines 508–512why, one step back508 def cmd(shout):509 pass510511 result = runner.invoke(cmd)512 assert not result.exceptionMerge pull request #994 from dsully/issue-926David Lordbefore adoption1ea6a75
lines 513–514why, one step back513514Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 515–516why, one step back515def test_aliases_for_flags(runner):516 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 517why, one step back517 @click.option("--warnings/--no-warnings", " /-W", default=True)Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 518–520why, one step back518 def cli(warnings):519 click.echo(warnings)520Merge branch '7.x'David Lordbefore adoption7239794
lines 521–526why, one step back521 result = runner.invoke(cli, ["--warnings"])522 assert result.output == "True\n"523 result = runner.invoke(cli, ["--no-warnings"])524 assert result.output == "False\n"525 result = runner.invoke(cli, ["-W"])526 assert result.output == "False\n"Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 527–528why, one step back527528 @click.command()Merge branch '7.x'David Lordbefore adoption7239794
line 529why, one step back529 @click.option("--warnings/--no-warnings", "-w", default=True)Merge pull request #731 from jeffwidman/patch-1Markus Unterwaditzerbefore adoptiona72baa4
lines 530–532why, one step back530 def cli_alt(warnings):531 click.echo(warnings)532Merge branch '7.x'David Lordbefore adoption7239794
lines 533–538why, one step back533 result = runner.invoke(cli_alt, ["--warnings"])534 assert result.output == "True\n"535 result = runner.invoke(cli_alt, ["--no-warnings"])536 assert result.output == "False\n"537 result = runner.invoke(cli_alt, ["-w"])538 assert result.output == "True\n"Merge branch '6.x-maintenance'Markus Unterwaditzerbefore adoption945b4d3
line 539why, one step back539Merge pull request #799 from ericfrederich/option_namesMarkus Unterwaditzerbefore adoptione634d7f
line 540why, one step back540Merge branch '7.x'David Lordbefore adoption7239794
lines 541–556why, one step back541@pytest.mark.parametrize(542 "option_args,expected",543 [544 (["--aggressive", "--all", "-a"], "aggressive"),545 (["--first", "--second", "--third", "-a", "-b", "-c"], "first"),546 (["--apple", "--banana", "--cantaloupe", "-a", "-b", "-c"], "apple"),547 (["--cantaloupe", "--banana", "--apple", "-c", "-b", "-a"], "cantaloupe"),548 (["-a", "-b", "-c"], "a"),549 (["-c", "-b", "-a"], "c"),550 (["-a", "--apple", "-b", "--banana", "-c", "--cantaloupe"], "apple"),551 (["-c", "-a", "--cantaloupe", "-b", "--banana", "--apple"], "cantaloupe"),552 (["--from", "-f", "_from"], "_from"),553 (["--return", "-r", "_ret"], "_ret"),554 ],555)556def test_option_names(runner, option_args, expected):Merge branch '6.x-maintenance'Markus Unterwaditzerbefore adoption945b4d3
lines 557–564why, one step back557 @click.command()558 @click.option(*option_args, is_flag=True)559 def cmd(**kwargs):560 click.echo(str(kwargs[expected]))561562 assert cmd.params[0].name == expected563564 for form in option_args:Merge branch '7.x'David Lordbefore adoption7239794
line 565why, one step back565 if form.startswith("-"):Merge pull request #799 from ericfrederich/option_namesMarkus Unterwaditzerbefore adoptione634d7f
line 566why, one step back566 result = runner.invoke(cmd, [form])Merge branch '7.x'David Lordbefore adoption7239794
line 567why, one step back567 assert result.output == "True\n"Merge pull request #1594 from MLH-Fellowship/duplicate-boolean-flagsDavid Lordbefore adoptiondfb842d
lines 568–572why, one step back568569570def test_flag_duplicate_names(runner):571 with pytest.raises(ValueError, match="cannot use the same flag for true/false"):572 click.Option(["--foo/--foo"], default=False)