Skip to content

r.random.cells: migrate tests from gunittest to pytest - #7893

Open
Valyrian-Code wants to merge 2 commits into
OSGeo:mainfrom
Valyrian-Code:r.random.cells-pytest
Open

r.random.cells: migrate tests from gunittest to pytest#7893
Valyrian-Code wants to merge 2 commits into
OSGeo:mainfrom
Valyrian-Code:r.random.cells-pytest

Conversation

@Valyrian-Code

Copy link
Copy Markdown
Contributor

Migrates the r.random.cells testsuite from gunittest to pytest, continuing the one-at-a-time migrations from #7635/#7675/#7780.

Keeps the same three cases and the same seed=100, so the reproduced values match the original test:

  • distance=0.01 fills every cell with a unique category (cells == n, no nulls)
  • distance=2.00001 (just over the cell width) fills less than half the cells; the exact count depends on the random sequence, so this keeps the original's loose upper-bound check rather than pinning an exact value
  • ncells=12 limits the fill to exactly that many cells

Verified locally, all three pass.

Copilot AI lite review requested due to automatic review settings September 5, 2026 19:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Migrates r.random.cells test coverage from the legacy gunittest harness to pytest, preserving the three existing behavioral cases and seed-based expectations.

Changes:

  • Removes the gunittest-based test file under testsuite/.
  • Adds a new pytest test module using an isolated GRASS project/session fixture.
  • Re-implements the same three assertions using r.univar JSON output.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
raster/r.random.cells/testsuite/test_random_cells.py Removes the previous gunittest tests being migrated.
raster/r.random.cells/tests/r_random_cells_test.py Adds pytest equivalents using grass.script + Tools and r.univar JSON assertions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +13 to +21
@pytest.fixture
def session(tmp_path):
"""An isolated GRASS session with the region r.random.cells fills."""
project = tmp_path / "r_random_cells_project"
gs.create_project(project)
with gs.setup.init(project, env=os.environ.copy()) as session:
tools = Tools(session=session)
tools.g_region(n=20, s=10, e=60, w=40, res=2)
yield session
Comment thread raster/r.random.cells/tests/r_random_cells_test.py Outdated
@@ -0,0 +1,62 @@
# SPDX-License-Identifier: GPL-2.0-or-later


@pytest.fixture
def session(tmp_path):
@echoix

echoix commented Sep 5, 2026

Copy link
Copy Markdown
Member

@wenzeslaus Is there a known pattern for gunittest "assertRasterFitsUnivar" to pytest? Otherwise, we would be recopying the assertions but we are loosing the fact that these multiple independant asserts mean something when together (so the pattern will probably diverge accross files in the future).

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Valyrian-Code

Copy link
Copy Markdown
Contributor Author

Thanks for the review. A few notes:

  • Fixture scope: kept function-scoped on purpose, isolated per test with a fresh tmp_path project. This matches the pattern in the already-merged r.cross (r.cross: migrate tests from gunittest to pytest #7635) and r.null (r.null: migrate tests from gunittest to pytest #7675) migrations, and avoids the shared-state cleanup that a module or session scope would need between tests.
  • SPDX-FileCopyrightText: neither r.null nor r.cross added this to their new pytest files, only SPDX-License-Identifier, so kept it consistent with that.
  • Fixture name: "session" matches the name used in r.null and r.support's already-merged tests, so kept it for consistency across the migrated files.

@github-actions github-actions Bot added raster Related to raster data processing Python Related code is in Python module tests Related to Test Suite labels Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module Python Related code is in Python raster Related to raster data processing tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants