[GRASS-SVN] r66249 - in grass/trunk/temporal/t.support: . testsuite

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Sep 16 09:24:10 PDT 2015


Author: huhabla
Date: 2015-09-16 09:24:10 -0700 (Wed, 16 Sep 2015)
New Revision: 66249

Added:
   grass/trunk/temporal/t.support/testsuite/
   grass/trunk/temporal/t.support/testsuite/test_support_str3ds.py
   grass/trunk/temporal/t.support/testsuite/test_support_strds.py
   grass/trunk/temporal/t.support/testsuite/test_support_stvds.py
Modified:
   grass/trunk/temporal/t.support/t.support.py
Log:
temporal modules: Added python tests to t.support, added aggregation type setting


Modified: grass/trunk/temporal/t.support/t.support.py
===================================================================
--- grass/trunk/temporal/t.support/t.support.py	2015-09-16 15:46:16 UTC (rev 66248)
+++ grass/trunk/temporal/t.support/t.support.py	2015-09-16 16:24:10 UTC (rev 66249)
@@ -54,6 +54,14 @@
 #% multiple: no
 #%end
 
+#%option
+#% key:  aggr_type
+#% type: string
+#% description: Aggregation type of the space time raster or 3D raster dataset
+#% required: no
+#% multiple: no
+#%end
+
 #%flag
 #% key: m
 #% label: Update the metadata information and spatial extent of registered maps from the GRASS spatial database
@@ -62,7 +70,7 @@
 
 #%flag
 #% key: u
-#% description: Update metadata information, temporal and spatial extent from registered maps
+#% description: Update metadata information, temporal and spatial extent from registered maps based on database entries.
 #%end
 
 
@@ -77,6 +85,7 @@
     name = options["input"]
     type = options["type"]
     title = options["title"]
+    aggr_type = options["aggr_type"]
     description = options["description"]
     semantic = options["semantictype"]
     update = flags["u"]
@@ -91,6 +100,12 @@
     stds = tgis.open_old_stds(name, type, dbif)
 
     update = False
+    if aggr_type and type == "stvds":
+        return()
+    
+    if aggr_type and type != "stvds":
+        stds.metadata.set_aggregation_type(aggregation_type=aggr_type)
+        update = True
     if title:
         stds.metadata.set_title(title=title)
         update = True

Added: grass/trunk/temporal/t.support/testsuite/test_support_str3ds.py
===================================================================
--- grass/trunk/temporal/t.support/testsuite/test_support_str3ds.py	                        (rev 0)
+++ grass/trunk/temporal/t.support/testsuite/test_support_str3ds.py	2015-09-16 16:24:10 UTC (rev 66249)
@@ -0,0 +1,105 @@
+"""Test t.support
+
+(C) 2015 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.
+
+:authors: Soeren Gebbert
+"""
+import os
+import grass.pygrass.modules as pymod
+import grass.temporal as tgis
+from grass.gunittest.case import TestCase
+from grass.gunittest.gmodules import SimpleModule
+
+class TestSupportAbsoluteSTR3DS(TestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        """Initiate the temporal GIS and set the region
+        """
+        os.putenv("GRASS_OVERWRITE",  "1")
+        tgis.init()
+        cls.use_temp_region()
+        cls.runModule("g.region",  s=0,  n=80,  w=0,  e=120,  b=0,  
+                      t=50,  res=10,  res3=10)
+        cls.runModule("r3.mapcalc", expression="a1 = 100",  overwrite=True)
+        cls.runModule("r3.mapcalc", expression="a2 = 200",  overwrite=True)
+        cls.runModule("r3.mapcalc", expression="a3 = 300",  overwrite=True)
+        cls.runModule("r3.mapcalc", expression="a4 = 400",  overwrite=True)
+
+        cls.runModule("t.create",  type="str3ds",  temporaltype="absolute",  
+                                    output="A",  title="A test",  
+                                    description="A test",  overwrite=True)
+
+        cls.runModule("t.register", flags="i",  type="raster_3d",  input="A",  
+                                     maps="a1,a2,a3,a4",
+                                     start="2001-01-15 12:05:45", 
+                                     increment="14 days",  
+                                     overwrite=True)
+    @classmethod
+    def tearDownClass(cls):
+        """Remove the temporary region
+        """
+        cls.del_temp_region()        
+        cls.runModule("t.remove", flags="rf", type="str3ds", inputs="A")
+        
+    def test_1_metadata(self):
+        """Set title, description and aggregation"""
+        
+        title="A new title"
+        descr="A new description"
+        aggr_type="average"
+        semantic="sum"
+        
+        self.assertModule("t.support", type="str3ds", input="A",
+                          title=title,
+                          description=descr,
+                          semantictype=semantic,
+                          aggr_type=aggr_type)
+
+        A = tgis.open_old_stds("A", type="str3ds")
+        A.select()
+        self.assertEqual(A.metadata.get_title(), title)  
+        self.assertEqual(A.metadata.get_description(), descr)  
+        self.assertEqual(A.metadata.get_aggregation_type(), aggr_type)   
+        self.assertEqual(A.base.get_semantic_type(), semantic)        
+        
+    def test_2_update(self):
+        """Set title, description and aggregation"""
+        
+        self.runModule("r3.mapcalc", expression="a1 = 10",  overwrite=True)
+        self.runModule("r3.mapcalc", expression="a2 = 20",  overwrite=True)
+        self.runModule("r3.mapcalc", expression="a3 = 30",  overwrite=True)
+        self.runModule("r3.mapcalc", expression="a4 = 40",  overwrite=True)
+        
+        self.assertModule("t.support", type="str3ds", input="A", flags="m")
+
+        A = tgis.open_old_stds("A", type="str3ds")
+        A.select()
+        self.assertEqual(A.metadata.get_min_min(), 10) 
+        self.assertEqual(A.metadata.get_min_max(), 40)  
+        self.assertEqual(A.metadata.get_max_min(), 10) 
+        self.assertEqual(A.metadata.get_max_max(), 40) 
+        self.assertEqual(A.metadata.get_number_of_maps(), 4)      
+
+    def test_3_update(self):
+        """Set title, description and aggregation"""
+        
+        self.runModule("g.remove", type="raster_3d", name="a4", flags="f")
+        
+        self.assertModule("t.support", type="str3ds", input="A", flags="m")
+
+        A = tgis.open_old_stds("A", type="str3ds")
+        A.select()
+        self.assertEqual(A.metadata.get_min_min(), 10) 
+        self.assertEqual(A.metadata.get_min_max(), 30)  
+        self.assertEqual(A.metadata.get_max_min(), 10) 
+        self.assertEqual(A.metadata.get_max_max(), 30)  
+        self.assertEqual(A.metadata.get_number_of_maps(), 3)      
+
+
+if __name__ == '__main__':
+    from grass.gunittest.main import test
+    test()

Added: grass/trunk/temporal/t.support/testsuite/test_support_strds.py
===================================================================
--- grass/trunk/temporal/t.support/testsuite/test_support_strds.py	                        (rev 0)
+++ grass/trunk/temporal/t.support/testsuite/test_support_strds.py	2015-09-16 16:24:10 UTC (rev 66249)
@@ -0,0 +1,105 @@
+"""Test t.support
+
+(C) 2015 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.
+
+:authors: Soeren Gebbert
+"""
+import os
+import grass.pygrass.modules as pymod
+import grass.temporal as tgis
+from grass.gunittest.case import TestCase
+from grass.gunittest.gmodules import SimpleModule
+
+class TestSupportAbsoluteSTRDS(TestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        """Initiate the temporal GIS and set the region
+        """
+        os.putenv("GRASS_OVERWRITE",  "1")
+        tgis.init()
+        cls.use_temp_region()
+        cls.runModule("g.region",  s=0,  n=80,  w=0,  e=120,  b=0,  
+                      t=50,  res=10,  res3=10)
+        cls.runModule("r.mapcalc", expression="a1 = 100",  overwrite=True)
+        cls.runModule("r.mapcalc", expression="a2 = 200",  overwrite=True)
+        cls.runModule("r.mapcalc", expression="a3 = 300",  overwrite=True)
+        cls.runModule("r.mapcalc", expression="a4 = 400",  overwrite=True)
+
+        cls.runModule("t.create",  type="strds",  temporaltype="absolute",  
+                                    output="A",  title="A test",  
+                                    description="A test",  overwrite=True)
+
+        cls.runModule("t.register", flags="i",  type="raster",  input="A",  
+                                     maps="a1,a2,a3,a4",
+                                     start="2001-01-15 12:05:45", 
+                                     increment="14 days",  
+                                     overwrite=True)
+    @classmethod
+    def tearDownClass(cls):
+        """Remove the temporary region
+        """
+        cls.del_temp_region()        
+        cls.runModule("t.remove", flags="rf", type="strds", inputs="A")
+        
+    def test_1_metadata(self):
+        """Set title, description and aggregation"""
+        
+        title="A new title"
+        descr="A new description"
+        aggr_type="average"
+        semantic="sum"
+        
+        self.assertModule("t.support", input="A",
+                          title=title,
+                          description=descr,
+                          semantictype=semantic,
+                          aggr_type=aggr_type)
+
+        A = tgis.open_old_stds("A", type="strds")
+        A.select()
+        self.assertEqual(A.metadata.get_title(), title)  
+        self.assertEqual(A.metadata.get_description(), descr)  
+        self.assertEqual(A.metadata.get_aggregation_type(), aggr_type)   
+        self.assertEqual(A.base.get_semantic_type(), semantic)        
+        
+    def test_2_update(self):
+        """Set title, description and aggregation"""
+        
+        self.runModule("r.mapcalc", expression="a1 = 10",  overwrite=True)
+        self.runModule("r.mapcalc", expression="a2 = 20",  overwrite=True)
+        self.runModule("r.mapcalc", expression="a3 = 30",  overwrite=True)
+        self.runModule("r.mapcalc", expression="a4 = 40",  overwrite=True)
+        
+        self.assertModule("t.support", input="A", flags="m")
+
+        A = tgis.open_old_stds("A", type="strds")
+        A.select()
+        self.assertEqual(A.metadata.get_min_min(), 10) 
+        self.assertEqual(A.metadata.get_min_max(), 40)  
+        self.assertEqual(A.metadata.get_max_min(), 10) 
+        self.assertEqual(A.metadata.get_max_max(), 40) 
+        self.assertEqual(A.metadata.get_number_of_maps(), 4)      
+
+    def test_3_update(self):
+        """Set title, description and aggregation"""
+        
+        self.runModule("g.remove", type="raster", name="a4", flags="f")
+        
+        self.assertModule("t.support", input="A", flags="m")
+
+        A = tgis.open_old_stds("A", type="strds")
+        A.select()
+        self.assertEqual(A.metadata.get_min_min(), 10) 
+        self.assertEqual(A.metadata.get_min_max(), 30)  
+        self.assertEqual(A.metadata.get_max_min(), 10) 
+        self.assertEqual(A.metadata.get_max_max(), 30)  
+        self.assertEqual(A.metadata.get_number_of_maps(), 3)      
+
+
+if __name__ == '__main__':
+    from grass.gunittest.main import test
+    test()

Added: grass/trunk/temporal/t.support/testsuite/test_support_stvds.py
===================================================================
--- grass/trunk/temporal/t.support/testsuite/test_support_stvds.py	                        (rev 0)
+++ grass/trunk/temporal/t.support/testsuite/test_support_stvds.py	2015-09-16 16:24:10 UTC (rev 66249)
@@ -0,0 +1,96 @@
+"""Test t.support
+
+(C) 2015 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.
+
+:authors: Soeren Gebbert
+"""
+import os
+import grass.pygrass.modules as pymod
+import grass.temporal as tgis
+from grass.gunittest.case import TestCase
+from grass.gunittest.gmodules import SimpleModule
+
+class TestSupportAbsoluteSTVDS(TestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        """Initiate the temporal GIS and set the region
+        """
+        os.putenv("GRASS_OVERWRITE",  "1")
+        tgis.init()
+        cls.use_temp_region()
+        cls.runModule("g.region",  s=0,  n=80,  w=0,  e=120,  b=0,  
+                      t=50,  res=10,  res3=10)
+        cls.runModule("v.random", quiet=True, npoints=20, seed=1,  output='a1')
+        cls.runModule("v.random", quiet=True, npoints=20, seed=1,  output='a2')
+        cls.runModule("v.random", quiet=True, npoints=20, seed=1,  output='a3')
+        cls.runModule("v.random", quiet=True, npoints=20, seed=1,  output='a4')
+
+        cls.runModule("t.create",  type="stvds",  temporaltype="absolute",  
+                                    output="A",  title="A test",  
+                                    description="A test",  overwrite=True)
+
+        cls.runModule("t.register", flags="i",  type="vector",  input="A",  
+                                     maps="a1,a2,a3,a4",
+                                     start="2001-01-15 12:05:45", 
+                                     increment="14 days",  
+                                     overwrite=True)
+    @classmethod
+    def tearDownClass(cls):
+        """Remove the temporary region
+        """
+        cls.del_temp_region()        
+        cls.runModule("t.remove", flags="rf", type="stvds", inputs="A")
+        
+    def test_1_metadata(self):
+        """Set title, description and aggregation"""
+        
+        title="A new title"
+        descr="A new description"
+        semantic="sum"
+        
+        self.assertModule("t.support", type="stvds", input="A",
+                          title=title,
+                          description=descr,
+                          semantictype=semantic)
+
+        A = tgis.open_old_stds("A", type="stvds")
+        A.select()
+        self.assertEqual(A.metadata.get_title(), title)  
+        self.assertEqual(A.metadata.get_description(), descr)  
+        self.assertEqual(A.base.get_semantic_type(), semantic)        
+        
+    def test_2_update(self):
+        """Set title, description and aggregation"""
+        
+        self.runModule("v.random", quiet=True, npoints=10, seed=1,  output='a1')
+        self.runModule("v.random", quiet=True, npoints=10, seed=1,  output='a2')
+        self.runModule("v.random", quiet=True, npoints=10, seed=1,  output='a3')
+        self.runModule("v.random", quiet=True, npoints=10, seed=1,  output='a4')
+        
+        self.assertModule("t.support", type="stvds", input="A", flags="m")
+
+        A = tgis.open_old_stds("A", type="stvds")
+        A.select()
+        self.assertEqual(A.metadata.get_number_of_points(), 40) 
+        self.assertEqual(A.metadata.get_number_of_maps(), 4)      
+
+    def test_3_update(self):
+        """Set title, description and aggregation"""
+        
+        self.runModule("g.remove", type="vector", name="a4", flags="f")
+        
+        self.assertModule("t.support", type="stvds", input="A", flags="m")
+
+        A = tgis.open_old_stds("A", type="stvds")
+        A.select()
+        self.assertEqual(A.metadata.get_number_of_points(), 30) 
+        self.assertEqual(A.metadata.get_number_of_maps(), 3)      
+
+
+if __name__ == '__main__':
+    from grass.gunittest.main import test
+    test()



More information about the grass-commit mailing list