grass.jupyter: Add comprehensive tests for utils.py#7205
grass.jupyter: Add comprehensive tests for utils.py#7205saurabh12nxf wants to merge 5 commits intoOSGeo:mainfrom
Conversation
|
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, Should I proceed with this, or is there a higher-priority area you'd recommend? Thanks! |
petrasovaa
left a comment
There was a problem hiding this comment.
- 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).
- 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. - 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. - Copy-paste error in docstring: test_east_greater_than_west says "greater than south coordinate."
- Typo: test_postive_resolution — "postive".
- test_contains_proj_keyword only exercises the XY branch since the fixture is always unprojected. The PROJ.4 path is never tested.
- 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.
|
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.) |
Description
This PR adds comprehensive pytest tests for the
grass.jupyter.utilsmodule, which previously had minimal test coverage.Changes
Added 21 new tests covering 5 critical utility functions:
get_region()- 6 tests validating region dictionary structureget_location_proj_string()- 3 tests for projection string handlingget_rendering_size()- 8 tests for aspect ratio calculationsget_number_of_cores()- 4 tests for CPU allocation logicreproject_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 -v21 passed, 4 skippedpytest python/grass/jupyter/tests/ -v73 passed, 4 skipped