Skip to content

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
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Test decorated actions #177

wants to merge 14 commits into from

Conversation

rwb27
Copy link
Collaborator

@rwb27 rwb27 commented Aug 16, 2025

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 how functools.wraps works) and watch it turn green wearing a smug expression. However, the test passes already: It turns out that reading the docs and using inspect.signature rather than accessing magic attributes directly has paid off, because wrapped functions are already supported. Apparently functools.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.

rwb27 added 14 commits August 15, 2025 00:23
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant