Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
47 changes: 0 additions & 47 deletions raster3d/r3.retile/test.r3.retile.sh

This file was deleted.

68 changes: 68 additions & 0 deletions raster3d/r3.retile/tests/r3_retile_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""Test r3.retile

The reference files in the data directory come from the former shell test.
test_retile_map_N.ref is the expected r3.out.ascii output and
test_retile_map_N_info.ref the expected r3.info -g output of map N.
"""

import os
from pathlib import Path

import pytest

import grass.script as gs
from grass.tools import Tools

DATA_DIR = Path(__file__).parent / "data"

# The references predate these keys of r3.info -g.
KEYS_NOT_IN_REF = {"rows", "cols", "depths"}

# Reference number, tile dimensions, and whether tile caching is disabled
CASES = [
(1, "1x1x1", False),
(2, "1x1x1", True),
(3, "8x8x4", False),
(4, "8x8x4", True),
(5, "16x16x16", False),
(6, "16x16x16", True),
(7, "35x47x23", False),
(8, "35x47x23", True),
(9, "34x46x22", False),
(10, "34x46x22", True),
]


@pytest.fixture(scope="module")
def volume_session(tmp_path_factory):
"""Session with a 3D raster containing nulls (scope: module)"""
project = tmp_path_factory.mktemp("r3_retile") / "xy_test"
gs.create_project(project)
with (
gs.setup.init(project, env=os.environ.copy()) as session,
Tools(session=session) as tools,
):
tools.g_region(s=0, n=47, w=0, e=35, b=0, t=23, res=10, res3=1, flags="3")
tools.r3_mapcalc(expression="volume = col() + row() + depth()")
tools.r3_mapcalc(
expression="volume_null = if(row() == 1 || row() == 5, null(), volume)"
)
yield session


@pytest.mark.parametrize(("number", "tiles", "no_cache"), CASES)
def test_retile_matches_reference(volume_session, number, tiles, no_cache):
"""Retiled map and its info match the reference files"""
tools = Tools(session=volume_session)
tools.r3_retile(
input="volume_null",
output=f"test_retile_map_{number}",
tiledimension=tiles,
flags="c" if no_cache else "",
)
data = tools.r3_out_ascii(input=f"test_retile_map_{number}", precision=0).stdout
assert data == (DATA_DIR / f"test_retile_map_{number}.ref").read_text()
info = tools.r3_info(map=f"test_retile_map_{number}", flags="g").stdout.splitlines()
info = [line for line in info if line.split("=")[0] not in KEYS_NOT_IN_REF]
reference = (DATA_DIR / f"test_retile_map_{number}_info.ref").read_text()
assert info == reference.splitlines()
Loading