[GRASS-SVN] r54671 - in grass-addons/grass7/raster/r.agent: libagent tests

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jan 16 05:30:24 PST 2013


Author: mic
Date: 2013-01-16 05:30:24 -0800 (Wed, 16 Jan 2013)
New Revision: 54671

Modified:
   grass-addons/grass7/raster/r.agent/libagent/grassland.py
   grass-addons/grass7/raster/r.agent/libagent/playground.py
   grass-addons/grass7/raster/r.agent/tests/test_grassland.py
   grass-addons/grass7/raster/r.agent/tests/test_playground.py
Log:
add tests and move methods to upper class

Modified: grass-addons/grass7/raster/r.agent/libagent/grassland.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/grassland.py	2013-01-16 13:15:56 UTC (rev 54670)
+++ grass-addons/grass7/raster/r.agent/libagent/grassland.py	2013-01-16 13:30:24 UTC (rev 54671)
@@ -47,25 +47,6 @@
         """
         self.setgrasslayer(layername, False, force)
 
-    def getlayer(self, layername):
-        """
-        Return a layer from the collection by its name
-        @param string name of the layer
-        @return list the requested map layer
-        """
-        retval = False
-        if self.layers.has_key(layername):
-            retval = self.layers[layername]
-        return retval
-
-    def removelayer(self, layername):
-        """
-        Remove (forget about) the layer named from the layer collection
-        @param string name of the layer
-        """
-        if self.layers.has_key(layername):
-            self.layers.pop(layername)
-
     def writelayer(self, layername, force=False):
         if self.layers.has_key(layername) and \
           self.grassmapnames.has_key(layername):

Modified: grass-addons/grass7/raster/r.agent/libagent/playground.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/playground.py	2013-01-16 13:15:56 UTC (rev 54670)
+++ grass-addons/grass7/raster/r.agent/libagent/playground.py	2013-01-16 13:30:24 UTC (rev 54671)
@@ -47,14 +47,32 @@
                                     "May not overwrite existing layer.")
         self.layers[layername] = layer
 
-    def createlayer(self, layername, grassmap=False):
+    def createlayer(self, layername, force=False):
+        """
+        Create a new layer and add it to the layer collection
+        @param string name of the layer
+        @param boolean whether to overwrite an existing layer
+        """
         pass
 
     def getlayer(self, layername):
-        return []
+        """
+        Return a layer from the collection by its name
+        @param string name of the layer
+        @return list the requested map layer
+        """
+        retval = False
+        if self.layers.has_key(layername):
+            retval = self.layers[layername]
+        return retval
 
     def removelayer(self, layername):
-        pass
+        """
+        Remove (forget about) the layer named from the layer collection
+        @param string name of the layer
+        """
+        if self.layers.has_key(layername):
+            self.layers.pop(layername)
 
     def writelayer(self, layername):
         pass

Modified: grass-addons/grass7/raster/r.agent/tests/test_grassland.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_grassland.py	2013-01-16 13:15:56 UTC (rev 54670)
+++ grass-addons/grass7/raster/r.agent/tests/test_grassland.py	2013-01-16 13:30:24 UTC (rev 54671)
@@ -18,8 +18,22 @@
         self.assertIsNotNone(self.pg.getbound("e"))
 
 #    def test_setlayer(self):
-        # Enought if tested from Playground and e.g. setgrasslayer below..
+# Enought if tested from Playground and e.g. setgrasslayer below..
 
+    def test_createlayer(self):
+        #TODO
+        self.pg.createlayer("foo")
+
+    def test_getlayer(self):
+        self.pg.layers["foo"] = [0]
+        self.assertIs(self.pg.layers["foo"], self.pg.getlayer("foo"))
+
+    def test_removelayer(self):
+        self.pg.layers["foo"] = [0]
+        self.assertTrue(self.pg.layers.has_key("foo"))
+        self.pg.removelayer("foo")             
+        self.assertFalse(self.pg.layers.has_key("foo"))
+
 #    def tearDown(self):
 
 

Modified: grass-addons/grass7/raster/r.agent/tests/test_playground.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_playground.py	2013-01-16 13:15:56 UTC (rev 54670)
+++ grass-addons/grass7/raster/r.agent/tests/test_playground.py	2013-01-16 13:30:24 UTC (rev 54671)
@@ -28,5 +28,19 @@
         self.pg.setlayer(key, layer, True)
         self.assertIs(self.pg.layers[key], layer)
 
+    def test_createlayer(self):
+        #TODO
+        self.pg.createlayer("foo")
+
+    def test_getlayer(self):
+        self.pg.layers["foo"] = [0]
+        self.assertIs(self.pg.layers["foo"], self.pg.getlayer("foo"))
+
+    def test_removelayer(self):
+        self.pg.layers["foo"] = [0]
+        self.assertTrue(self.pg.layers.has_key("foo"))
+        self.pg.removelayer("foo")
+        self.assertFalse(self.pg.layers.has_key("foo"))
+
 #    def tearDown(self):
 



More information about the grass-commit mailing list