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

Test MM Core calls with mocks #239

Merged
merged 6 commits into from
Oct 20, 2022
Merged

Test MM Core calls with mocks #239

merged 6 commits into from
Oct 20, 2022

Conversation

ziw-liu
Copy link
Contributor

@ziw-liu ziw-liu commented Oct 19, 2022

Our test coverage has been declining. This is an initial attempt to address this problem by using simple mock-up objects to unit-test methods that make calls to Micro-Manger APIs.

On a side note, it may be beneficial if we isolated all outbound calls via pycromanager and aggregate them in the io.core_functions module.

Starting to address #156.

@ziw-liu ziw-liu added enhancement New feature or request testing Testing the code labels Oct 19, 2022
@ziw-liu ziw-liu added this to the 0.3.0 milestone Oct 19, 2022
@ziw-liu ziw-liu self-assigned this Oct 19, 2022
@deprecated-napari-hub-preview-bot
Copy link

deprecated-napari-hub-preview-bot bot commented Oct 19, 2022

Preview page for your plugin is ready here:
https://preview.napari-hub.org/mehta-lab/recOrder/239
Updated: 2022-10-20T00:00:09.739926

@ziw-liu ziw-liu marked this pull request as ready for review October 19, 2022 21:57
Copy link
Collaborator

@talonchandler talonchandler 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 is an excellent step towards improved test coverage, and I think you've made some really excellent choices here. Great job, Ziwen!

I really like that you're testing the io.core_functions first, and I second your idea that we should work towards isolating all of our pycromanager/external calls into io.core_functions. We're likely not far from that goal when we begin full work towards 1.0.0.

I particularly like:

  • that you've made the test image width and height random. This isn't exciting yet, but we've seen all sorts of bugs with the user selecting different ROIs (for example, see today's Phase acquisitions fail after changing MM ROI #236) not to mention challenging background correction bugs.
  • that you've marked much of the initialization code to be moved to a fixture when we're ready. I think it's great that you're taking this step by step.

I think this is ready to merge since it tests one file cleanly.

What do you think the next file/functionality to test is? I'd be particularly excited to see the calibration code tested since it will not be changing anytime soon, and we have a long list of setting combinations that we'd like to test. I can help you set up simple simulations of the LCs and cameras that will let us do a simulate a complete calibration.

Comment on lines +15 to +16
IMAGE_WIDTH = np.random.randint(1, 2**12)
IMAGE_HEIGHT = np.random.randint(1, 2**12)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool! This is a really nice place for randomness.

IMAGE_HEIGHT = np.random.randint(1, 2**12)
PIXEL_COUNT = IMAGE_HEIGHT * IMAGE_WIDTH
# serialized image from the pycromanager bridge
SERIAL_IMAGE = np.random.randint(0, TIFF_I_MAX, size=(PIXEL_COUNT,))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fantastic. I think on future iterations we can have a really simple noise model here. No changes needed now.

recOrder/tests/mmcore_tests/test_core_func.py Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Oct 19, 2022

Codecov Report

Merging #239 (df3f820) into main (5bc9314) will increase coverage by 1.51%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #239      +/-   ##
==========================================
+ Coverage   10.02%   11.54%   +1.51%     
==========================================
  Files          40       41       +1     
  Lines        5265     5355      +90     
==========================================
+ Hits          528      618      +90     
  Misses       4737     4737              
Impacted Files Coverage Δ
recOrder/tests/mmcore_tests/test_core_func.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@ziw-liu
Copy link
Contributor Author

ziw-liu commented Oct 20, 2022

I'd be particularly excited to see the calibration code tested since it will not be changing anytime soon, and we have a long list of setting combinations that we'd like to test.

I think this makes a lot of sense. One thing I (intentionally) left out in this PR is the generation of test data. I am almost convinced by this paper that we should use Hypothesis to do this, and I think we can have a better understanding of what do we need from such a tool once we start to conceive of testing the most physics-heavy part of recOrder.

@ziw-liu ziw-liu merged commit dc15b8a into main Oct 20, 2022
@ziw-liu ziw-liu deleted the test-mock-mm branch October 20, 2022 00:08
@talonchandler
Copy link
Collaborator

Just skimmed the paper...looks pretty cool. I think it's definitely worth a try.


# TODO: move these to fixture or generate with Hypothesis
# dynamic range
TIFF_I_MAX = 2**16
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd recommend also testing with 8-bit and 12-bit images in the future.

@ieivanov
Copy link
Contributor

This is great! Thanks for getting it started @ziw-liu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request testing Testing the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants