-
-
Notifications
You must be signed in to change notification settings - Fork 291
/
test_parser_json.py
113 lines (95 loc) · 3.61 KB
/
test_parser_json.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"""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.
@author Soeren Gebbert
"""
import subprocess
from grass.gunittest.case import TestCase
from grass.script import decode
import json
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 = [
{
"param": "elevation",
"value": "elevation+https://storage.googleapis.com/graas-geodata/elev_ned_30m.tif",
},
{"param": "format", "value": "degrees"},
{"param": "precision", "value": "FCELL"},
{"param": "zscale", "value": "1.0"},
{"param": "min_slope", "value": "0.0"},
{"param": "nprocs", "value": "1"},
{"param": "memory", "value": "300"},
]
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 = json.loads(decode(stdout))
self.assertEqual(json_code["module"], "r.slope.aspect")
self.assertEqual(len(json_code["inputs"]), 7)
self.assertEqual(json_code["inputs"], inputs)
self.assertEqual(json_code["outputs"], outputs)
def test_v_out_ascii(self):
args = [
"v.out.ascii",
"input=hospitals@PERMANENT",
"output=myfile+TXT",
"--json",
]
inputs = [
{"param": "input", "value": "hospitals@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 = json.loads(decode(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@PERMANENT", "-c", "--json"]
inputs = [
{"param": "map", "value": "hospitals@PERMANENT"},
{"param": "layer", "value": "1"},
]
stdout, stderr = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()
print(stdout)
json_code = json.loads(decode(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()