t.rast.mapcalc: migrate additional shell test to pytest#6967
t.rast.mapcalc: migrate additional shell test to pytest#6967sakirr05 wants to merge 14 commits intoOSGeo:mainfrom
Conversation
|
Hey @ninsbl, I followed up on your suggestion and migrated the t.rast.mapcalc shell test to pytest |
petrasovaa
left a comment
There was a problem hiding this comment.
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.
temporal/t.rast.mapcalc/tests/test_t_rast_mapcalc_basic_pytest.py
Outdated
Show resolved
Hide resolved
|
Hi @petrosavova, thanks for the detailed review and suggestions |
|
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) |
There was a problem hiding this comment.
Please check the actual number here (applies to other tests as well).
temporal/t.rast.mapcalc/testsuite/test_t_rast_mapcalc_operators.py
Outdated
Show resolved
Hide resolved
|
Thanks for the review @petrasovaa The switch to grass.gunittest was mainly because pytest was not available in the I’ll recheck the expected number_of_maps assertions and remove the incorrect |
Fix incorrect map count assertions, ensure proper STRDS cleanup, and align tests with actual t.rast.mapcalc behavior across CI environments.
Hi @sakirr05 , please not that tests in the 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
|
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. |
|
This is not going to work, pytests are expected to create their own session, see all the other fixtures. |
|
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 |
|
@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
left a comment
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Why not using tools also here? They also provide functios for stdout parsing, like e.g. `tools.t_info(...).json?
There was a problem hiding this comment.
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.
|
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. |
| reference = dict( | ||
| line.strip().split(sep, 1) | ||
| for line in reference_string.strip().split("\n") | ||
| if sep in line | ||
| ) |
There was a problem hiding this comment.
Hm, just represent the reference as dict instead of multiline string and you can avoid all this parsing.
There was a problem hiding this comment.
hey @petrasovaa I’ve addressed the requested changes
Just keep it local as you have it to not complicate this further, we may want to evaluate these later. |
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.