[GRASS-SVN] r73527 - in grass/trunk/lib/gis: . testsuite

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Oct 13 11:14:20 PDT 2018


Author: huhabla
Date: 2018-10-13 11:14:20 -0700 (Sat, 13 Oct 2018)
New Revision: 73527

Added:
   grass/trunk/lib/gis/testsuite/test_parser_json.py
Modified:
   grass/trunk/lib/gis/parser_json.c
Log:
Added tests to the GRASS GIS JSON parser


Modified: grass/trunk/lib/gis/parser_json.c
===================================================================
--- grass/trunk/lib/gis/parser_json.c	2018-10-13 15:47:09 UTC (rev 73526)
+++ grass/trunk/lib/gis/parser_json.c	2018-10-13 18:14:20 UTC (rev 73527)
@@ -200,7 +200,7 @@
 
     file_name = G_tempfile();
 
-    fprintf(stderr, "Filename: %s\n", file_name);
+    /* fprintf(stderr, "Filename: %s\n", file_name); */
     fp = fopen(file_name, "w+");
     if (fp == NULL)
     {
@@ -256,9 +256,6 @@
     }
 
     /* Print the input options
-
-      TODO: Check for URLs in the answer to create import options
-      TODO: Check for mapset names in the answer and remove the current mapset name from the string
     */
     if (st->n_opts && num_inputs > 0) {
         struct Option *opt;
@@ -289,9 +286,6 @@
     }
 
     /* Print the output options
-
-      TODO: Check export options in the answer to create export options
-      TODO: Check for mapset names in the answer and remove the mapset name from the string
     */
     if (st->n_opts && num_outputs > 0) {
         struct Option *opt;

Added: grass/trunk/lib/gis/testsuite/test_parser_json.py
===================================================================
--- grass/trunk/lib/gis/testsuite/test_parser_json.py	                        (rev 0)
+++ grass/trunk/lib/gis/testsuite/test_parser_json.py	2018-10-13 18:14:20 UTC (rev 73527)
@@ -0,0 +1,98 @@
+"""Test the JSON extension of the GRASS parser
+
+(C) 2014 by 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.
+
+ at author Soeren Gebbert
+"""
+
+import subprocess
+from grass.gunittest.case import TestCase
+import simplejson
+
+
+class TestParserJson(TestCase):
+    def test_r_slope_aspect_json(self):
+        args = ["r.slope.aspect",
+                "elevation=elevation+https://storage.googleapis.com/graas-geodata/elev_ned_30m.tif",
+                "slope=slope+GTiff",
+                "aspect=aspect+GTiff", "--json"]
+
+        inputs = [
+            {"import_descr": {"source": "https://storage.googleapis.com/graas-geodata/elev_ned_30m.tif",
+                              "type": "raster"},
+             "param": "elevation", "value": "elevation"},
+            {"param": "format", "value": "degrees"},
+            {"param": "precision", "value": "FCELL"},
+            {"param": "zscale", "value": "1.0"},
+            {"param": "min_slope", "value": "0.0"}
+        ]
+
+        outputs = [
+            {"export": {"format": "GTiff", "type": "raster"},
+             "param": "slope", "value": "slope"},
+            {"export": {"format": "GTiff", "type": "raster"},
+             "param": "aspect", "value": "aspect"}
+        ]
+
+        stdout, stderr = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()
+        print(stdout)
+        json_code = simplejson.loads(stdout)
+        self.assertEqual(json_code["module"], "r.slope.aspect")
+        self.assertEqual(len(json_code["inputs"]), 5)
+        self.assertEqual(json_code["inputs"], inputs)
+        self.assertEqual(json_code["outputs"], outputs)
+
+    def test_v_out_ascii(self):
+        args = ["v.out.ascii",
+                "input=hospitals at PERMANENT",
+                "output=myfile+TXT",
+                "--json"]
+
+        inputs = [
+            {"param": "input", "value": "hospitals at PERMANENT"},
+            {"param": "layer", "value": "1"},
+            {"param": "type", "value": "point,line,boundary,centroid,area,face,kernel"},
+            {"param": "format", "value": "point"},
+            {"param": "separator", "value": "pipe"},
+            {"param": "precision", "value": "8"}
+        ]
+
+        outputs = [
+            {"export": {"format": "TXT", "type": "file"},
+             "param": "output", "value": "$file::myfile"}
+        ]
+
+        stdout, stderr = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()
+        print(stdout)
+        json_code = simplejson.loads(stdout)
+        self.assertEqual(json_code["module"], "v.out.ascii")
+        self.assertEqual(len(json_code["inputs"]), 6)
+        self.assertEqual(json_code["inputs"], inputs)
+        self.assertEqual(json_code["outputs"], outputs)
+
+    def test_v_info(self):
+        args = ["v.info",
+                "map=hospitals at PERMANENT",
+                "-c",
+                "--json"]
+
+        inputs = [
+         {"param": "map", "value": "hospitals at PERMANENT"},
+         {"param": "layer", "value": "1"}
+       ]
+
+        stdout, stderr = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()
+        print(stdout)
+        json_code = simplejson.loads(stdout)
+        self.assertEqual(json_code["module"], "v.info")
+        self.assertEqual(len(json_code["inputs"]), 2)
+        self.assertEqual(json_code["inputs"], inputs)
+
+
+if __name__ == '__main__':
+    from grass.gunittest.main import test
+
+    test()



More information about the grass-commit mailing list