Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions python/grass/pygrass/raster/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#
# import GRASS modules
#
from grass.script import fatal, gisenv
from grass.exceptions import GrassError
from grass.script import gisenv
import grass.lib.gis as libgis
import grass.lib.raster as libraster

Expand All @@ -18,7 +19,7 @@
#
from grass.pygrass import utils
from grass.pygrass.gis.region import Region
from grass.pygrass.errors import must_be_open, must_be_in_current_mapset
from grass.pygrass.errors import must_be_in_current_mapset, must_be_open
from grass.pygrass.shell.conversion import dict2html
from grass.pygrass.shell.show import raw_figure

Expand Down Expand Up @@ -408,7 +409,7 @@ def __getitem__(self, key):
)
raise IndexError(msg)
return self.get_row(key)
fatal("Invalid argument type.")
raise TypeError("Invalid argument type: %r." % key)

def __iter__(self):
"""Return a constructor of the class"""
Expand Down Expand Up @@ -503,8 +504,8 @@ def set_region_from_rast(self, rastname="", mapset=""):

"""
if self.is_open():
fatal("You cannot change the region if map is open")
raise
msg = "You cannot change the region if map is open"
raise GrassError(msg)
region = Region()
if rastname == "":
rastname = self.name
Expand All @@ -522,8 +523,8 @@ def set_region(self, region):
The GRASS region settings will not be modified.
"""
if self.is_open():
fatal("You cannot change the region if map is open")
raise
msg = "You cannot change the region if map is open"
raise GrassError(msg)
self._set_raster_window(region)

def _set_raster_window(self, region):
Expand Down
16 changes: 15 additions & 1 deletion python/grass/pygrass/raster/testsuite/test_pygrass_raster.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from grass.exceptions import OpenError
from grass.exceptions import GrassError, OpenError
from grass.gunittest.case import TestCase
from grass.gunittest.main import test

Expand Down Expand Up @@ -88,6 +88,20 @@ def test_row_range(self):
r[9999]
r.close()

def test_getitem_invalid_type(self):
r = RasterRow(self.name)
with self.assertRaises(TypeError):
r["invalid_key"]

def test_set_region_open_map(self):
r = RasterRow(self.name)
r.open(mode="r")
with self.assertRaises(GrassError):
r.set_region_from_rast()
with self.assertRaises(GrassError):
r.set_region(None)
r.close()


if __name__ == "__main__":
test()
Loading