Last active
August 8, 2019 16:33
-
-
Save wenzeslaus/87e588b036e2f0f8c3c0c4e3311a2253 to your computer and use it in GitHub Desktop.
This file contains 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
# Test GRASS GIS installation | |
# It assumes GRASS GIS is available through command `grass` | |
# and existence of directory /tmp with read and write access. | |
# It does not test anything from GUI and it does not test using | |
# GRASS GIS Python functionality directly from Python | |
# (but it tests that Python parts in GRASS GIS work). | |
# Author: Vaclav Petras | |
import os | |
import subprocess | |
# test if there is the command and if it is not broken | |
path = subprocess.check_output(["grass", "--config", "path"]) | |
assert path.strip(), "GRASS GIS can't find its files" | |
# access to directories | |
# (also needed for the steps below; rough equivalent to --tmp-location in 7.6) | |
# test we can create locations and mapsets inside the database directory | |
database_path = "/tmp" | |
mapset_path = os.path.join(database_path, "testloc", "test1") | |
subprocess.check_call(["grass", "-c", "EPSG:3358", os.path.join(database_path, "testloc"), "-e"]) | |
subprocess.check_call(["grass", "-c", mapset_path, "-e"]) | |
# basic functions | |
# also sets the environment to make computations non-trivial (but still fast) | |
# test we can run a GRASS GIS module | |
subprocess.check_output(["grass", mapset_path, "--exec", | |
"g.region", "rows=10", "cols=20"]) | |
# test we can get output from a GRASS GIS module | |
text = subprocess.check_output(["grass", mapset_path, "--exec", | |
"g.region", "-p"]) | |
assert text.strip(), "No text output from a GRASS GIS module" | |
# test a computational modules | |
# --overwrite allows to run it repetetively during testing of this line | |
subprocess.check_call(["grass", mapset_path, "--exec", | |
"r.surf.fractal", "output=fractal_surface", "--overwrite"]) | |
subprocess.check_call(["grass", mapset_path, "--exec", | |
"r.slope.aspect", "elevation=fractal_surface", "slope=slope", "--overwrite"]) | |
# test vector module (writes vector map) | |
subprocess.check_call(["grass", mapset_path, "--exec", | |
"r.to.vect", "input=fractal_surface", "output=points", "type=point", "--overwrite"]) | |
# test Python module | |
# creates a file in the current directory | |
subprocess.check_call(["grass", mapset_path, "--exec", | |
"v.pack", "input=points", "output=points.pack", "--overwrite"]) | |
assert os.path.isfile("points.pack") | |
# GRASS GIS does not ship with its testsuite, | |
# but it would be possible to run some Python doctests if more thorough test is needed | |
# (without downloading the source code). | |
# requires internet access# test we can install Python extensions | |
subprocess.check_call(["grass", mapset_path, "--exec", | |
"g.extension", "r.forestfrag"]) | |
# test we can install C extensions | |
subprocess.check_call(["grass", mapset_path, "--exec", | |
"g.extension", "r.accumulate"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment