-
-
Notifications
You must be signed in to change notification settings - Fork 309
/
gis_lib_env_test.py
75 lines (60 loc) · 2.43 KB
/
gis_lib_env_test.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
"""Test of gis library environment management
@author Soeren Gebbert
"""
from grass.gunittest.case import TestCase
import grass.lib.gis as libgis
class GisLibraryTestEnv(TestCase):
@classmethod
def setUpClass(cls):
libgis.G_gisinit("GisLibraryTestEnv")
def test_gisrc(self):
# File access
libgis.G_setenv("TEST", "A");
value = libgis.G_getenv("TEST")
self.assertEqual(value, "A")
value = libgis.G_getenv2("TEST", libgis.G_VAR_GISRC)
self.assertEqual(value, "A")
# In memory management
libgis.G_setenv_nogisrc("TEST", "B");
value = libgis.G_getenv_nofatal("TEST")
self.assertEqual(value, "B")
value = libgis.G_getenv_nofatal2("TEST", libgis.G_VAR_GISRC)
self.assertEqual(value, "B")
# Force reading
libgis.G__read_gisrc_env()
value = libgis.G_getenv("TEST")
self.assertEqual(value, "A")
value = libgis.G_getenv2("TEST", libgis.G_VAR_GISRC)
self.assertEqual(value, "A")
def test_switch_env(self):
libgis.G_setenv_nogisrc("TEST", "SWITCH");
libgis.G_setenv_nogisrc2("TEST", "SWITCH2", libgis.G_VAR_MAPSET);
# Create alternative env
libgis.G_create_alt_env()
libgis.G_setenv_nogisrc("TEST", "TARGET");
libgis.G_setenv_nogisrc2("TEST", "TARGET2", libgis.G_VAR_MAPSET);
value = libgis.G_getenv("TEST")
self.assertEqual(value, "TARGET")
value = libgis.G_getenv2("TEST", libgis.G_VAR_MAPSET)
self.assertEqual(value, "TARGET2")
# Switch back to orig env
libgis.G_switch_env()
value = libgis.G_getenv("TEST")
self.assertEqual(value, "SWITCH")
value = libgis.G_getenv2("TEST", libgis.G_VAR_MAPSET)
self.assertEqual(value, "SWITCH2")
def test_mapset(self):
# Mapset VAR file
libgis.G_setenv2("TEST", "C", libgis.G_VAR_MAPSET);
value = libgis.G_getenv2("TEST", libgis.G_VAR_MAPSET)
self.assertEqual(value, "C")
libgis.G_setenv_nogisrc2("TEST", "D", libgis.G_VAR_MAPSET);
value = libgis.G_getenv_nofatal2("TEST", libgis.G_VAR_MAPSET)
self.assertEqual(value, "D")
# Force reading
libgis.G__read_mapset_env()
value = libgis.G_getenv2("TEST", libgis.G_VAR_MAPSET)
self.assertEqual(value, "C")
if __name__ == '__main__':
from grass.gunittest.main import test
test()