Skip to content
Myr

test: add two new tests for Parameter.__init__ in src/click/core.py

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

The function Parameter.__init__ does not have 100% coverage. This commit adds two new test cases that improve the coverage. The first one tests that a ValueError is raised when `nargs != self.type.arity`. The second one tests that a ValueError is raised when `_check_iter(check_default)` raises `TypeError`. Fixes #2860 Recreation of #2861

authored by Kevin Deldycke · committed by Kevin Deldycke · parent 0be2bd3 · Browse files · 2 files+39 added−0 removed
This commit

State

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

Diff stats

2 files+39 added−0 removed

  • tests:+39 added−0 removed

2 files+39 added−0 removed

modified:tests/test_arguments.py+9 added
61 unmodified lines
62 assert result.exception is None63 assert result.output.splitlines() == ["name=peter id=1"]646566def test_nargs_mismatch_with_tuple_type():67 with pytest.raises(ValueError, match="nargs.*must be 2.*but it was 3"):6869 @click.command()70 @click.argument("test", type=(str, int), nargs=3)71 def cli(_):72 pass737475def test_nargs_err(runner):76 @click.command()77 @click.argument("x")78 def copy(x):
392 unmodified lines
modified:tests/test_options.py+30 added
1451 unmodified lines
1452 pass14531454 with pytest.warns(UserWarning):1455 runner.invoke(cli, [])145614571458@pytest.mark.parametrize(1459 ("multiple", "nargs", "default", "expected_message"),1460 [1461 (1462 False, # multiple1463 2, # nargs1464 42, # default (not a list)1465 "'default' must be a list when 'nargs' != 1.",1466 ),1467 (1468 True, # multiple1469 2, # nargs1470 [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)1478def 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 )