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

Organise testing utils #567

Closed
wants to merge 19 commits into from
Closed

Organise testing utils #567

wants to merge 19 commits into from

Conversation

dperl-dls
Copy link
Collaborator

@dperl-dls dperl-dls commented May 21, 2024

Fixes #564

Moves many mock device test fixtures and utility functions to a central place under src/, so that they can easily be reused by application code

Instructions to reviewer on how to test:

  1. See that no tests are broken

Checks for reviewer

  • Would the PR title make sense to a scientist on a set of release notes
  • If a new device has been added does it follow the standards
  • If changing the API for a pre-existing device, ensure that any beamlines using this device have updated their Bluesky plans accordingly

Copy link

codecov bot commented May 22, 2024

Codecov Report

Attention: Patch coverage is 98.17518% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 93.20%. Comparing base (5f375ef) to head (62a4c29).
Report is 35 commits behind head on main.

Current head 62a4c29 differs from pull request most recent head 6aa2310

Please upload reports for the commit 6aa2310 to get more accurate results.

Files Patch % Lines
src/dodal/testing_utils/__init__.py 81.25% 3 Missing ⚠️
src/dodal/devices/detector/det_dim_constants.py 50.00% 1 Missing ⚠️
src/dodal/testing_utils/constants.py 97.22% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #567      +/-   ##
==========================================
+ Coverage   92.78%   93.20%   +0.42%     
==========================================
  Files          99      104       +5     
  Lines        3769     4062     +293     
==========================================
+ Hits         3497     3786     +289     
- Misses        272      276       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dperl-dls dperl-dls marked this pull request as ready for review May 22, 2024 09:28
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.

Thank you! I'm not convinced about the structure as whole yet. Could you make the changes in hyperion so we have an example of how this improves code in a downstream app? Then I think maybe it needs a brief in person discussion



async def get_mock_device() -> Synchrotron:
async with DeviceCollector(mock=True):
Copy link
Contributor

Choose a reason for hiding this comment

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

Should: I think from looking at the docs DeviceCollector doesn't need to be async e.g. you can just do:

with DeviceCollector(mock=True):
    device = Synchrotron()

Then the whole function can be synchronous too. This is true in multiple places in this PR, can you do the same there?

Comment on lines 44 to 51
SYNCHR_RING_CURRENT = 0.556677
SYNCHR_USER_COUNTDOWN = 55.0
SYNCHR_START_COUNTDOWN = 66.0
SYNCHR_END_COUNTDOWN = 77.0
SYNCHR_BEAM_ENERGY = 3.0158
SYNCHR_MODE = "Injection"
SYNCHR_NUMBER = "number"
SYNCHR_STRING = "string"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could: I sort of feel these should be with the device too but I don't want to pollute the device namespace too much. Maybe we add the convention of as well as get_mock_device you also have a dict/dataclass of TESTING_CONSTS?

async def mock_aperturescatterguard_with_call_log():
call_log = MagicMock()
ap_sg = await get_mock_ap_sg()
with (
Copy link
Contributor

Choose a reason for hiding this comment

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

Should: patch_ophyd_async_motor isn't a context manager

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes it is, it's type-hinted wrong in ophyd-async, fix has been merged but not released, doesn't affect functionality

patch_ophyd_async_motor(ap_sg.aperture.y, call_log=call_log),
patch_ophyd_async_motor(ap_sg.aperture.z, call_log=call_log),
patch_ophyd_async_motor(ap_sg.scatterguard.x, call_log=call_log),
patch_ophyd_async_motor(ap_sg.scatterguard.y, call_log=call_log),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should: Can we do this patching in get_mock_ap_sg?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no, it leads to circular import errors if we import test utils to device classes and then device classes to test utils



@pytest.fixture
def mock_eiger_and_stage(mock_eiger):
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Rename to something like mock_eiger_with_noop_stage?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

haha, that's actually what I had first and I changed it to this

@dperl-dls
Copy link
Collaborator Author

never mind, this is too hard, I now think it's better to just copy and paste stuff everywhere

@dperl-dls dperl-dls closed this May 23, 2024
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.

Organise testing fixtures and utilities so that they can be made use of by application code
2 participants