[GRASS-SVN] r61227 - grass/trunk/lib/python/temporal/testsuite

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jul 9 19:18:32 PDT 2014


Author: wenzeslaus
Date: 2014-07-09 19:18:32 -0700 (Wed, 09 Jul 2014)
New Revision: 61227

Modified:
   grass/trunk/lib/python/temporal/testsuite/unittests_register.py
Log:
testing: use gunittest methods for temporary region, remove trailing whitespace

motivation for fix is actually a change of 'grass' from 'grass.script' back to 'grass' after 'import grass.gunittest' and subsequent error when acessing grass.script.use_temp_region (this is not a problem of gunittest, its import or Python, this shows how 'import grass.script as grass' is a bad practice)

moreover, grass.script.overwrite is a function, so assigning True does nothing (although the suggested API is interesting)

Modified: grass/trunk/lib/python/temporal/testsuite/unittests_register.py
===================================================================
--- grass/trunk/lib/python/temporal/testsuite/unittests_register.py	2014-07-10 02:00:33 UTC (rev 61226)
+++ grass/trunk/lib/python/temporal/testsuite/unittests_register.py	2014-07-10 02:18:32 UTC (rev 61227)
@@ -1,4 +1,4 @@
-"""!Unit test to register raster maps with absolute and relative 
+"""!Unit test to register raster maps with absolute and relative
    time using tgis.register_maps_in_space_time_dataset()
 
 (C) 2013 by the GRASS Development Team
@@ -9,7 +9,6 @@
 @author Soeren Gebbert
 """
 
-import grass.script as grass
 import grass.temporal as tgis
 import grass.gunittest
 import datetime
@@ -24,16 +23,15 @@
         # Use always the current mapset as temporal database
         cls.runModule("g.gisenv", set="TGIS_USE_CURRENT_MAPSET=1")
         tgis.init()
-        grass.overwrite = True
-        grass.use_temp_region()
-        cls.runModule("g.region", n=80.0, s=0.0, e=120.0,
-                               w=0.0, t=1.0, b=0.0, res=10.0)
+        cls.use_temp_region()
+        cls.runModule('g.region', n=80.0, s=0.0, e=120.0, w=0.0,
+                      t=1.0, b=0.0, res=10.0)
 
     @classmethod
     def tearDownClass(cls):
         """!Remove the temporary region
         """
-        grass.del_temp_region()
+        cls.del_temp_region()
 
     def setUp(self):
         """!Create the test maps and the space time raster datasets
@@ -43,9 +41,9 @@
         self.runModule("r.mapcalc", overwrite=True, quiet=True,
                        expression="register_map_2 = 2")
 
-        self.strds_abs = tgis.open_new_stds(name="register_test_abs", type="strds", temporaltype="absolute", 
+        self.strds_abs = tgis.open_new_stds(name="register_test_abs", type="strds", temporaltype="absolute",
                                             title="Test strds", descr="Test strds", semantic="field")
-        self.strds_rel = tgis.open_new_stds(name="register_test_rel", type="strds", temporaltype="relative", 
+        self.strds_rel = tgis.open_new_stds(name="register_test_rel", type="strds", temporaltype="relative",
                                             title="Test strds", descr="Test strds", semantic="field")
 
     def tearDown(self):
@@ -60,7 +58,7 @@
         """!Test the registration of maps with absolute time in a
            space time raster dataset
         """
-        tgis.register_maps_in_space_time_dataset(type="rast", name=self.strds_abs.get_name(), 
+        tgis.register_maps_in_space_time_dataset(type="rast", name=self.strds_abs.get_name(),
                  maps="register_map_1,register_map_2",
                  start="2001-01-01", increment="1 day", interval=True)
 
@@ -92,7 +90,7 @@
         ciface.write_raster_timestamp("register_map_1", tgis.get_current_mapset(), "1 Jan 2001/2 Jan 2001")
         ciface.write_raster_timestamp("register_map_2", tgis.get_current_mapset(), "2 Jan 2001/3 Jan 2001")
 
-        tgis.register_maps_in_space_time_dataset(type="rast", name=self.strds_abs.get_name(), 
+        tgis.register_maps_in_space_time_dataset(type="rast", name=self.strds_abs.get_name(),
                                                  maps="register_map_1,register_map_2")
 
         map = tgis.RasterDataset("register_map_1@" + tgis.get_current_mapset())
@@ -115,7 +113,7 @@
     def test_absolute_time_1(self):
         """!Test the registration of maps with absolute time
         """
-        tgis.register_maps_in_space_time_dataset(type="rast", name=None, 
+        tgis.register_maps_in_space_time_dataset(type="rast", name=None,
                  maps="register_map_1,register_map_2",
                  start="2001-01-01", increment="1 day", interval=True)
 
@@ -134,7 +132,7 @@
     def test_absolute_time_2(self):
         """!Test the registration of maps with absolute time
         """
-        tgis.register_maps_in_space_time_dataset(type="rast", name=None, 
+        tgis.register_maps_in_space_time_dataset(type="rast", name=None,
                  maps="register_map_1,register_map_2",
                  start="2001-01-01 10:30:01", increment="8 hours", interval=False)
 
@@ -149,18 +147,18 @@
         self.assertEqual(start, datetime.datetime(2001, 1, 1, 18, 30, 1))
 
     def test_absolute_time_3(self):
-        """!Test the registration of maps with absolute time. 
+        """!Test the registration of maps with absolute time.
            The timestamps are set using the C-Interface beforehand, so that the register function needs
            to read the timetsamp from the map metadata.
         """
-                 
+
         ciface = tgis.get_tgis_c_library_interface()
         ciface.write_raster_timestamp("register_map_1", tgis.get_current_mapset(), "1 Jan 2001 10:30:01")
         ciface.write_raster_timestamp("register_map_2", tgis.get_current_mapset(), "1 Jan 2001 18:30:01")
 
-        tgis.register_maps_in_space_time_dataset(type="rast", name=None, 
+        tgis.register_maps_in_space_time_dataset(type="rast", name=None,
                  maps="register_map_1,register_map_2")
-                 
+
         map = tgis.RasterDataset("register_map_1@" + tgis.get_current_mapset())
         map.select()
         start, end = map.get_absolute_time()
@@ -176,8 +174,8 @@
            space time raster dataset
         """
 
-        tgis.register_maps_in_space_time_dataset(type="rast", name=self.strds_rel.get_name(), 
-                                                 maps="register_map_1,register_map_2", start=0, 
+        tgis.register_maps_in_space_time_dataset(type="rast", name=self.strds_rel.get_name(),
+                                                 maps="register_map_1,register_map_2", start=0,
                                                  increment=1, unit="day", interval=True)
 
         map = tgis.RasterDataset("register_map_1@" + tgis.get_current_mapset())
@@ -202,14 +200,14 @@
 
     def test_relative_time_strds_2(self):
         """!Test the registration of maps with relative time in a
-           space time raster dataset. The timetsamps are set for the maps using the 
+           space time raster dataset. The timetsamps are set for the maps using the
            C-interface before registration.
         """
         ciface = tgis.get_tgis_c_library_interface()
         ciface.write_raster_timestamp("register_map_1", tgis.get_current_mapset(), "1000000 seconds/1500000 seconds")
         ciface.write_raster_timestamp("register_map_2", tgis.get_current_mapset(), "1500000 seconds/2000000 seconds")
 
-        tgis.register_maps_in_space_time_dataset(type="rast", name=self.strds_rel.get_name(), 
+        tgis.register_maps_in_space_time_dataset(type="rast", name=self.strds_rel.get_name(),
                                                  maps="register_map_1,register_map_2")
 
         map = tgis.RasterDataset("register_map_1@" + tgis.get_current_mapset())
@@ -231,11 +229,11 @@
         self.assertEqual(start, 1000000)
         self.assertEqual(end, 2000000)
         self.assertEqual(unit, "seconds")
-        
+
     def test_relative_time_1(self):
         """!Test the registration of maps with relative time
         """
-        tgis.register_maps_in_space_time_dataset(type="rast", name=None, 
+        tgis.register_maps_in_space_time_dataset(type="rast", name=None,
                  maps="register_map_1,register_map_2",
                  start=0, increment=1, unit="day", interval=True)
 
@@ -256,7 +254,7 @@
     def test_relative_time_2(self):
         """!Test the registration of maps with relative time
         """
-        tgis.register_maps_in_space_time_dataset(type="rast", name=None, 
+        tgis.register_maps_in_space_time_dataset(type="rast", name=None,
                  maps="register_map_1,register_map_2",
                  start=1000000, increment=500000, unit="seconds", interval=True)
 
@@ -281,8 +279,8 @@
         ciface = tgis.get_tgis_c_library_interface()
         ciface.write_raster_timestamp("register_map_1", tgis.get_current_mapset(), "1000000 seconds/1500000 seconds")
         ciface.write_raster_timestamp("register_map_2", tgis.get_current_mapset(), "1500000 seconds/2000000 seconds")
-        
-        tgis.register_maps_in_space_time_dataset(type="rast", name=None, 
+
+        tgis.register_maps_in_space_time_dataset(type="rast", name=None,
                  maps="register_map_1,register_map_2")
 
         map = tgis.RasterDataset("register_map_1@" + tgis.get_current_mapset())



More information about the grass-commit mailing list