Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for Parameter.__init__ in src/click/core.py to improve coverage #2860

Open
vilhelmprytz opened this issue Feb 19, 2025 · 0 comments · May be fixed by #2861
Open

Add tests for Parameter.__init__ in src/click/core.py to improve coverage #2860

vilhelmprytz opened this issue Feb 19, 2025 · 0 comments · May be fixed by #2861

Comments

@vilhelmprytz
Copy link

The function Parameter.__init__ in src/click/core.py does not have 100% coverage.

Two new test cases could be added.

  1. Test this raise ValuError (where nargs != self.type.arity):

click/src/click/core.py

Lines 2112 to 2115 in 5dd6288

raise ValueError(
f"'nargs' must be {self.type.arity} (or None) for"
f" type {self.type!r}, but it was {nargs}."
)

  1. Test this raise ValuError which happens when _check_iter(check_default) raises TypeError.

click/src/click/core.py

Lines 2131 to 2143 in 5dd6288

if nargs != 1 and check_default is not None:
try:
_check_iter(check_default)
except TypeError:
if multiple:
message = (
"'default' must be a list of lists when 'multiple' is"
" true and 'nargs' != 1."
)
else:
message = "'default' must be a list when 'nargs' != 1."
raise ValueError(message) from None

vilhelmprytz added a commit to dd2480-2025-group7/click that referenced this issue Feb 19, 2025
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 pallets#2860
vilhelmprytz added a commit to dd2480-2025-group7/click that referenced this issue Feb 20, 2025
* test: add two new tests for Parameter.__init__ in src/click/core.py

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 pallets#2860

* fix too long line in tests/test_options.py

fixes following error from pre-commit run on gh actions

  tests/test_options.py:1081:89: E501 Line too long (90 > 88)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant