Skip to content

Commit 2aa4836

Browse files
authored
r.slope.aspect: Show behavior with repeated output name in a test (OSGeo#6347)
While working in OSGeo#5877, I checked how r.slope.aspect behaves when multiple output parameters are set to the same name, e.g., slope=slope aspect=slope. While the current behavior is not ideal, and I'm not adding it to the documentation, i.e., leaving it undefined, the test at least makes it clear what is the current behavior, providing a starting point for any future changes.
1 parent 66ca756 commit 2aa4836

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
3+
import pytest
4+
5+
import grass.script as gs
6+
from grass.tools import Tools
7+
8+
9+
@pytest.fixture
10+
def xy_dataset_session(tmp_path):
11+
"""Active session in an XY location (scope: function)"""
12+
project = tmp_path / "xy_test"
13+
gs.create_project(project)
14+
with (
15+
gs.setup.init(project, env=os.environ.copy()) as session,
16+
Tools(session=session) as tools,
17+
):
18+
tools.g_region(s=0, n=5, w=0, e=6, res=1)
19+
tools.r_mapcalc(expression="rows_raster = row()")
20+
yield session
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from grass.tools import Tools
2+
3+
4+
def test_repeated_output(xy_dataset_session):
5+
"""Check behavior when two outputs have the same name
6+
7+
This is practically undefined behavior, but here, we test the current behavior
8+
which is that one of the outputs wins (regardless of the order of the provided
9+
parameters or other in the interface).
10+
"""
11+
tools = Tools(session=xy_dataset_session, consistent_return_value=True)
12+
name = "output_1"
13+
14+
tools.r_slope_aspect(elevation="rows_raster", aspect=name, slope=name)
15+
stats = tools.r_univar(map=name, format="json")
16+
# This is slope.
17+
assert stats["min"] == 45
18+
assert stats["max"] == 45
19+
assert stats["sum"] == 540
20+
21+
name = "output_2"
22+
tools.r_slope_aspect(elevation="rows_raster", dx=name, dy=name, slope=name)
23+
stats = tools.r_univar(map=name, format="json")
24+
# This is dy.
25+
assert stats["min"] == 1
26+
assert stats["max"] == 1
27+
assert stats["sum"] == 12

0 commit comments

Comments
 (0)