Skip to content

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

Merged
petrasovaa merged 20 commits into
OSGeo:mainfrom
sakirr05:migrate-additional-t-rast-mapcalc-test
May 12, 2026
Merged

petrasovaa merged 20 commits into
OSGeo:mainfrom
sakirr05:migrate-additional-t-rast-mapcalc-test

Conversation

@sakirr05

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

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

@petrasovaa petrasovaa left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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

@sakirr05

Copy link
Copy Markdown
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

ninsbl commented Jan 28, 2026

Copy link
Copy Markdown
Member

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....

- 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
Copy Markdown
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
Copy Markdown
Contributor

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

@ninsbl

ninsbl commented Jan 29, 2026

Copy link
Copy Markdown
Member

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
Copy Markdown
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

sakirr05 commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor Author

@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.

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)

@ninsbl ninsbl left a comment

Copy link
Copy Markdown
Member

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.

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

ninsbl commented Jan 31, 2026

Copy link
Copy Markdown
Member

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
Copy Markdown
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
@petrasovaa

Copy link
Copy Markdown
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
@sakirr05

Copy link
Copy Markdown
Contributor Author

Hey @petrasovaa and @ninsbl all the previous review feedback has been addressed: tests are now in the correct tests/ directory, using pytest. The _assert_tinfo_key_value helper is kept local as suggested. Would really appreciate a final review whenever you are free

ninsbl
ninsbl previously approved these changes Feb 27, 2026

@ninsbl ninsbl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me. A second opinion would be very much appreciated.... So I leave it for some else to merge...

@sakirr05

Copy link
Copy Markdown
Contributor Author

Looks good to me. A second opinion would be very much appreciated.... So I leave it for some else to merge...

@echoix or @wenzeslaus please review it whenever you are free,
thanks.

@echoix

echoix commented Feb 28, 2026

Copy link
Copy Markdown
Member

@petrasovaa are all your requested changes addressed?

@ninsbl

ninsbl commented Apr 15, 2026

Copy link
Copy Markdown
Member

I am working on a t.rast.mapcalc PR. Would be great to have this merged first, @petrasovaa do you think this is good to go?

@echoix
echoix requested review from petrasovaa and removed request for petrasovaa April 27, 2026 14:58
Collapsed the duplicated fixtures and helper into a single mapcalc_session + assert_tinfo in conftest.py, replaced
  the destructive g.remove in the failure test with a rename/restore via try/finally, switched assertions from manual
  parse_key_val to .keyval (with int values), and trimmed cosmetic noise (boilerplate @author, leading/trailing-space
  expressions, misleading docstring); also reduced nprocs from 5 to 3.
@sakirr05
sakirr05 requested a review from ninsbl May 5, 2026 18:44
@petrasovaa
petrasovaa enabled auto-merge (squash) May 12, 2026 14:56
@petrasovaa
petrasovaa merged commit 1ddc99b into OSGeo:main May 12, 2026
29 of 31 checks passed
@github-actions github-actions Bot added this to the 8.6.0 milestone May 12, 2026
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Jul 7, 2026
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.

4 participants