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

Allow shared parent mock to be passed to Device.connect #599

Merged
merged 4 commits into from
Oct 31, 2024
Merged

Conversation

jsouter
Copy link
Contributor

@jsouter jsouter commented Oct 4, 2024

Addresses #336

Allows a Device to accept a unittest.Mock or a boolean.
If True passed, creates a new Mock()
if Mock() passed, finds any child mocks set with attach_mock if they exist, else passes down mock=True to children.

Will push some tests for this

edit: now realising that I misunderstood the requirements, will fix quickly!

Copy link
Contributor

@DominicOram DominicOram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks about right. As you say a bunch of tests confirming all the use cases would be great

@jsouter
Copy link
Contributor Author

jsouter commented Oct 7, 2024

Would have to call attach_mock after each child device is connected as that is when the signal backend gets set to MockSignalBackend and the _backend.put_mock can be accessed. Tom has said he may touch how that is handled soon so I will wait for that to be done first.

@coretl
Copy link
Collaborator

coretl commented Oct 14, 2024

#594 is sufficiently advanced that you can work on top of it to see if you can apply this on top of it

@jsouter jsouter changed the base branch from main to signal-typing October 17, 2024 08:20
@jsouter
Copy link
Contributor Author

jsouter commented Oct 17, 2024

I've rebased on top of #594, still a WIP but it appears to work with the existing tests. I will work on porting over the new tests I added in the force-pushed-over commits here

@jsouter jsouter force-pushed the shared_mock branch 3 times, most recently from 2785615 to 204aab2 Compare October 18, 2024 09:55

from ._device import Device
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is mostly in a sensible state now, depending on if we're happy with get_mock in _mock_signal_utils accepting Device | Signal

@jsouter jsouter marked this pull request as ready for review October 18, 2024 10:14
src/ophyd_async/core/_device.py Outdated Show resolved Hide resolved
src/ophyd_async/core/_mock_signal_utils.py Outdated Show resolved Hide resolved
src/ophyd_async/core/_mock_signal_utils.py Show resolved Hide resolved
src/ophyd_async/core/_mock_signal_backend.py Outdated Show resolved Hide resolved
src/ophyd_async/core/_device.py Outdated Show resolved Hide resolved
src/ophyd_async/core/_device.py Outdated Show resolved Hide resolved
src/ophyd_async/core/_mock_signal_backend.py Outdated Show resolved Hide resolved
src/ophyd_async/core/_mock_signal_backend.py Outdated Show resolved Hide resolved
src/ophyd_async/core/_mock_signal_utils.py Outdated Show resolved Hide resolved
Base automatically changed from signal-typing to main October 30, 2024 10:57
@coretl
Copy link
Collaborator

coretl commented Oct 31, 2024

Shall I merge?

@jsouter
Copy link
Contributor Author

jsouter commented Oct 31, 2024

Shall I merge?

I'm happy with it unless @DominicOram has any more thoughts

@coretl coretl merged commit 0df62dd into main Oct 31, 2024
18 checks passed
@coretl coretl deleted the shared_mock branch October 31, 2024 14:30
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.

Add a shared parent mock for all signals in once device
3 participants