Fix test_callable_spec to handle keyword only parameters#2040
Fix test_callable_spec to handle keyword only parameters#2040the-allanc wants to merge 2 commits intocherrypy:mainfrom
test_callable_spec to handle keyword only parameters#2040Conversation
8e49095 to
c4ca792
Compare
|
Currently tests fail in versions of Python that have reached EOL - see #2041. |
|
Clicking “rebase” in this PR... |
Also fixed some mistakes in the tests themselves.
This is done by delegating the validation to inspect.Signature.bind, and processing the error that it raises.
c4ca792 to
8002e15
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2040 +/- ##
==========================================
- Coverage 76.74% 76.74% -0.01%
==========================================
Files 107 107
Lines 13986 13956 -30
Branches 1702 1689 -13
==========================================
- Hits 10734 10710 -24
+ Misses 2641 2635 -6
Partials 611 611 🚀 New features to boost your workflow:
|
webknjaz
left a comment
There was a problem hiding this comment.
cherrypy/test/test_request_obj.py::RequestObjectTests::testParamErrors is broken on Python 3.12. It probably needs some compat fallbacks for >= 3.12. I haven't yet added 3.13 to the CI but I expect it to fail the same.
test_callable_spec to handle keyword only parameters
|
@the-allanc FYI it looks like the email in the commits ( |
What kind of change does this PR introduce?
What is the related issue number (starting with
#)None.
What is the current behavior? (You can also link to an open issue here)
If a TypeError occurs inside the execution of the handler, and the handler has had keyword parameters passed to it, test_callable_spec will cause a 404 to be returned, rather than allowing the TypeError to be correctly propagated as a 500 response.
What is the new behavior (if this is a feature change)?
We delegate validation of the provided args and kwargs against the callable to the inspect module, which adds support for keyword-only parameters while removing the need to perform these checks directly in CherryPy. In the situation mentioned previously, this means we correctly raise a 500 error instead of returning a 404 response.
Other information:
I've kept the behaviour compatible with what was previously there regarding reporting user-friendly messages when "show_mismatched_params" is enabled (all previous tests pass), but I've also added additional checks to testParamErrors which will fail if using the current code in _cpdispatch.py. There were also some bugs in the tests which I found while making these changes that I've fixed.
Checklist:
and description in grammatically correct, complete sentences