-
Notifications
You must be signed in to change notification settings - Fork 132
Increasing code coverage by mocking datasets #490
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
Conversation
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## main #490 +/- ##
==========================================
+ Coverage 78.55% 80.80% +2.25%
==========================================
Files 182 187 +5
Lines 15933 16615 +682
Branches 2100 2184 +84
==========================================
+ Hits 12516 13426 +910
+ Misses 2717 2443 -274
- Partials 700 746 +46 ☔ View full report in Codecov by Sentry. |
|
This is really cool, Jérémy. Looking forward to reviewing this, when you're ready. |
|
What do you think of this way of doing things? @Andrewwango |
|
@jscanvic thanks for doing this hard work. I really agree with this point (and it is not just true of datasets, but also mocking other things e.g. external libraries, maybe even long-running algorithms.)
It would be worth adding best-practice instructions somewhere in the repo about how we write tests - i.e. write tests for the intended outcome of the code, then writing code to pass these, rather than writing code then writing tests that pass on the code. AFAIK the remaining TODOs for #487 wrt. datasets are:
|
|
Thanks @Andrewwango Do we want to mock the datasets that are currently downloaded just fine on the CI server? It is not clear to me. I think all of the datasets are now tested, mocked or not (though coverage can still be increased). I added an option for mocking using an environment variable - it gets less in the way in my opinion. I'll update the contributing guide later. |
|
Mocking other datasets makes it more uniform I guess, but you're right that there's no point to mocking them if we also want to test downloading them. |
Andrewwango
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your hard work especially dealing with the CT dataset, mostly small comments
|
Thanks for having taken the time to review this PR @Andrewwango! |
|
Following what @romainvo does in #474, I changed some of the calls to patch("os.listdir", return_value=[f"{i}_HR.png" for i in range(1, 15)])
patch.object(os, "listdir", return_value=[f"{i}_HR.png" for i in range(1, 15)])For bare |
Andrewwango
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Responding to previous comments, looks good so far, happy to approve once these have been addressed!
Co-authored-by: Andrewwango <[email protected]>
Co-authored-by: Andrewwango <[email protected]>
|
Thanks Andrew! I made the changes |
Andrewwango
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Exploratory pull request towards solving #487
Data that cannot be loaded onto the CI servers can be mocked using
unittest.mock.patch.Code used for testing should ideally only test what the implementation does, and not how it does it. This is to avoid brittleness and testing the wrong thing. Mocking is an exception to this rule as, by its very nature, it is meant to alter the implementation by changing what the subroutines it calls do. This means that mocking code is necessarily coupled with the implementation which is okay but it should ideally be kept to a minimum.
From what I can tell, the best way to write tests with mocked data might be to write tests that would pass for the actual data, and then mock the data to make them pass, and not to start by mocking the data before cobbling implementation-dependent tests around it. In the case of DeepInverse, we can probably play with pytest fixtures which are currently used (in part) for downloading datasets before testing them. At least some of those tests are currently marked as skipped (
test_load_Kohler_dataset,test_load_set14_dataset) because the corresponding datasets are too big to be downloaded on CI servers. A good way to proceed might be to do the mocking there, by mocking the datasets instead of downloading them, ideally with some automated logic to determine if mocking is necessary or not.Coverage
deepinv.datasets.lidc_idri31% ➡️ 80%deepinv.datasets.set1431% ➡️ 56%deepinv.datasets.kohler30% ➡️ 79%deepinv.datasets.fmd24% ➡️ 67%deepinv.datasets.lsdir24% ➡️ 57%deepinv.datasets.flickr2k31% ➡️ 56%deepinv.datasets+13%Bugs found in the process
selfis currently missing inKohler.get_blurry_shotandKohler.select_frame.LidcIdriDatasetdoes not support the minimum version of Python supported by the library.Checks to be done before submitting your PR
python3 -m pytest tests/runs successfully.black .runs successfully.make htmlruns successfully (in thedocs/directory).