From f9be593a15cb75e86ffb68e3cadcb3139f01c2ff Mon Sep 17 00:00:00 2001 From: saket0187 Date: Tue, 2 Jun 2026 19:40:41 +0530 Subject: [PATCH 1/2] Add tests to t.list --- temporal/t.list/tests/conftest.py | 57 ++++++++++++++++++++++++++++ temporal/t.list/tests/test_t_list.py | 51 +++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 temporal/t.list/tests/conftest.py create mode 100644 temporal/t.list/tests/test_t_list.py diff --git a/temporal/t.list/tests/conftest.py b/temporal/t.list/tests/conftest.py new file mode 100644 index 00000000000..c4829467271 --- /dev/null +++ b/temporal/t.list/tests/conftest.py @@ -0,0 +1,57 @@ +""" +Configuration and fixtures for t.list pytest suite. +""" + +import os +from types import SimpleNamespace + +import pytest + +import grass.script as gs +from grass.tools import Tools + + +@pytest.fixture(scope="module") +def space_time_dataset(tmp_path_factory): + """Start an isolated session and create a raster time series. + + Returns an object with attributes about the dataset. + """ + tmp_path = tmp_path_factory.mktemp("raster_time_series") + project = tmp_path / "test_project" + gs.create_project(project) + + with gs.setup.init(project, env=os.environ.copy()) as session: + tools = Tools(session=session) + + tools.g_region(s=0, n=80, w=0, e=120, res=10) + + names = [f"temp_{i}" for i in range(1, 4)] + for i, name in enumerate(names, start=1): + tools.r_mapcalc(expression=f"{name} = {i}", overwrite=True) + + dataset_name = "temperature_dataset" + + tools.t_create( + type="strds", + temporaltype="absolute", + output=dataset_name, + title="Temperature", + description="Random series generated for tests", + ) + + dataset_file = tmp_path / "names.txt" + dataset_file.write_text("\n".join(names)) + tools.t_register( + type="raster", + input=dataset_name, + file=dataset_file, + start="2026-01-01", + increment="1 month", + ) + + yield SimpleNamespace( + session=session, + name=dataset_name, + map_names=names, + ) diff --git a/temporal/t.list/tests/test_t_list.py b/temporal/t.list/tests/test_t_list.py new file mode 100644 index 00000000000..a8ee8353166 --- /dev/null +++ b/temporal/t.list/tests/test_t_list.py @@ -0,0 +1,51 @@ +"""Test t.list functionality""" + +import pytest + +from grass.tools import Tools + + +@pytest.mark.needs_solo_run +def test_t_list_defaults(space_time_dataset): + """Check that the module correctly lists datasets (strds) and maps (raster).""" + tools = Tools(session=space_time_dataset.session) + + strds_result = tools.t_list(type="strds", columns="name") + assert strds_result.returncode == 0 + + strds_lines = [line.strip() for line in strds_result.stdout.strip().splitlines()] + assert space_time_dataset.name in strds_lines + + # Test Map Listing (raster) + raster_result = tools.t_list(type="raster", columns="name") + + raster_lines = [line.strip() for line in raster_result.stdout.strip().splitlines()] + for map_name in space_time_dataset.map_names: + assert map_name in raster_lines + + +@pytest.mark.needs_solo_run +def test_t_list_where_filter(space_time_dataset): + """Check that where clause filter the output exactly.""" + tools = Tools(session=space_time_dataset.session) + + match = tools.t_list(type="strds", columns="name", where="name LIKE 'temp_%'") + match_lines = [line.strip() for line in match.stdout.strip().splitlines()] + assert len(match_lines) == 1 + assert match_lines[0] == space_time_dataset.name + + empty = tools.t_list(type="strds", columns="name", where="name LIKE 'land_%'") + assert empty is None + + +@pytest.mark.needs_solo_run +def test_t_list_order(space_time_dataset): + """Check that ordering the output actually sorts the data correctly.""" + tools = Tools(session=space_time_dataset.session) + + result_asc = tools.t_list(type="raster", columns="name", order="start_time") + assert result_asc is not None + + lines_asc = [line.strip() for line in result_asc.stdout.strip().splitlines()] + + assert lines_asc == space_time_dataset.map_names From ec04f22dd777291dd0ee528b84ce82d3ee971237 Mon Sep 17 00:00:00 2001 From: saket0187 Date: Wed, 3 Jun 2026 12:19:04 +0530 Subject: [PATCH 2/2] Remove marker --- temporal/t.list/tests/test_t_list.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/temporal/t.list/tests/test_t_list.py b/temporal/t.list/tests/test_t_list.py index a8ee8353166..887aad2889b 100644 --- a/temporal/t.list/tests/test_t_list.py +++ b/temporal/t.list/tests/test_t_list.py @@ -1,11 +1,8 @@ """Test t.list functionality""" -import pytest - from grass.tools import Tools -@pytest.mark.needs_solo_run def test_t_list_defaults(space_time_dataset): """Check that the module correctly lists datasets (strds) and maps (raster).""" tools = Tools(session=space_time_dataset.session) @@ -24,7 +21,6 @@ def test_t_list_defaults(space_time_dataset): assert map_name in raster_lines -@pytest.mark.needs_solo_run def test_t_list_where_filter(space_time_dataset): """Check that where clause filter the output exactly.""" tools = Tools(session=space_time_dataset.session) @@ -38,7 +34,6 @@ def test_t_list_where_filter(space_time_dataset): assert empty is None -@pytest.mark.needs_solo_run def test_t_list_order(space_time_dataset): """Check that ordering the output actually sorts the data correctly.""" tools = Tools(session=space_time_dataset.session)