-
Notifications
You must be signed in to change notification settings - Fork 287
Fix get_nexrad_location mutating shared NEXRAD_LOCATIONS table #1879
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
Open
Yuxiang-Ren-HUB
wants to merge
3
commits into
ARM-DOE:main
Choose a base branch
from
Yuxiang-Ren-HUB:fix-nexrad-location-mutation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+39
−3
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| """Unit Tests for Py-ART's io/nexrad_common.py module.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from pyart.io import nexrad_common | ||
|
|
||
|
|
||
| def test_get_nexrad_location_known_station(): | ||
| lat, lon, elev = nexrad_common.get_nexrad_location("KTLX") | ||
| assert lat == pytest.approx(35.33306, abs=1e-3) | ||
| assert lon == pytest.approx(-97.2775, abs=1e-3) | ||
| # bundled table stores elevation in feet (1213 ft); function must | ||
| # return meters | ||
| assert elev == pytest.approx(1213 * 0.3048, abs=1e-6) | ||
|
|
||
|
|
||
| def test_get_nexrad_location_repeated_calls_are_stable(): | ||
| # Regression test: get_nexrad_location used to mutate the shared | ||
| # NEXRAD_LOCATIONS dict in place (loc["elev"] = loc["elev"] * 0.3048, | ||
| # where loc is a reference into the module-level table, not a copy). | ||
| # A second call for the same station then applied the feet->meters | ||
| # conversion again on top of the already-converted value, silently | ||
| # corrupting the elevation. | ||
| _, _, elev_first = nexrad_common.get_nexrad_location("KTLX") | ||
| _, _, elev_second = nexrad_common.get_nexrad_location("KTLX") | ||
| _, _, elev_third = nexrad_common.get_nexrad_location("KTLX") | ||
| assert elev_first == elev_second == elev_third | ||
| # and the underlying table itself must be untouched (still in feet) | ||
| assert nexrad_common.NEXRAD_LOCATIONS["KTLX"]["elev"] == 1213 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think the behavior
table values changesshould be preserved as some code in the wild may be relying on it. We may add units to know if the height is already changed in meters or not. If yes then conversion will return the values but will not change it back in the table again. This will preserved the behavior.