-
-
Notifications
You must be signed in to change notification settings - Fork 425
tools: implement dynamic jupyter utils tests using session_with_data #7209
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| """Tests for grass.jupyter.utils.""" | ||
|
|
||
| import pytest | ||
| import grass.script as gs | ||
| from grass.jupyter.utils import ( | ||
| get_region, | ||
| get_rendering_size, | ||
| get_map_name_from_d_command, | ||
| ) | ||
|
|
||
|
|
||
| def test_get_region(session_with_data): | ||
| """get_region() should match GRASS region output.""" | ||
| env = session_with_data.env | ||
|
|
||
| expected = gs.region(env=env) | ||
| result = get_region(env=env) | ||
|
|
||
| assert result["north"] == pytest.approx(expected["n"]) | ||
| assert result["south"] == pytest.approx(expected["s"]) | ||
| assert result["east"] == pytest.approx(expected["e"]) | ||
| assert result["west"] == pytest.approx(expected["w"]) | ||
|
|
||
|
|
||
| def test_get_rendering_size(): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about if neither width or height are provided?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, good point. When neither width nor height is given, the function falls back to the default bounding box limits and computes the final size from the region aspect ratio. I updated the test to cover that case and added checks for both a wide region and a tall region, since the function handles those two sizing paths separately. I also renamed the file to grass_jupyter_utils_test.py. I ran the updated tests locally and they pass. |
||
| """Test rendering size calculations.""" | ||
| wide_region = {"n": 4, "s": 0, "e": 8, "w": 0} | ||
| tall_region = {"n": 8, "s": 0, "e": 4, "w": 0} | ||
|
|
||
| # both provided | ||
| assert get_rendering_size({}, 800, 600) == (800, 600) | ||
|
|
||
| # width only | ||
| assert get_rendering_size(wide_region, 800, None) == (800, 400) | ||
|
|
||
| # height only | ||
| assert get_rendering_size(wide_region, None, 400) == (800, 400) | ||
|
|
||
| # neither provided - wide region | ||
| assert get_rendering_size(wide_region, None, None) == (600, 300) | ||
|
|
||
| # neither provided - tall region | ||
| assert get_rendering_size(tall_region, None, None) == (200, 400) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("cmd", "kwargs", "expected"), | ||
| [ | ||
| ("d.rast", {"map": "elevation"}, "elevation"), | ||
| ("d.rgb", {"red": "red_band"}, "red_band"), | ||
| ("d.legend", {"raster": "elevation"}, "elevation"), | ||
| ], | ||
| ) | ||
| def test_get_map_name_from_d_command(cmd, kwargs, expected): | ||
| """Test map name extraction from display commands.""" | ||
| assert get_map_name_from_d_command(cmd, **kwargs) == expected | ||
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.
should be probably
grass_jupyter_utils_test.py.