[GRASS-SVN] r55560 - in grass-addons/grass7/raster/r.agent: libagent tests
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Mar 27 09:05:15 PDT 2013
Author: mic
Date: 2013-03-27 09:05:14 -0700 (Wed, 27 Mar 2013)
New Revision: 55560
Modified:
grass-addons/grass7/raster/r.agent/libagent/grassland.py
grass-addons/grass7/raster/r.agent/tests/test_grassland.py
Log:
implement write grass layer
Modified: grass-addons/grass7/raster/r.agent/libagent/grassland.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/grassland.py 2013-03-27 15:41:58 UTC (rev 55559)
+++ grass-addons/grass7/raster/r.agent/libagent/grassland.py 2013-03-27 16:05:14 UTC (rev 55560)
@@ -78,10 +78,15 @@
raise error.DataError("r.agent::libagent.grassland.Grassland()",
"Grass Map name is empty.")
if self.layers.has_key(layername):
- if force:
- force="force"
- self.layers[layername].write(self.grassmapnames[layername],
- overwrite=force)
+ if grassmapname in \
+ grass.list_grouped('rast')[grass.gisenv()['MAPSET']]:
+ if force:
+ force="force"
+ else:
+ raise error.DataError(
+ "r.agent::libagent.grassland.Grassland()",
+ "Grass map already exists.")
+ self.layers[layername].write(grassmapname, overwrite=force)
def parsevectorlayer(self, layername, grassmapname, value=1, force=False):
"""
Modified: grass-addons/grass7/raster/r.agent/tests/test_grassland.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_grassland.py 2013-03-27 15:41:58 UTC (rev 55559)
+++ grass-addons/grass7/raster/r.agent/tests/test_grassland.py 2013-03-27 16:05:14 UTC (rev 55560)
@@ -107,9 +107,20 @@
def test_writelayer(self):
if self.rastlayername:
+ # create an empty test map
layer = garray.array()
-# TODO
- pass
+ self.pg.createlayer(self.rastlayername, self.rastlayername)
+ # write it once
+ self.pg.writelayer(self.rastlayername)
+ # now remove it from the internal grasslayer list
+ self.pg.grassmapnames.pop(self.rastlayername)
+ self.assertRaises(error.DataError, self.pg.writelayer,
+ self.rastlayername)
+ # try again, this time being explicit, but still fail
+ self.assertRaises(error.DataError, self.pg.writelayer,
+ *[self.rastlayername, self.rastlayername])
+ # force write it again..
+ self.pg.writelayer(self.rastlayername, self.rastlayername, True)
def test_parsegrasslayer(self):
if self.vectlayername:
More information about the grass-commit
mailing list