pytroll / satpy

Python package for earth-observing satellite data processing
http://satpy.readthedocs.org/en/latest/
GNU General Public License v3.0
1.06k stars 292 forks source link

Add a testing utility for faking reading #2840

Closed mraspaud closed 2 months ago

mraspaud commented 3 months ago

This PR adds a testing utility to satpy for faking reading.

Useful for testing programs that use satpy for reading with actually needing to read anything. Can be used like this:


        scene_dict = {channel: somedata}
        with fake_satpy_reading(scene_dict):
            scene = Scene(input_files, reader="dummy_reader")
            scene.load([channel])

and the scene will be loaded with the contents of scene_dict.

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 95.98%. Comparing base (1832175) to head (f9dba55). Report is 41 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #2840 +/- ## ========================================== + Coverage 95.95% 95.98% +0.03% ========================================== Files 366 368 +2 Lines 53615 53798 +183 ========================================== + Hits 51446 51639 +193 + Misses 2169 2159 -10 ``` | [Flag](https://app.codecov.io/gh/pytroll/satpy/pull/2840/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pytroll) | Coverage Δ | | |---|---|---| | [behaviourtests](https://app.codecov.io/gh/pytroll/satpy/pull/2840/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pytroll) | `4.03% <0.00%> (-0.02%)` | :arrow_down: | | [unittests](https://app.codecov.io/gh/pytroll/satpy/pull/2840/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pytroll) | `96.08% <100.00%> (+0.03%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pytroll#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

mraspaud commented 3 months ago
  1. I'm following numpy here, as they have np.testing. I would also add that tests for me are rather internal/private, while testing is intended to be public api.
djhoese commented 3 months ago

Sounds good.

gerritholl commented 3 months ago

Users may want to debug their custom composites, both configs and actual execution of custom composite python code. Is there a way to allow for that? I suppose this would require mocking the lower-level Scene readers dictionary and distinguishing between the users scene_dict being reader datasets versus composite datasets. Maybe not worth it.

The final three tests at https://github.com/pytroll/satpy/blob/main/satpy/tests/modifier_tests/test_parallax.py test loading a composite via the Scene.load interface, involving a fake configuration file and mocking satpy.composites.config_loader.config_search_paths.

Maybe those tests could use this utility instead (not sure).

coveralls commented 2 months ago

Pull Request Test Coverage Report for Build 10058493408

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Files with Coverage Reduction New Missed Lines %
satpy/tests/reader_tests/test_ami_l1b.py 3 98.17%
satpy/readers/ami_l1b.py 4 97.32%
<!-- Total: 7 -->
Totals Coverage Status
Change from base Build 10006768762: 0.02%
Covered Lines: 51868
Relevant Lines: 53981

💛 - Coveralls
mraspaud commented 2 months ago
  1. addressed here https://satpy--2840.org.readthedocs.build/en/2840/dev_guide/testing.html