Skip to content

t.rast.mapcalc: migrate additional shell test to pytest#6967

Open
sakirr05 wants to merge 14 commits intoOSGeo:mainfrom
sakirr05:migrate-additional-t-rast-mapcalc-test
Open

t.rast.mapcalc: migrate additional shell test to pytest#6967
sakirr05 wants to merge 14 commits intoOSGeo:mainfrom
sakirr05:migrate-additional-t-rast-mapcalc-test

Conversation

@sakirr05
Copy link
Contributor

Migrates one additional shell-based t.rast.mapcalc test to pytest and removes
the corresponding shell test block. This is a small follow-up to #6948.

@github-actions github-actions bot added temporal Related to temporal data processing Python Related code is in Python module tests Related to Test Suite labels Jan 25, 2026
@sakirr05
Copy link
Contributor Author

Hey @ninsbl, I followed up on your suggestion and migrated the t.rast.mapcalc shell test to pytest

Copy link
Contributor

@petrasovaa petrasovaa left a comment

Choose a reason for hiding this comment

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

Thanks! Could you please migrate the entire test, it shouldn't be that much more work. It would be nice to add at least little bit more testing of the results beyond a smoke test, e.g. that the number of maps is correct.

Also the "_pytest.py" is unnecessary, so please rename this test file and the other you added already.

@sakirr05
Copy link
Contributor Author

Hi @petrosavova, thanks for the detailed review and suggestions
I’ve now migrated the remaining shell tests to pytest, added stronger assertions (map count, name, temporal type), fixed overwrite handling, and cleaned up the file naming as you suggested.

@sakirr05 sakirr05 requested a review from petrasovaa January 27, 2026 18:14
@petrasovaa
Copy link
Contributor

Any reason you migrated it to unittest? It's not necessarily wrong, but pytest is preferred.

strds_info = gs.parse_key_val(info.outputs.stdout, sep="=")
self.assertEqual(strds_info["name"], "precip_abs4")
# With null() multiplication, maps may be empty but STRDS should exist
self.assertIn("number_of_maps", strds_info)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check the actual number here (applies to other tests as well).

@sakirr05
Copy link
Contributor Author

Thanks for the review @petrasovaa

The switch to grass.gunittest was mainly because pytest was not available in the
temporal CI jobs for this PR, which caused the original failures. Happy to follow
the preferred direction once pytest is consistently available there.

I’ll recheck the expected number_of_maps assertions and remove the incorrect
comment unnecessary flag in a follow-up commit.

Fix incorrect map count assertions, ensure proper STRDS cleanup,
and align tests with actual t.rast.mapcalc behavior across CI
environments.
@ninsbl
Copy link
Member

ninsbl commented Jan 28, 2026

The switch to grass.gunittest was mainly because pytest was not available in the temporal CI jobs for this PR, which caused the original failures. Happy to follow the preferred direction once pytest is consistently available there.

Hi @sakirr05 , please not that tests in the testsuite directory are picked up as gunit-tests, while tests in a testsdirectory would be picked up by pytest.
So, pytest is fine and available also for temporal tests, just put them in a ./temporal/t.rast.mapcalc/tests folder instead of ./temporal/t.rast.mapcalc/testsuite, as you did with the test you added ~two days ago...

With regards to efficiency of tests, it might be an advantage to have cases for t.rast.mapcalc collected in test so fixures can be shared across cases, at least until fixures get more centraly organized....

sakirr added 3 commits January 29, 2026 09:20
- Migrates remaining t.rast.mapcalc shell tests to pytest
- Stabilizes fixtures for execution in an existing GRASS session
- Aligns failure assertions with original shell test behavior
- Makes teardown idempotent to avoid failures when data is already removed
@sakirr05
Copy link
Contributor Author

Hi @petrosavova, @ninsbl

I’ve addressed the review comments and squashed the related changes into a single commit for clarity.

