bluesky / ophyd-async

Hardware abstraction for bluesky written using asyncio
https://blueskyproject.io/ophyd-async
BSD 3-Clause "New" or "Revised" License
11 stars 26 forks source link

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

Closed jsouter closed 3 weeks ago

jsouter commented 1 month ago

Addresses https://github.com/bluesky/ophyd-async/issues/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!

jsouter commented 1 month ago

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 commented 1 month ago

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

jsouter commented 1 month ago

I've rebased on top of https://github.com/bluesky/ophyd-async/pull/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

coretl commented 3 weeks ago

Shall I merge?

jsouter commented 3 weeks ago

Shall I merge?

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