Repository navigation
d.correlate: exit on insufficient input and fix text line counter #7485
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
Merged
echoix
merged 2 commits into
OSGeo:main
from
Valyrian-Code:d.correlate-exit-on-insufficient-maps
Jun 20, 2026
Merged
Changes from all commits
Commits
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,47 @@ | ||
| """Tests of d.correlate""" | ||
|
|
||
| import pytest | ||
|
|
||
| from grass.exceptions import CalledModuleError | ||
| from grass.tools import Tools | ||
|
|
||
|
|
||
| def render_tools(session, tmp_path): | ||
| """Return a Tools object for the session's mapset with an offscreen renderer. | ||
|
|
||
| A copy of the session environment is used, rather than mutating it, so the | ||
| cairo render settings do not leak into the shared session fixture. | ||
| d.correlate is a display tool, so the tests need a working render target; | ||
| without one the tool would fail at its first d.text call and mask the | ||
| behavior under test. | ||
| """ | ||
| env = dict(session.env) | ||
| env["GRASS_RENDER_IMMEDIATE"] = "cairo" | ||
| env["GRASS_RENDER_FILE"] = str(tmp_path / "correlate.png") | ||
| return Tools(env=env) | ||
|
|
||
|
|
||
| def test_fewer_than_two_maps_is_fatal(xy_raster_dataset_session_mapset, tmp_path): | ||
| """d.correlate must fail, not silently succeed, with fewer than two maps. | ||
|
|
||
| Regression test: a single map previously printed an error but still exited | ||
| with a success code and produced no output. | ||
| """ | ||
| tools = render_tools(xy_raster_dataset_session_mapset, tmp_path) | ||
| tools.r_mapcalc(expression="map_a = 1") | ||
| with pytest.raises(CalledModuleError): | ||
| tools.d_correlate(map="map_a") | ||
|
|
||
|
|
||
| def test_more_than_two_maps_runs(xy_raster_dataset_session_mapset, tmp_path): | ||
| """d.correlate handles more than two maps without crashing. | ||
|
|
||
| Regression test: the per-pair text line counter was reused as the | ||
| file-iteration variable, raising a TypeError on the second map pair (that | ||
| is, whenever three or more maps were given). | ||
| """ | ||
| tools = render_tools(xy_raster_dataset_session_mapset, tmp_path) | ||
| tools.r_mapcalc(expression="map_a = 1") | ||
| tools.r_mapcalc(expression="map_b = col()") | ||
| tools.r_mapcalc(expression="map_c = row()") | ||
| tools.d_correlate(map="map_a,map_b,map_c") | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.