-
Notifications
You must be signed in to change notification settings - Fork 2
Test decorated actions #177
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
Open
rwb27
wants to merge
14
commits into
main
Choose a base branch
from
test-decorated-actions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I've added a stub __set__ to BaseProperty to improve type checking. Other than that, no code changes.
The ActionDescriptor really confuses mypy. It would be nice to find a better way to reference actions.
This doesn't improve the fact that the generated class can't be type checked.
None of these should affect how the code actually runs. Return types of functions used as FastAPI endpoints are also specified as the `model` and thus I don't expect any change to the API.
This also combines the two runs of mypy on src and typing_tests, as they can now both use the stricter rules.
Using `str` was converting `pending` to `InvocationStatus.PENDING` which caused the websocket tests to fail. Using `.value` fixes the problem.
These weren't flagged by dmypy but did show up with mypy.
I added a __set__ to BaseProperty to satisfy mypy, so now there is a test to check it raises an error and is overridden.
Using a decorator on an action will result in a callable that doesn't have a signature, and instead has a __wrapped__ attribute. These tests check that doesn't cause problems with LabThings. test_locking_decorator.py is a more realistic test of decorators that anticipates their use to lock functions.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In #101 and #156 it's clear there are situations where we'd like to be able to decorate actions. In #156 @julianstirling shared code that looked like it should work, but failed strangely.
This PR introduces test code for decorated actions. I was expecting it to fail, then I was going to explicitly support
__wrapped__
(which is howfunctools.wraps
works) and watch it turn green wearing a smug expression. However, the test passes already: It turns out that reading the docs and usinginspect.signature
rather than accessing magic attributes directly has paid off, because wrapped functions are already supported. Apparentlyfunctools.partial
objects should also work - this might be useful in a couple of places, but isn't relevant to this PR.Unfortunately this means I can't reproduce #156, but I think these are useful tests for a use case that I didn't know we supported.
This PR is based off the branch for #176 and should be merged afterwards
It only touches two test files, if more changes are showing, that's because the previous PR is not in yet. It may need a rebase after #176 is in.