-
-
Notifications
You must be signed in to change notification settings - Fork 399
pygrass: add get_json_dict function #2937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
46dad7c
add get_json_dict
ninsbl 7015985
add test for get_json_dict
ninsbl d8933b6
handle export
ninsbl b62eb04
add more tests
ninsbl 26d2684
fix typo
ninsbl 561353c
fix some tests
ninsbl 17ff69f
fix tests
ninsbl 949e84d
fix tests
ninsbl e4af988
use f-strings
ninsbl 0ee415a
Merge branch 'main' into get_json
ninsbl 63bf42e
Update python/grass/pygrass/modules/interface/module.py
ninsbl 27f49fb
Update python/grass/pygrass/modules/interface/module.py
ninsbl fe3de57
flake8
ninsbl 4eb76a0
handle STDOUT
ninsbl 9239679
add pytest
ninsbl 22527b0
pylint
ninsbl 47c3b2f
remove TestModulesJsonDictExport TestCase
ninsbl 2046e3e
Merge branch 'main' into get_json
echoix 9ab7c64
Merge branch 'main' into get_json
echoix 0dae970
Merge branch 'main' into get_json
echoix e4888e6
Fix extra space
echoix 851b28f
Fix ruff rule EM102
echoix d0feda9
ruff and better docstring
ninsbl baec08c
Merge branch 'OSGeo:main' into get_json
ninsbl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
python/grass/pygrass/modules/interface/testsuite/pygrass_modules_interface_json_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| ############################################################################ | ||
| # | ||
| # MODULE: Test of JSON export from pygrass.Module for usage in actinia | ||
| # AUTHOR(S): Stefan Blumentrath | ||
| # PURPOSE: Test of JSON export from pygrass.Module for usage in actinia | ||
| # COPYRIGHT: (C) 2024 by Stefan Blumentrath and the GRASS Development Team | ||
| # | ||
| # This program is free software under the GNU General Public | ||
| # License (>=v2). Read the file COPYING that comes with GRASS | ||
| # for details. | ||
| # | ||
| ############################################################################# | ||
|
|
||
| """Test of JSON export from pygrass.Module for usage in actinia """ | ||
|
|
||
echoix marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| from grass.pygrass.modules.interface import Module | ||
|
|
||
|
|
||
| def test_rinfo_simple(): | ||
| """Test if a Module can be exported to json dict""" | ||
|
|
||
| mod_json_dict = Module("r.info", map="elevation", run_=False).get_json_dict() | ||
|
|
||
| assert isinstance(mod_json_dict, dict) | ||
| assert set(mod_json_dict.keys()) == {"module", "id", "inputs"} | ||
| assert mod_json_dict["module"] == "r.info" | ||
| assert mod_json_dict["id"].startswith("r_info_") | ||
| assert "flags" not in mod_json_dict | ||
| assert set(mod_json_dict["inputs"][0].keys()) == {"param", "value"} | ||
|
|
||
|
|
||
| def test_rinfo_ov(): | ||
| """Test if a Module can be exported to json dict with quiet and overwrite flags""" | ||
|
|
||
| mod_json_dict = Module( | ||
| "r.info", quiet=True, map="elevation", run_=False | ||
| ).get_json_dict() | ||
|
|
||
| assert isinstance(mod_json_dict, dict) | ||
| assert set(mod_json_dict.keys()) == {"module", "id", "inputs", "quiet"} | ||
| assert mod_json_dict["module"] == "r.info" | ||
| assert mod_json_dict["id"].startswith("r_info_") | ||
| assert "flags" not in mod_json_dict | ||
| assert mod_json_dict["quiet"] is True | ||
| assert isinstance(mod_json_dict["inputs"], list) | ||
| assert set(mod_json_dict["inputs"][0].keys()) == {"param", "value"} | ||
|
|
||
|
|
||
| def test_rinfo_ov_export(): | ||
| """Test if a Module can be exported to json dict with overwrite | ||
| and verbose flags and results exported to CSV""" | ||
|
|
||
| mod_json_dict = Module( | ||
| "r.info", | ||
| verbose=True, | ||
| map="elevation", | ||
| flags="g", | ||
| run_=False, | ||
| ).get_json_dict(stdout_export="list") | ||
|
|
||
| assert isinstance(mod_json_dict, dict) | ||
| assert set(mod_json_dict.keys()) == { | ||
| "module", | ||
| "id", | ||
| "flags", | ||
| "inputs", | ||
| "verbose", | ||
| "stdout", | ||
| } | ||
| assert mod_json_dict["module"] == "r.info" | ||
| assert mod_json_dict["id"].startswith("r_info_") | ||
| assert mod_json_dict["flags"] == "g" | ||
| assert mod_json_dict["verbose"] is True | ||
| assert isinstance(mod_json_dict["inputs"], list) | ||
| assert set(mod_json_dict["inputs"][0].keys()) == {"param", "value"} | ||
| assert mod_json_dict["stdout"] == { | ||
| "id": "stdout", | ||
| "format": "list", | ||
| "delimiter": "|", | ||
| } | ||
|
|
||
|
|
||
| def test_rslopeaspect_ov_export(): | ||
| """Test if a Module can be exported to json dict with overwrite | ||
| and verbose flags and results exported to CSV""" | ||
|
|
||
| mod_json_dict = Module( | ||
| "r.slope.aspect", | ||
| elevation="elevation", | ||
| slope="slope", | ||
| aspect="aspect", | ||
| overwrite=True, | ||
| verbose=True, | ||
| run_=False, | ||
| ).get_json_dict(export="GTiff") | ||
|
|
||
| assert isinstance(mod_json_dict, dict) | ||
| assert set(mod_json_dict.keys()) == { | ||
| "module", | ||
| "id", | ||
| "inputs", | ||
| "outputs", | ||
| "overwrite", | ||
| "verbose", | ||
| } | ||
| assert mod_json_dict["module"] == "r.slope.aspect" | ||
| assert mod_json_dict["id"].startswith("r_slope_aspect_") | ||
| assert mod_json_dict["overwrite"] is True | ||
| assert mod_json_dict["verbose"] is True | ||
| assert isinstance(mod_json_dict["inputs"], list) | ||
| assert isinstance(mod_json_dict["outputs"], list) | ||
| assert set(mod_json_dict["outputs"][0].keys()) == {"param", "value", "export"} | ||
| assert mod_json_dict["outputs"][0]["export"] == { | ||
| "format": "GTiff", | ||
| "type": "raster", | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.