-
Notifications
You must be signed in to change notification settings - Fork 48
CI Test Clean Up: Mock USGS, Acoustic Tolerances #404
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
|
@akeeste this is ready for review |
akeeste
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 @ssolson this looks good to me. Approved.
One clarifying question on what the test behavior is like when mocked
| df = river.io.usgs.request_usgs_data( | ||
| station="15515500", | ||
| parameter="00060", | ||
| start_date="2009-08-01", | ||
| end_date="2009-08-10", | ||
| options={"data_type": "Instantaneous"}, | ||
| options={"data_type": "Instantaneous", "clear_cache": True}, | ||
| ) |
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.
With this mocking set-up, will this function call to river.io.usgs.request_usgs_data() still attempt to hit the USGS API once even though we don't test its output, or is that also skipped?
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.
Hey Adam The short answer is no, the usgs API is not hit.
The key line is:
@patch("mhkit.river.io.usgs.requests.get")
The process is:
- The @patch decorator replaces the requests.get function with a mock object before the test runs
- The mock is configured to return a fake response with status code 200 and the mock payload
- When request_usgs_data() is called, it will internally call requests.get()
- The mock intercepts this call and returns the fake response instead of making a real HTTP request
- The real USGS API is never contacted
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.
Got it, that makes sense. I see the call to requests.get() within usgs.io.request_usgs_data() now. Thanks!
## Summary
1. Replaced live USGS API calls with mock calls in tests to prevent
failures in GitHub Actions due to repeated API connectivity issues. This
ensures the functions are still invoked without being dependent on
external API availability.
2. Adjusted acoustic module test tolerances to account for minor
floating-point discrepancies. These discrepancies likely stem from:
- Over-precise stored constants created in older environments.
- Cumulative rounding errors from sequential operations (e.g.,
band_aggregate followed by time_aggregate).
- Changes in behavior in newer versions of NumPy, Pandas, or xarray.
#### Justification for Tolerance Adjustment
- A tolerance of 1e-5 is acceptable since decibel outputs are typically
displayed with only two decimal places.
- Numerical differences at this scale (1e-6 to 1e-5) are common due to
aggregation method variations
To resolve some intermittent tests failing when using conda and 3.11, this PR bumps some acoustics tolerances to 1e-5 as reasoned in #404
v1.0.0 # MHKiT v1.0.0 ## New Features * Sound Exposure Level by @jmcvey3 in #388 * Add discharge function to MHKiT by @jmcvey3 in #385 ## Functionality enhancements * Fix for corrupted Nortek files by @jmcvey3 in #372 * Update integral length scale function by @jmcvey3 in #376 * Fix ever-changing RDI RiverPro depth bin ranges by @jmcvey3 in #378 * Allow clean functions to handle _avg variables by @jmcvey3 in #377 * IEC TS 62600 updates by @akeeste in #382 * MLER explanation updates/corrections by @rgcoe in #393 * Improve Nortek2 index file creator functions by @jmcvey3 in #397 * Read Sentinel V specific data packets by @jmcvey3 in #396 * Short list of VMDAS updates by @jmcvey3 in #405 * Allow user to specify universal Kolmogorov constant for TKE dissipation rate function by @jmcvey3 in #406 * Nortek Dual Profile Dataset Rotation by @jmcvey3 in #414 ## Source code improvements * Lint Tidal by @ssolson in #386 * Lint river module by @ssolson in #389 * Lint hindcast by @ssolson in #398 * Modernize Package Configuration by @ssolson in #400 * Configure specific warnings by @ssolson in #401 ## Bug fixes * Avoid failing to scan very large files by @jmcvey3 in #371 * Acoustics SPL bugfix by @jmcvey3 in #379 * DOLfYN/RDI: Set `fs` to NaN when typical calculation methods yield error (#408) by @simmsa in #409 ## Testing and Continuous Integration Updates * Fix Jupyter Notebook tests running Python 3.13 by @ssolson in #380 * CI Test Clean Up: Mock USGS, Acoustic Tolerances by @ssolson in #404 * Speed up tests with concurrency checks to prevent duplicate workflows on PRs from develop into main or from main into develop by @akeeste * Define MPLBACKEND to decrease intermittent matplotlib errors in tests by @akeeste ## Documentation and Examples * Add WEC-Sim power performance example by @akeeste in #395 * Update dolfyn function docstrings and associated notebooks by @jmcvey3 in #412 * Update examples by @akeeste in #417 * Update installation instructions in README.md by @akeeste * Adjust acoustics test tolerances by @akeeste in #420 **Full Changelog**: v0.9.0...v1.0.0
Summary
Justification for Tolerance Adjustment