The tests are now fully migrated to pytest, fixtures are stabilized for execution in an existing GRASS session, failure assertions match the original shell tests, and teardown is idempotent to avoid failures when data is already removed.

All tests pass locally; CI is running.

@petrasovaa
Copy link
Contributor

This is not going to work, pytests are expected to create their own session, see all the other fixtures.

@ninsbl
Copy link
Member

ninsbl commented Jan 29, 2026

I see you use grass.script read_command/run_command family of functions. While that is not wrong, the Tools API would be preferred...

@petrasovaa
Copy link
Contributor

I see you use grass.script read_command/run_command family of functions. While that is not wrong, the Tools API would be preferred...

https://grass.osgeo.org/grass-devel/manuals/python_intro.html#running-tools

@sakirr05
Copy link
Contributor Author

sakirr05 commented Jan 29, 2026

@petrasovaa and @ninsbl, thanks a lot for taking the time to explain this.

I realize now that I misunderstood how pytest sessions are expected to work in GRASS. I’m still getting familiar with the project’s testing patterns, I appreciate you pointing this out. Sorry about the confusion on my side.

I’ll rework the tests to follow the existing fixture-based session setup and switch to the preferred Tools API where appropriate. I’ll push an updated version once that’s done.

Thanks again for the patience and guidance.

sakirr added 3 commits January 29, 2026 23:15
Minimal fix following temporal/t.rast.list/tests/conftest.py pattern:
- Fixtures now create temporary GRASS project via gs.create_project()
- Session initialized via gs.setup.init() context manager
- All commands use session.env parameter
- Test files unchanged (still use gs.run_command)
- No manual cleanup needed (temp directory auto-deleted)
Copy link
Member

@ninsbl ninsbl left a comment

Choose a reason for hiding this comment

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

This is going into the right direction. Please use the Tools API consistently throughout the tests.

def test_basic_addition(mapcalc_session_basic):
"""Test basic addition of two STRDS with -n flag (register null maps)."""
env = mapcalc_session_basic.env
gs.run_command(
Copy link
Member

Choose a reason for hiding this comment

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

Why not using tools also here? They also provide functios for stdout parsing, like e.g. `tools.t_info(...).json?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey @ninsbl Thanks for pointing this out. I’ve now switched the remaining test code to use the Tools API consistently — the earlier version was mainly to confirm CI stability.Please let me know if anything else should be adjusted.

@sakirr05 sakirr05 requested a review from ninsbl January 31, 2026 13:31
@ninsbl
Copy link
Member

ninsbl commented Jan 31, 2026

Thanks, @sakirr05 ! Much better. I see you define a copy of _assert_tinfo_key_value in each test. Not sure where to place that function... in #6995 such functions were added to python/grass/script/pytest_utils.py...

@sakirr05
Copy link
Contributor Author

hey @ninsbl I added the helper locally to keep the migration minimal, but I’m happy to move it to a shared pytest utility (e.g. grass.script.pytest_utils) and import it in the tests if that’s preferred.

Please let me know if you want me to do that in this PR or as a follow-up.

@sakirr05 sakirr05 requested a review from petrasovaa February 1, 2026 17:36
Comment on lines 19 to 23
reference = dict(
line.strip().split(sep, 1)
for line in reference_string.strip().split("\n")
if sep in line
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, just represent the reference as dict instead of multiline string and you can avoid all this parsing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey @petrasovaa I’ve addressed the requested changes

@petrasovaa
Copy link
Contributor

hey @ninsbl I added the helper locally to keep the migration minimal, but I’m happy to move it to a shared pytest utility (e.g. grass.script.pytest_utils) and import it in the tests if that’s preferred.

Please let me know if you want me to do that in this PR or as a follow-up.

Just keep it local as you have it to not complicate this further, we may want to evaluate these later.

@sakirr05 sakirr05 requested a review from petrasovaa February 2, 2026 10:26
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 temporal Related to temporal data processing tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants