[GRASS-SVN] r54849 - in grass-addons/grass7/raster/r.agent: libagent tests
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Feb 2 12:20:43 PST 2013
Author: mic
Date: 2013-02-02 12:20:42 -0800 (Sat, 02 Feb 2013)
New Revision: 54849
Modified:
grass-addons/grass7/raster/r.agent/libagent/playground.py
grass-addons/grass7/raster/r.agent/libagent/world.py
grass-addons/grass7/raster/r.agent/tests/test_playground.py
Log:
fix getregion and clean error msgs
Modified: grass-addons/grass7/raster/r.agent/libagent/playground.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/playground.py 2013-02-02 19:48:09 UTC (rev 54848)
+++ grass-addons/grass7/raster/r.agent/libagent/playground.py 2013-02-02 20:20:42 UTC (rev 54849)
@@ -20,6 +20,7 @@
def __init__(self):
"""Create a Playground"""
self.layers = dict()
+ self.region = dict()
self.setregion(1,1)
def setregion(self, rows, cols):
@@ -29,8 +30,19 @@
@param numeric number of rows
@param numeric number of columns
"""
- self.region = dict(s=0,n=rows,w=0,e=cols,rows=rows,cols=cols)
+ self.region["s"] = 0
+ self.region["n"] = rows
+ self.region["w"] = 0
+ self.region["e"] = cols
+ self.region["rows"] = rows
+ self.region["cols"] = cols
+ for layer in self.layers:
+ if not ( len(layer) is rows and len(layer[0]) is cols):
+ raise error.Error(
+ "r.agent::libagent.playground.Playground.setregion()",
+ "new region is incompatible with some layer(s).")
+
def getregion(self):
"""
Return the region information
@@ -55,8 +67,9 @@
@param boolean optional, whether to overwrite values if key exists
"""
if not force and self.layers.has_key(layername):
- raise error.Error("r.agent::libagent.playground.Playground()",
- "May not overwrite existing layer.")
+ raise error.Error(
+ "r.agent::libagent.playground.Playground.setlayer()",
+ "May not overwrite existing layer.")
self.layers[layername] = layer
def createlayer(self, layername, filename=False, force=False):
Modified: grass-addons/grass7/raster/r.agent/libagent/world.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/world.py 2013-02-02 19:48:09 UTC (rev 54848)
+++ grass-addons/grass7/raster/r.agent/libagent/world.py 2013-02-02 20:20:42 UTC (rev 54849)
@@ -81,7 +81,8 @@
"""
position = self.findposition(position)
if not position:
- raise error.DataError("world.bear", "invalid position")
+ raise error.DataError("r.agent::libagent.world.World.bear()",
+ "invalid position")
agent = self.agenttype(timetolive, self, position)
self.agents.append(agent)
return agent
@@ -94,7 +95,8 @@
"""
position = self.findposition(position)
if not position:
- raise error.DataError("world.bear", "invalid position")
+ raise error.DataError("r.agent::libagent.world.World.move()",
+ "invalid position")
agent.setposition(position)
def getneighbourpositions(self, position, freedom=None):
Modified: grass-addons/grass7/raster/r.agent/tests/test_playground.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_playground.py 2013-02-02 19:48:09 UTC (rev 54848)
+++ grass-addons/grass7/raster/r.agent/tests/test_playground.py 2013-02-02 20:20:42 UTC (rev 54849)
@@ -9,8 +9,11 @@
self.pg = playground.Playground()
def test_setregion(self):
- # is actually already tested by playground.Playground.__init__()
- pass
+ self.assertTrue(self.pg.region["rows"] == 1)
+ self.pg.setregion(2,1)
+ self.pg.createlayer("bar")
+ self.assertTrue(self.pg.region["rows"] == 2)
+ self.assertRaises(error.Error, self.pg.setregion, *[2,1])
def test_getregion(self):
self.assertIsNotNone(self.pg.getregion())
More information about the grass-commit
mailing list