Skip to content

g.gisenv: Add pytest test suite - #7803

Merged
echoix merged 2 commits into
OSGeo:mainfrom
jalpatel11:add-g-gisenv-tests
Aug 8, 2026
Merged

echoix merged 2 commits into
OSGeo:mainfrom
jalpatel11:add-g-gisenv-tests

Conversation

@jalpatel11

Copy link
Copy Markdown
Contributor

Summary

g.gisenv had no test coverage. This adds a pytest suite (tests/g_gisenv_test.py, tests/conftest.py) covering:

  • Reading a variable that's always set (MAPSET)
  • Case-insensitive variable names
  • Reading multiple variables at once with a custom separator
  • Reading an undefined variable fails
  • Set/get round-trip
  • Setting an empty value unsets the variable, same as unset=
  • unset= removes a variable
  • Unsetting a protected variable (GISDBASE, LOCATION_NAME, MAPSET) warns but is a no-op instead of failing
  • Plain (-n) vs. shell-quoted (-s) print-all output
  • store=mapset and the default gisrc store are separate namespaces

11 tests total. general/ has no shared conftest.py yet, so this adds a local one with session/tools fixtures, following the same pattern as raster/conftest.py's session_tools fixture.

Testing

Ran the suite against a real main-branch GRASS session (osgeo/grass-gis:main-alpine Docker image) — all 11 tests pass. Caught and fixed a bug in my own test along the way: an early version of the separator test split the output on /, which broke because GISDBASE paths contain / themselves. Checked formatting/lint with the pinned ruff version (v0.15.17).

AI disclosure

I used AI assistance (Claude) to draft and verify these tests, then reviewed and tested them myself as described above.

g.gisenv had no test coverage. Add tests/g_gisenv_test.py covering
get/set/unset, case-insensitive variable names, the empty-value-unsets
shortcut, protected variables (GISDBASE, LOCATION_NAME, MAPSET) being
a no-op instead of failing, plain vs. shell-quoted print-all output,
and the separate gisrc vs. store=mapset namespaces. Adds a local
conftest.py with session/tools fixtures, following the pattern used
in raster/conftest.py.

AI assistance (Claude) was used to draft and verify these tests.
@github-actions github-actions Bot added Python Related code is in Python module general tests Related to Test Suite labels Aug 5, 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 in general good to me. One comment regarding the test of where the variable is stored. That may also be relevant to check storage for the gisrc case...

Comment thread general/g.gisenv/tests/g_gisenv_test.py Resolved
Address review feedback on the pytest suite: the store=mapset test
only checked round-trip behavior through get=, not that the variable
was actually written to disk. Add two tests that check the files
directly with pathlib:

- test_set_stores_variable_in_gisrc_file: the default store=gisrc
  writes into the session's gisrc file (session.env["GISRC"]).
- test_set_store_mapset_stores_variable_in_var_file: store=mapset
  writes into <gisdbase>/<location>/<mapset>/VAR.

Keeps the existing test_store_mapset_is_separate_from_gisrc, which
checks the behavioral contract via get= and is complementary to the
new on-disk checks.
@jalpatel11

Copy link
Copy Markdown
Contributor Author

@ninsbl Good catch; pushed a fix. Added two tests that check the files directly with pathlib instead of only going through get=: one confirms set= writes into the session's gisrc file, the other confirms store=mapset writes into <gisdbase>/<location>/<mapset>/VAR. Kept the original round-trip test too since it's still a useful, complementary check. All 13 tests pass.

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

@jalpatel11

Copy link
Copy Markdown
Contributor Author

@ninsbl ready for merge.

@jalpatel11

Copy link
Copy Markdown
Contributor Author

@echoix can you check?

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

I have nothing to say after a quick read

@echoix
echoix merged commit ba1d7b7 into OSGeo:main Aug 8, 2026
26 checks passed
@github-actions github-actions Bot added this to the 8.6.0 milestone Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

general module Python Related code is in Python tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants