-
-
Notifications
You must be signed in to change notification settings - Fork 335
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
r.clump: added tests for r.clump module #4733
Open
Shreshth-Malik
wants to merge
8
commits into
OSGeo:main
Choose a base branch
from
Shreshth-Malik:r.clump-test
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.
+167
−0
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
09a8160
Added tests for r.clump tool
Shreshth-Malik 930711d
Added the test files to "tests" folder
Shreshth-Malik c1338d9
Merge branch 'main' into r.clump-test
echoix 925b2d6
added minsize and threshold tests, added conftest file and worked on …
Shreshth-Malik 0783946
Merge branch 'r.clump-test' of https://github.com/Shreshth-Malik/gras…
Shreshth-Malik 19f0598
Merge branch 'main' into r.clump-test
Shreshth-Malik 51e2351
Formatted conftest.py
Shreshth-Malik f329e15
Merge branch 'r.clump-test' of https://github.com/Shreshth-Malik/gras…
Shreshth-Malik 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 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,70 @@ | ||
import pytest | ||
from grass.script import run_command, read_command, parse_command | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def setup_map(): | ||
"""Set up a temporary region and generate a clumped map.""" | ||
# Set the region | ||
run_command("g.region", n=3, s=0, e=3, w=0, res=1) | ||
|
||
# Create the custom map | ||
# 5 null null | ||
# null 5 null | ||
# null 6 6 | ||
run_command( | ||
"r.mapcalc", | ||
expression=( | ||
"custom_map = " | ||
"if(row() == 1 && col() == 1, 5, " | ||
"if(row() == 2 && col() == 2, 5, " | ||
"if(row() == 3 && col() >= 2, 6, null())))" | ||
), | ||
overwrite=True, | ||
) | ||
yield | ||
|
||
# Teardown: Remove maps | ||
run_command( | ||
"g.remove", flags="f", type="raster", name=["custom_map", "clumped_map"] | ||
) | ||
|
||
|
||
def test_clump_basic(setup_map): | ||
"""Test basic clumped map.""" | ||
|
||
run_command("r.clump", input="custom_map", output="clumped_map", overwrite=True) | ||
|
||
output_maps = parse_command("g.list", type="raster") | ||
assert "clumped_map" in output_maps, "Output raster map 'clumped_map' should exist" | ||
|
||
category_output = read_command("r.category", map="clumped_map").strip().split("\n") | ||
actual_categories = { | ||
int(line.split("\t")[0]): line.split("\t")[1].strip() if "\t" in line else "" | ||
for line in category_output | ||
} | ||
|
||
expected_categories = {1: "", 2: "", 3: ""} | ||
petrasovaa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
assert set(actual_categories.keys()) == set(expected_categories.keys()) | ||
|
||
|
||
def test_clump_diagonal(setup_map): | ||
"""Test clumped map with diagonal connectivity.""" | ||
|
||
run_command( | ||
"r.clump", input="custom_map", output="clumped_map", flags="d", overwrite=True | ||
) | ||
|
||
output_maps = parse_command("g.list", type="raster") | ||
assert "clumped_map" in output_maps, "Output raster map 'clumped_map' should exist" | ||
|
||
category_output = read_command("r.category", map="clumped_map").strip().split("\n") | ||
actual_categories = { | ||
int(line.split("\t")[0]): line.split("\t")[1].strip() if "\t" in line else "" | ||
for line in category_output | ||
} | ||
|
||
expected_categories = {1: "", 2: ""} | ||
|
||
assert set(actual_categories.keys()) == set(expected_categories.keys()) |
Unchanged files with check annotations Beta
This file contains 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
- name: Set number of cores for compilation | ||
run: | | ||
echo "MAKEFLAGS=-j$(nproc)" >> $GITHUB_ENV | ||
Check warning on line 149 in .github/workflows/python-code-quality.yml
|
||
- uses: rui314/setup-mold@b015f7e3f2938ad3a5ed6e5111a8c6c7c1d6db6e # v1 | ||
- name: Build | ||
run: .github/workflows/build_${{ matrix.os }}.sh $HOME/install |
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.
r.category has json output, you can use parse_command to get the list
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.
because r.category already has format option, the call is more complicated:
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.
This still needs to be done.