diff options
author | David Lord <davidism@gmail.com> | 2020-08-05 07:35:50 -0700 |
---|---|---|
committer | David Lord <davidism@gmail.com> | 2020-08-05 07:35:50 -0700 |
commit | 9537f4c17a1ba00184d7517b835c221715114e63 (patch) | |
tree | a301d4f6bf44311a1230e4ffdbc2b92895343e72 /tests/test_basic.py | |
parent | ce498eb559e37852e6c69651a5176b4b6fcf28e8 (diff) | |
download | click-9537f4c17a1ba00184d7517b835c221715114e63.tar.gz |
use sets for bool string check
update doc, changelog, test
Diffstat (limited to 'tests/test_basic.py')
-rw-r--r-- | tests/test_basic.py | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/tests/test_basic.py b/tests/test_basic.py index 92e7963..9daccc2 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -1,5 +1,8 @@ import os import uuid +from itertools import chain + +import pytest import click @@ -198,27 +201,24 @@ def test_boolean_option(runner): assert result.output == f"{default}\n" -def test_boolean_conversion(runner): - for default in True, False: - - @click.command() - @click.option("--flag", default=default, type=bool) - def cli(flag): - click.echo(flag) - - for value in "true", "t", "1", "yes", "y", "on": - result = runner.invoke(cli, ["--flag", value]) - assert not result.exception - assert result.output == "True\n" +@pytest.mark.parametrize( + ("value", "expect"), + chain( + ((x, "True") for x in ("1", "true", "t", "yes", "y", "on")), + ((x, "False") for x in ("0", "false", "f", "no", "n", "off")), + ), +) +def test_boolean_conversion(runner, value, expect): + @click.command() + @click.option("--flag", type=bool) + def cli(flag): + click.echo(flag, nl=False) - for value in "false", "f", "0", "no", "n", "off": - result = runner.invoke(cli, ["--flag", value]) - assert not result.exception - assert result.output == "False\n" + result = runner.invoke(cli, ["--flag", value]) + assert result.output == expect - result = runner.invoke(cli, []) - assert not result.exception - assert result.output == f"{default}\n" + result = runner.invoke(cli, ["--flag", value.title()]) + assert result.output == expect def test_file_option(runner): |