Skip to content

Commit 93d2bbd

Browse files
committed
r.category: update test to use r.info for title verification
Replace direct cats-file reading with r.info -e (JSON format) to verify the preserved title. The cats file is an internal format; using the public API is more robust and is consistent with how other tests and tools read raster metadata.
1 parent 8b390ef commit 93d2bbd

2 files changed

Lines changed: 6 additions & 11 deletions

File tree

raster/r.category/tests/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""Fixture for r.category test"""
22

33
import os
4+
45
import pytest
6+
57
import grass.script as gs
68

79

raster/r.category/tests/r_category_test.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ def test_r_category_with_json_output_color(simple_dataset):
341341

342342
def test_r_category_rules_preserves_title(simple_dataset):
343343
"""Test that rules= does not erase a title previously set with r.support."""
344-
import os
345344

346345
session = simple_dataset
347346
title = "USGS National Land Cover"
@@ -356,17 +355,11 @@ def test_r_category_rules_preserves_title(simple_dataset):
356355
env=session.env,
357356
)
358357

359-
# Read the title directly from the cats file (line 1, after the category count).
360-
gisenv = gs.gisenv(env=session.env)
361-
cats_path = os.path.join(
362-
gisenv["GISDBASE"], gisenv["LOCATION_NAME"], gisenv["MAPSET"], "cats", "test"
358+
info = json.loads(
359+
gs.read_command("r.info", map="test", flags="e", format="json", env=session.env)
363360
)
364-
with open(cats_path) as f:
365-
f.readline() # skip "# N categories" line
366-
actual_title = f.readline().strip()
367-
368-
assert actual_title == title, (
369-
f"Expected title '{title}', but r.category rules= overwrote it with '{actual_title}'"
361+
assert info["title"] == title, (
362+
f"Expected title '{title}', but r.category rules= overwrote it with '{info['title']}'"
370363
)
371364

372365

0 commit comments

Comments
 (0)