Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/grass/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(PYDIRS
pygrass/shell
pygrass/tests
pygrass/vector
pytest
script
semantic_label
temporal
Expand Down
Empty file added python/grass/pytest/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions python/grass/pytest/assertions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import grass.script as gs


def rasterExists(map_name, env=None):
"""Check if a raster map exists in the given mapset."""
result = gs.find_file(map_name, element="cell", env=env)
return bool(result["name"])
12 changes: 12 additions & 0 deletions python/grass/pytest/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
import pytest
import grass.script as gs


@pytest.fixture
def session(tmp_path):
project = tmp_path / "test_proj"
gs.create_project(project)

with gs.setup.init(project, env=os.environ.copy()) as session:
yield session.env

Check failure on line 12 in python/grass/pytest/conftest.py

View workflow job for this annotation

GitHub Actions / Python Code Quality Checks (ubuntu-24.04)

Ruff (W292)

python/grass/pytest/conftest.py:12:26: W292 No newline at end of file
9 changes: 9 additions & 0 deletions python/grass/pytest/tests/test_assertions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import grass.script as gs
from grass.pytest.assertions import rasterExists


def test_rasterExists(session):
gs.run_command("r.mapcalc", expression="test_map = 1", env=session)

assert rasterExists("test_map", env=session)
assert not rasterExists("missing_map", env=session)

Check failure on line 9 in python/grass/pytest/tests/test_assertions.py

View workflow job for this annotation

GitHub Actions / Python Code Quality Checks (ubuntu-24.04)

Ruff (W292)

python/grass/pytest/tests/test_assertions.py:9:56: W292 No newline at end of file
Loading