Skip to content

grass.jupyter: Add comprehensive tests for utils.py#7205

Open
saurabh12nxf wants to merge 5 commits intoOSGeo:mainfrom
saurabh12nxf:add-utils-tests
Open

grass.jupyter: Add comprehensive tests for utils.py#7205
saurabh12nxf wants to merge 5 commits intoOSGeo:mainfrom
saurabh12nxf:add-utils-tests

Conversation

@saurabh12nxf
Copy link
Copy Markdown
Contributor

@saurabh12nxf saurabh12nxf commented Mar 21, 2026

Description

This PR adds comprehensive pytest tests for the grass.jupyter.utils module, which previously had minimal test coverage.

Changes

Added 21 new tests covering 5 critical utility functions:
get_region() - 6 tests validating region dictionary structure
get_location_proj_string() - 3 tests for projection string handling
get_rendering_size() - 8 tests for aspect ratio calculations
get_number_of_cores() - 4 tests for CPU allocation logic
reproject_region() - 4 tests for coordinate transformation (skipped for XY locations)

Testing
All tests pass both in isolation and when run with the full test suite:
pytest python/grass/jupyter/tests/test_utils.py -v 21 passed, 4 skipped
pytest python/grass/jupyter/tests/ -v 73 passed, 4 skipped

@github-actions github-actions Bot added Python Related code is in Python libraries tests Related to Test Suite notebook labels Mar 21, 2026
@saurabh12nxf saurabh12nxf changed the title Add comprehensive tests for grass.jupyter.utils grass.jupyter : Add comprehensive tests for utils.py Mar 21, 2026
@saurabh12nxf saurabh12nxf changed the title grass.jupyter : Add comprehensive tests for utils.py grass.jupyter: Add comprehensive tests for utils.py Mar 21, 2026
@saurabh12nxf
Copy link
Copy Markdown
Contributor Author

Hi @petrasovaa,

Quick question: I've submitted my GSoC proposal and want to keep contributing.

I'd like to improve pytest coverage for grass.jupyter modules (timeseriesmap,
seriesmap, map3d and others). These align with my proposal's testing focus.

Should I proceed with this, or is there a higher-priority area you'd recommend?

Thanks!
Saurabh

Copy link
Copy Markdown
Contributor

@petrasovaa petrasovaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. All reproject_region tests are always skipped. session_with_data creates an XY project, so every test hits the pytest.skip. These tests never actually run. You need a fixture with a projected session (e.g., EPSG:26917).
  2. get_number_of_cores tests don't account for NPROCS. The function checks gisenv for NPROCS first and returns it directly, bypassing the requested parameter and system core cap. test_respects_requested_cores and
    test_caps_at_available_cores would fail if NPROCS is set.
  3. test_minimum_one_core asserts >= 0 — that can never fail. min(0, positive) is always 0, so the assertion is trivially true. Either test and document that 0 is returned (with == 0), or flag that this might be a bug in the
    function.
  4. Copy-paste error in docstring: test_east_greater_than_west says "greater than south coordinate."
  5. Typo: test_postive_resolution — "postive".
  6. test_contains_proj_keyword only exercises the XY branch since the fixture is always unprojected. The PROJ.4 path is never tested.
  7. Over-granular TestGetRegion: 6 separate tests each calling get_region() — these could be one test checking all properties, avoiding repeated session overhead.

Disclaimer: it's AI review, but please consider it.

@saurabh12nxf
Copy link
Copy Markdown
Contributor Author

Hi @petrasovaa

while investigating the recent CI failures on macOS and Windows, I noticed that TestReprojectRegion tests are failing with OSError: Cannot find the executable m.proj.

I realized this is because reproject_region() in utils.py relies on gs.start_command() to execute m.proj, but unlike get_region(env=None) and get_location_proj_string(env=None), it does not accept or pass down an env parameter. Because Pytest runs without a global GRASS environment setup on these runners, the subprocess spawns in an isolated state and cannot locate the m.proj executable in its PATH.

I see two approaches to resolve this:

Fix utils.py directly (Recommended): I can add an env=None parameter to reproject_region() and forward it to gs.start_command("m.proj", env=env). This makes the function consistent with the other utilities in this module and permanently fixes this latent bug.

Handle it test-side: I can leave utils.py untouched and instead use pytest's monkeypatch explicitly within TestReprojectRegion to inject session_projected.env into the global environment state temporarily. (Note: I know we recently removed monkeypatching for NPROCS, so I wanted to check before doing this.)
Would you prefer I implement the fix inside utils.py or keep everything confined to the test file using Pytest tools?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libraries notebook Python Related code is in Python tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants