Debian Codegraph @

temporal/t.unregister/testsuite/test_unregister.py

raw
1 """Test t.unregister
2
3 (C) 2014 by the GRASS Development Team
4 This program is free software under the GNU General Public
5 License (>=v2). Read the file COPYING that comes with GRASS
6 for details.
7
8 :authors: Soeren Gebbert
9 """
10
11 import os
12
13 import grass.temporal as tgis
14 from grass.gunittest.case import TestCase
15 from grass.gunittest.gmodules import SimpleModule
16
17
18 class TestUnregister(TestCase):
19 @classmethod
20 def setUpClass(cls):
21 """Initiate the temporal GIS and set the region"""
22 tgis.init()
23 cls.use_temp_region()
24 cls.runModule("g.gisenv", set="TGIS_USE_CURRENT_MAPSET=1")
25 cls.runModule("g.region", s=0, n=80, w=0, e=120, b=0, t=50, res=10, res3=10)
26
27 @classmethod
28 def tearDownClass(cls):
29 """Remove the temporary region"""
30 cls.del_temp_region()
31
32 def setUp(self):
33 """Create input data"""
34 self.runModule("r.mapcalc", expression="a1 = 100", overwrite=True)
35 self.runModule("r.mapcalc", expression="a2 = 200", overwrite=True)
36 self.runModule("r.mapcalc", expression="a3 = 300", overwrite=True)
37 self.runModule("r.mapcalc", expression="a4 = 400", overwrite=True)
38 self.runModule("r.mapcalc", expression="a5 = 500", overwrite=True)
39 self.runModule("r.mapcalc", expression="a6 = 600", overwrite=True)
40
41 self.runModule(
42 "t.create",
43 type="strds",
44 temporaltype="absolute",
45 output="A",
46 title="A test",
47 description="A test",
48 overwrite=True,
49 )
50 self.runModule(
51 "t.register",
52 flags="i",
53 type="raster",
54 input="A",
55 maps="a1,a2,a3,a4,a5,a6",
56 start="2001-01-01",
57 increment="3 months",
58 overwrite=True,
59 )
60
61 self.runModule(
62 "t.create",
63 type="strds",
64 temporaltype="absolute",
65 output="B",
66 title="B test",
67 description="B test",
68 overwrite=True,
69 )
70 self.runModule(
71 "t.register",
72 flags="i",
73 type="raster",
74 input="B",
75 maps="a1,a2,a3,a4,a5,a6",
76 start="2001-01-01",
77 increment="3 months",
78 overwrite=True,
79 )
80
81 def tearDown(self):
82 """Remove generated data"""
83 self.runModule("g.remove", flags="f", type="raster", name="a1,a2,a3,a4,a5,a6")
84
85 def test_1(self):
86 """Perform several unregistration operations"""
87
88 # Prepare some strings for the tests
89 new_line = os.linesep
90 a = ["a1", "a2", "a3", "a4", "a5", "a6"]
91 al = new_line.join(a)
92 al += new_line
93
94 a123 = new_line.join(a[:3])
95 a123 += new_line
96
97 a456 = new_line.join(a[3:])
98 a456 += new_line
99
100 # Unregister maps a1, a2 and a3 from STRDS A
101 self.assertModule("t.unregister", input="A", maps="a1,a2,a3")
102
103 lister = SimpleModule("t.rast.list", input="A", columns="name", flags="u")
104 self.runModule(lister)
105 self.assertEqual(a456, lister.outputs.stdout)
106
107 # Check if all maps are present in STRDS B
108 lister = SimpleModule("t.rast.list", input="B", columns="name", flags="u")
109 self.runModule(lister)
110 self.assertEqual(al, lister.outputs.stdout)
111
112 # Check if maps a1, a2 and a3 are still present in the temporal database
113 lister = SimpleModule(
114 "t.list",
115 type="raster",
116 columns="name",
117 where="mapset = '%s' AND (name = 'a1' OR name = 'a2' OR name = 'a3')"
118 % (tgis.get_current_mapset()),
119 )
120 self.runModule(lister)
121 self.assertEqual(a123, lister.outputs.stdout)
122
123 # Unregister maps a1, a2 and a3 from the temporal database
124 self.assertModule("t.unregister", maps="a1,a2,a3")
125
126 lister = SimpleModule(
127 "t.list",
128 type="raster",
129 columns="name",
130 where="mapset = '%s' AND (name = 'a1' OR name = 'a2' OR name = 'a3')"
131 % (tgis.get_current_mapset()),
132 )
133 self.runModule(lister)
134 self.assertEqual("", lister.outputs.stdout)
135
136 # Check that masp a1, a2 and a3 are not present in STRDS B
137 lister = SimpleModule("t.rast.list", input="B", columns="name", flags="u")
138 self.runModule(lister)
139 self.assertEqual(a456, lister.outputs.stdout)
140
141 # Remove STRDS A and B and check if maps a4, a5 and a6 are still in the temporal database
142 self.assertModule("t.remove", type="strds", inputs="A,B")
143
144 lister = SimpleModule(
145 "t.list",
146 type="raster",
147 columns="name",
148 where="mapset = '%s' AND (name = 'a4' OR name = 'a5' OR name = 'a6')"
149 % (tgis.get_current_mapset()),
150 )
151 self.runModule(lister)
152 self.assertEqual(a456, lister.outputs.stdout)
153
154 # Unregister maps a4, a5 and a6 from the temporal database
155 self.assertModule("t.unregister", maps="a4,a5,a6")
156
157 lister = SimpleModule(
158 "t.list",
159 type="raster",
160 columns="name",
161 where="mapset = '%s' AND (name = 'a4' OR name = 'a5' OR name = 'a6')"
162 % (tgis.get_current_mapset()),
163 )
164 self.runModule(lister)
165 self.assertEqual("", lister.outputs.stdout)
166
167
168 if __name__ == "__main__":
169 from grass.gunittest.main import test
170
171 test()