Skip to content

Commit c096a10

Browse files
authored
test: add two new tests for Parameter.__init__ (recreation of #2861) (#3012)
2 parents 0be2bd3 + cc3942a commit c096a10

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tests/test_arguments.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ def copy(item):
6363
assert result.output.splitlines() == ["name=peter id=1"]
6464

6565

66+
def test_nargs_mismatch_with_tuple_type():
67+
with pytest.raises(ValueError, match="nargs.*must be 2.*but it was 3"):
68+
69+
@click.command()
70+
@click.argument("test", type=(str, int), nargs=3)
71+
def cli(_):
72+
pass
73+
74+
6675
def test_nargs_err(runner):
6776
@click.command()
6877
@click.argument("x")

tests/test_options.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,3 +1453,33 @@ def cli(one, two):
14531453

14541454
with pytest.warns(UserWarning):
14551455
runner.invoke(cli, [])
1456+
1457+
1458+
@pytest.mark.parametrize(
1459+
("multiple", "nargs", "default", "expected_message"),
1460+
[
1461+
(
1462+
False, # multiple
1463+
2, # nargs
1464+
42, # default (not a list)
1465+
"'default' must be a list when 'nargs' != 1.",
1466+
),
1467+
(
1468+
True, # multiple
1469+
2, # nargs
1470+
[
1471+
"test string which is not a list in the list"
1472+
], # default (list of non-lists)
1473+
"'default' must be a list of lists when 'multiple' is true"
1474+
" and 'nargs' != 1.",
1475+
),
1476+
],
1477+
)
1478+
def test_default_type_error_raises(multiple, nargs, default, expected_message):
1479+
with pytest.raises(ValueError, match=expected_message):
1480+
click.Option(
1481+
["--test"],
1482+
multiple=multiple,
1483+
nargs=nargs,
1484+
default=default,
1485+
)

0 commit comments

Comments
 (0)