[GRASS-SVN] r72317 - in grass/trunk/lib/python/pygrass: . raster raster/testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Mar 3 04:15:41 PST 2018
Author: marisn
Date: 2018-03-03 04:15:41 -0800 (Sat, 03 Mar 2018)
New Revision: 72317
Modified:
grass/trunk/lib/python/pygrass/errors.py
grass/trunk/lib/python/pygrass/raster/__init__.py
grass/trunk/lib/python/pygrass/raster/abstract.py
grass/trunk/lib/python/pygrass/raster/buffer.py
grass/trunk/lib/python/pygrass/raster/category.py
grass/trunk/lib/python/pygrass/raster/history.py
grass/trunk/lib/python/pygrass/raster/segment.py
grass/trunk/lib/python/pygrass/raster/testsuite/test_category.py
grass/trunk/lib/python/pygrass/raster/testsuite/test_doctests.py
grass/trunk/lib/python/pygrass/raster/testsuite/test_history.py
grass/trunk/lib/python/pygrass/raster/testsuite/test_numpy.py
grass/trunk/lib/python/pygrass/raster/testsuite/test_raster.py
grass/trunk/lib/python/pygrass/raster/testsuite/test_raster_img.py
grass/trunk/lib/python/pygrass/raster/testsuite/test_raster_region.py
Log:
pygrass: raster PEP8 cleanup
Modified: grass/trunk/lib/python/pygrass/errors.py
===================================================================
--- grass/trunk/lib/python/pygrass/errors.py 2018-03-03 11:42:02 UTC (rev 72316)
+++ grass/trunk/lib/python/pygrass/errors.py 2018-03-03 12:15:41 UTC (rev 72317)
@@ -14,7 +14,8 @@
if self.is_open():
return method(self, *args, **kargs)
else:
- get_msgr().warning(_("The map is close!"))
+ msgr = get_msgr()
+ msgr.warning(_("The map is close!"))
return wrapper
Modified: grass/trunk/lib/python/pygrass/raster/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/__init__.py 2018-03-03 11:42:02 UTC (rev 72316)
+++ grass/trunk/lib/python/pygrass/raster/__init__.py 2018-03-03 12:15:41 UTC (rev 72317)
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import (nested_scopes, generators, division, absolute_import,
with_statement, print_function, unicode_literals)
-import os
import ctypes
import numpy as np
@@ -8,8 +7,7 @@
#
# import GRASS modules
#
-from grass.script import fatal, warning
-from grass.script import core as grasscore
+from grass.script import fatal
import grass.lib.gis as libgis
import grass.lib.raster as libraster
@@ -35,8 +33,9 @@
WARN_OVERWRITE = "Raster map <{0}> already exists and will be overwritten"
-test_raster_name="Raster_test_map"
+test_raster_name = "Raster_test_map"
+
class RasterRow(RasterAbstractBase):
"""Raster_row_access": Inherits: "Raster_abstract_base" and implements
the default row access of the Rast library.
@@ -329,7 +328,7 @@
def __setitem__(self, key, row):
"""Return the row of Raster object, slice allowed."""
if isinstance(key, slice):
- #Get the start, stop, and step from the slice
+ # Get the start, stop, and step from the slice
return [self.put_row(ii, row)
for ii in range(*key.indices(len(self)))]
elif isinstance(key, tuple):
@@ -546,7 +545,7 @@
self.hist.read()
if self.mode == "rw":
- #warning(_(WARN_OVERWRITE.format(self)))
+ # warning(_(WARN_OVERWRITE.format(self)))
# Close the file descriptor and open it as new again
libraster.Rast_close(self._fd)
self._fd = libraster.Rast_open_new(
@@ -553,7 +552,7 @@
self.name, self._gtype)
# Here we simply overwrite the existing map without content copying
elif self.mode == "w":
- #warning(_(WARN_OVERWRITE.format(self)))
+ # warning(_(WARN_OVERWRITE.format(self)))
self._gtype = RTYPE[self.mtype]['grass type']
self.segment.open(self)
self._fd = libraster.Rast_open_new(self.name, self._gtype)
@@ -678,7 +677,7 @@
color_mode = 4
if array is None:
- array = np.ndarray((region.rows*region.cols*scale), np.uint8)
+ array = np.ndarray((region.rows * region.cols * scale), np.uint8)
libraster.Rast_map_to_img_str(rastname, color_mode,
array.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8)))
@@ -709,16 +708,16 @@
if __name__ == "__main__":
import doctest
- from grass.pygrass import utils
from grass.pygrass.modules import Module
Module("g.region", n=40, s=0, e=40, w=0, res=10)
- Module("r.mapcalc", expression="%s = row() + (10 * col())"%(test_raster_name),
- overwrite=True)
+ Module("r.mapcalc",
+ expression="%s = row() + (10 * col())" % (test_raster_name),
+ overwrite=True)
Module("r.support", map=test_raster_name,
- title="A test map",
- history="Generated by r.mapcalc",
- description="This is a test map")
- cats="""11:A
+ title="A test map",
+ history="Generated by r.mapcalc",
+ description="This is a test map")
+ cats = """11:A
12:B
13:C
14:D
Modified: grass/trunk/lib/python/pygrass/raster/abstract.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/abstract.py 2018-03-03 11:42:02 UTC (rev 72316)
+++ grass/trunk/lib/python/pygrass/raster/abstract.py 2018-03-03 12:15:41 UTC (rev 72317)
@@ -11,7 +11,7 @@
#
# import GRASS modules
#
-from grass.script import fatal, error, gisenv
+from grass.script import fatal, gisenv
import grass.lib.gis as libgis
import grass.lib.raster as libraster
@@ -31,9 +31,9 @@
from grass.pygrass.raster.category import Category
from grass.pygrass.raster.history import History
-test_raster_name="abstract_test_map"
+test_raster_name = "abstract_test_map"
-## Define global variables to not exceed the 80 columns
+# Define global variables to not exceed the 80 columns
INDXOUTRANGE = "The index (%d) is out of range, have you open the map?."
INFO = """{name}@{mapset}
rows: {rows}
@@ -225,17 +225,17 @@
"""
self.mapset = mapset
self._name = name
- ## Private attribute `_fd` that return the file descriptor of the map
+ # Private attribute `_fd` that return the file descriptor of the map
self._fd = None
- ## Private attribute `_rows` that return the number of rows
+ # Private attribute `_rows` that return the number of rows
# in active window, When the class is instanced is empty and it is set
# when you open the file, using Rast_window_rows()
self._rows = None
- ## Private attribute `_cols` that return the number of rows
+ # Private attribute `_cols` that return the number of rows
# in active window, When the class is instanced is empty and it is set
# when you open the file, using Rast_window_cols()
self._cols = None
- #self.region = Region()
+ # self.region = Region()
self.hist = History(self.name, self.mapset)
self.cats = Category(self.name, self.mapset)
self.info = Info(self.name, self.mapset)
@@ -259,7 +259,6 @@
def _set_mtype(self, mtype):
"""Private method to change the Raster type"""
if mtype.upper() not in ('CELL', 'FCELL', 'DCELL'):
- #fatal(_("Raser type: {0} not supported".format(mtype) ) )
str_err = "Raster type: {0} not supported ('CELL','FCELL','DCELL')"
raise ValueError(_(str_err).format(mtype))
self._mtype = mtype
@@ -327,8 +326,7 @@
def __getitem__(self, key):
"""Return the row of Raster object, slice allowed."""
if isinstance(key, slice):
- #import pdb; pdb.set_trace()
- #Get the start, stop, and step from the slice
+ # Get the start, stop, and step from the slice
return (self.get_row(ii) for ii in range(*key.indices(len(self))))
elif isinstance(key, tuple):
x, y = key
@@ -556,11 +554,10 @@
if __name__ == "__main__":
import doctest
- from grass.pygrass import utils
from grass.pygrass.modules import Module
Module("g.region", n=40, s=0, e=40, w=0, res=10)
- Module("r.mapcalc", expression="%s = row() + (10 * col())"%(test_raster_name),
- overwrite=True)
+ Module("r.mapcalc", expression="%s = row() + (10 * col())" % (test_raster_name),
+ overwrite=True)
doctest.testmod()
Modified: grass/trunk/lib/python/pygrass/raster/buffer.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/buffer.py 2018-03-03 11:42:02 UTC (rev 72316)
+++ grass/trunk/lib/python/pygrass/raster/buffer.py 2018-03-03 12:15:41 UTC (rev 72317)
@@ -30,7 +30,6 @@
def __new__(cls, shape, mtype='FCELL', buffer=None, offset=0,
strides=None, order=None):
- #import pdb; pdb.set_trace()
obj = np.ndarray.__new__(cls, shape, RTYPE[mtype]['numpy'],
buffer, offset, strides, order)
obj.pointer_type = ctypes.POINTER(RTYPE[mtype]['ctypes'])
Modified: grass/trunk/lib/python/pygrass/raster/category.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/category.py 2018-03-03 11:42:02 UTC (rev 72316)
+++ grass/trunk/lib/python/pygrass/raster/category.py 2018-03-03 12:15:41 UTC (rev 72317)
@@ -8,6 +8,7 @@
from operator import itemgetter
import grass.lib.raster as libraster
+from grass.exceptions import ImplementationError
from grass.pygrass.errors import GrassError
@@ -65,7 +66,6 @@
def _set_mtype(self, mtype):
if mtype.upper() not in ('CELL', 'FCELL', 'DCELL'):
- #fatal(_("Raser type: {0} not supported".format(mtype) ) )
raise ValueError(_("Raster type: {0} not supported".format(mtype)))
self._mtype = mtype
self._gtype = RTYPE[self.mtype]['grass type']
@@ -270,8 +270,8 @@
"""Not implemented yet.
void Rast_set_cats_fmt()
"""
- #TODO: add
- pass
+ # TODO: add
+ raise ImplementationError("set_cats_fmt() is not implemented yet.")
def read_rules(self, filename, sep=':'):
"""Copy categories from a rules file, default separetor is ':', the
@@ -300,7 +300,6 @@
label, min_cat, max_cat = cat
else:
raise TypeError("Row length is greater than 3")
- #import pdb; pdb.set_trace()
self.append((label, min_cat, max_cat))
def write_rules(self, filename, sep=':'):
Modified: grass/trunk/lib/python/pygrass/raster/history.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/history.py 2018-03-03 11:42:02 UTC (rev 72316)
+++ grass/trunk/lib/python/pygrass/raster/history.py 2018-03-03 12:15:41 UTC (rev 72317)
@@ -40,7 +40,7 @@
def __eq__(self, hist):
for attr in self.attrs:
- if getattr(self, attr) != getattr(hist, attr):
+ if getattr(self, attr) != getattr(hist, attr):
return False
return True
@@ -50,8 +50,8 @@
def __iter__(self):
return ((attr, getattr(self, attr)) for attr in self.attrs)
- #----------------------------------------------------------------------
- #libraster.HIST_CREATOR
+ # ----------------------------------------------------------------------
+ # libraster.HIST_CREATOR
def _get_creator(self):
return libraster.Rast_get_history(self.c_hist,
libraster.HIST_CREATOR)
@@ -64,8 +64,8 @@
creator = property(fget=_get_creator, fset=_set_creator,
doc="Set or obtain the creator of map")
- #----------------------------------------------------------------------
- #libraster.HIST_DATSRC_1
+ # ----------------------------------------------------------------------
+ # libraster.HIST_DATSRC_1
def _get_src1(self):
return libraster.Rast_get_history(self.c_hist,
libraster.HIST_DATSRC_1)
@@ -78,8 +78,8 @@
src1 = property(fget=_get_src1, fset=_set_src1,
doc="Set or obtain the first source of map")
- #----------------------------------------------------------------------
- #libraster.HIST_DATSRC_2
+ # ----------------------------------------------------------------------
+ # libraster.HIST_DATSRC_2
def _get_src2(self):
return libraster.Rast_get_history(self.c_hist,
libraster.HIST_DATSRC_2)
@@ -92,8 +92,8 @@
src2 = property(fget=_get_src2, fset=_set_src2,
doc="Set or obtain the second source of map")
- #----------------------------------------------------------------------
- #libraster.HIST_KEYWORD
+ # ----------------------------------------------------------------------
+ # libraster.HIST_KEYWORD
def _get_keyword(self):
return libraster.Rast_get_history(self.c_hist,
libraster.HIST_KEYWRD)
@@ -106,8 +106,8 @@
keyword = property(fget=_get_keyword, fset=_set_keyword,
doc="Set or obtain the keywords of map")
- #----------------------------------------------------------------------
- #libraster.HIST_MAPID
+ # ----------------------------------------------------------------------
+ # libraster.HIST_MAPID
def _get_date(self):
date_str = libraster.Rast_get_history(self.c_hist,
libraster.HIST_MAPID)
@@ -127,8 +127,8 @@
date = property(fget=_get_date, fset=_set_date,
doc="Set or obtain the date of map")
- #----------------------------------------------------------------------
- #libraster.HIST_MAPSET
+ # ----------------------------------------------------------------------
+ # libraster.HIST_MAPSET
def _get_mapset(self):
return libraster.Rast_get_history(self.c_hist,
libraster.HIST_MAPSET)
@@ -141,8 +141,8 @@
mapset = property(fget=_get_mapset, fset=_set_mapset,
doc="Set or obtain the mapset of map")
- #----------------------------------------------------------------------
- #libraster.HIST_MAPTYPE
+ # ----------------------------------------------------------------------
+ # libraster.HIST_MAPTYPE
def _get_maptype(self):
return libraster.Rast_get_history(self.c_hist,
libraster.HIST_MAPTYPE)
@@ -155,8 +155,8 @@
maptype = property(fget=_get_maptype, fset=_set_maptype,
doc="Set or obtain the type of map")
- #----------------------------------------------------------------------
- #libraster.HIST_NUM_FIELDS
+ # ----------------------------------------------------------------------
+ # libraster.HIST_NUM_FIELDS
#
# Never used in any raster modules
#
@@ -170,8 +170,8 @@
# ctypes.c_char_p(num_fields))
#
# num_fields = property(fget = _get_num_fields, fset = _set_num_fields)
- #----------------------------------------------------------------------
- #libraster.HIST_TITLE
+ # ----------------------------------------------------------------------
+ # libraster.HIST_TITLE
def _get_title(self):
return libraster.Rast_get_history(self.c_hist,
libraster.HIST_TITLE)
Modified: grass/trunk/lib/python/pygrass/raster/segment.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/segment.py 2018-03-03 11:42:02 UTC (rev 72316)
+++ grass/trunk/lib/python/pygrass/raster/segment.py 2018-03-03 12:15:41 UTC (rev 72317)
@@ -47,7 +47,6 @@
self.val = RTYPE[mapobj.mtype]['grass def']()
size = ctypes.sizeof(RTYPE[mapobj.mtype]['ctypes'])
file_name = libgis.G_tempfile()
- #import pdb; pdb.set_trace()
libseg.Segment_open(self.c_seg, file_name,
self.rows(), self.cols(),
self.srows, self.scols,
Modified: grass/trunk/lib/python/pygrass/raster/testsuite/test_category.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/testsuite/test_category.py 2018-03-03 11:42:02 UTC (rev 72316)
+++ grass/trunk/lib/python/pygrass/raster/testsuite/test_category.py 2018-03-03 12:15:41 UTC (rev 72317)
@@ -22,13 +22,14 @@
"""Create test raster map and region"""
cls.use_temp_region()
cls.runModule("g.region", n=40, s=0, e=40, w=0, res=10)
- cls.runModule("r.mapcalc", expression="%s = row() + (10.0 * col())"%(cls.name),
- overwrite=True)
+ cls.runModule("r.mapcalc",
+ expression="%s = row() + (10.0 * col())" % (cls.name),
+ overwrite=True)
cls.runModule("r.support", map=cls.name,
- title="A test map",
- history="Generated by r.mapcalc",
- description="This is a test map")
- cats="""11:A
+ title="A test map",
+ history="Generated by r.mapcalc",
+ description="This is a test map")
+ cats = """11:A
12:B
13:C
14:D
@@ -46,12 +47,12 @@
44:P"""
cls.runModule("r.category", rules="-", map=cls.name,
- stdin_=cats, separator=":")
+ stdin_=cats, separator=":")
@classmethod
def tearDownClass(cls):
"""Remove the generated vector map, if exist"""
- cls.runModule("g.remove", flags='f', type='raster',
+ cls.runModule("g.remove", flags='f', type='raster',
name=cls.name)
cls.del_temp_region()
Modified: grass/trunk/lib/python/pygrass/raster/testsuite/test_doctests.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/testsuite/test_doctests.py 2018-03-03 11:42:02 UTC (rev 72316)
+++ grass/trunk/lib/python/pygrass/raster/testsuite/test_doctests.py 2018-03-03 12:15:41 UTC (rev 72317)
@@ -32,17 +32,16 @@
grass.gunittest.utils.do_doctest_gettext_workaround()
# this should be called at some top level
-
from grass.pygrass.modules import Module
Module("g.region", n=40, s=0, e=40, w=0, res=10)
- Module("r.mapcalc", expression="%s = row() + (10 * col())"%\
- (pgrass.test_raster_name),
- overwrite=True)
+ Module("r.mapcalc",
+ expression="%s = row() + (10 * col())" % (pgrass.test_raster_name),
+ overwrite=True)
Module("r.support", map=pgrass.test_raster_name,
- title="A test map",
- history="Generated by r.mapcalc",
- description="This is a test map")
- cats="""11:A
+ title="A test map",
+ history="Generated by r.mapcalc",
+ description="This is a test map")
+ cats = """11:A
12:B
13:C
14:D
@@ -61,9 +60,9 @@
Module("r.category", rules="-", map=pgrass.test_raster_name,
stdin_=cats, separator=":")
- Module("r.mapcalc", expression="%s = row() + (10 * col())"%\
- (pgrass.abstract.test_raster_name),
- overwrite=True)
+ Module("r.mapcalc",
+ expression="%s = row() + (10 * col())" % (pgrass.abstract.test_raster_name),
+ overwrite=True)
tests.addTests(doctest.DocTestSuite(pgrass))
tests.addTests(doctest.DocTestSuite(pgrass.abstract))
Modified: grass/trunk/lib/python/pygrass/raster/testsuite/test_history.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/testsuite/test_history.py 2018-03-03 11:42:02 UTC (rev 72316)
+++ grass/trunk/lib/python/pygrass/raster/testsuite/test_history.py 2018-03-03 12:15:41 UTC (rev 72317)
@@ -21,17 +21,18 @@
"""Create test raster map and region"""
cls.use_temp_region()
cls.runModule("g.region", n=40, s=0, e=40, w=0, res=10)
- cls.runModule("r.mapcalc", expression="%s = row() + (10 * col())"%(cls.name),
- overwrite=True)
+ cls.runModule("r.mapcalc",
+ expression="%s = row() + (10 * col())" % (cls.name),
+ overwrite=True)
cls.runModule("r.support", map=cls.name,
- title="A test map",
- history="Generated by r.mapcalc",
- description="This is a test map")
+ title="A test map",
+ history="Generated by r.mapcalc",
+ description="This is a test map")
@classmethod
def tearDownClass(cls):
"""Remove the generated vector map, if exist"""
- cls.runModule("g.remove", flags='f', type='raster',
+ cls.runModule("g.remove", flags='f', type='raster',
name=cls.name)
cls.del_temp_region()
@@ -41,13 +42,13 @@
hist = r.hist
self.assertEqual(hist.title, "A test map")
- self.assertEqual(hist.keyword, "This is a test map")
+ self.assertEqual(hist.keyword, "This is a test map")
hist1 = History(self.name)
hist1.read()
self.assertEqual(hist1.title, "A test map")
- self.assertEqual(hist1.keyword, "This is a test map")
+ self.assertEqual(hist1.keyword, "This is a test map")
self.assertEqual(hist, hist1)
self.assertEqual(hist.creator, hist1.creator)
@@ -65,7 +66,7 @@
hist = r.hist
self.assertEqual(hist.title, "No such title")
- self.assertEqual(hist.keyword, "No such description")
+ self.assertEqual(hist.keyword, "No such description")
self.assertEqual(hist.creator, "Markus")
self.assertEqual(hist.creator, "Markus")
self.assertEqual(hist.src1, "No such source 1")
Modified: grass/trunk/lib/python/pygrass/raster/testsuite/test_numpy.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/testsuite/test_numpy.py 2018-03-03 11:42:02 UTC (rev 72316)
+++ grass/trunk/lib/python/pygrass/raster/testsuite/test_numpy.py 2018-03-03 12:15:41 UTC (rev 72317)
@@ -29,8 +29,9 @@
"""Create test raster map and region"""
cls.use_temp_region()
cls.runModule("g.region", n=40, s=0, e=60, w=0, res=1)
- cls.runModule("r.mapcalc", expression="%s = float(row() + (10.0 * col()))"%(cls.name),
- overwrite=True)
+ cls.runModule("r.mapcalc",
+ expression="%s = float(row() + (10.0 * col()))" % (cls.name),
+ overwrite=True)
cls.numpy_obj = raster2numpy(cls.name)
@classmethod
Modified: grass/trunk/lib/python/pygrass/raster/testsuite/test_raster.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/testsuite/test_raster.py 2018-03-03 11:42:02 UTC (rev 72316)
+++ grass/trunk/lib/python/pygrass/raster/testsuite/test_raster.py 2018-03-03 12:15:41 UTC (rev 72317)
@@ -2,7 +2,6 @@
from grass.exceptions import OpenError
from grass.gunittest.case import TestCase
from grass.gunittest.main import test
-from unittest import skip
from grass.pygrass.raster import RasterRow
@@ -17,7 +16,7 @@
cls.use_temp_region()
cls.runModule("g.region", n=40, s=0, e=40, w=0, res=10)
cls.runModule("r.mapcalc", expression="%s = row() + (10.0 * col())" % (cls.name),
- overwrite=True)
+ overwrite=True)
@classmethod
def tearDownClass(cls):
Modified: grass/trunk/lib/python/pygrass/raster/testsuite/test_raster_img.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/testsuite/test_raster_img.py 2018-03-03 11:42:02 UTC (rev 72316)
+++ grass/trunk/lib/python/pygrass/raster/testsuite/test_raster_img.py 2018-03-03 12:15:41 UTC (rev 72317)
@@ -1,25 +1,23 @@
# -*- coding: utf-8
import numpy as np
import unittest
-import ctypes
-from unittest import skip
from grass.gunittest.case import TestCase
from grass.gunittest.main import test
-from grass.pygrass.raster import RasterRow
from grass.pygrass.raster import raster2numpy_img
from grass.pygrass.gis.region import Region
from grass.script.core import tempfile
-has_PyQt4=False
+has_PyQt4 = False
try:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
- has_PyQt4=True
+ has_PyQt4 = True
except:
pass
+
class RasterRowImgTestCase(TestCase):
name = "RasterRowImgTestCase_map"
@@ -29,8 +27,9 @@
"""Create test raster map and region"""
cls.use_temp_region()
cls.runModule("g.region", n=60, s=0, e=40, w=0, res=0.1)
- cls.runModule("r.mapcalc", expression="%s = if(row() >= 10 && row() <= 60, null(), row() + (10.0 * col()))"%(cls.name),
- overwrite=True)
+ cls.runModule("r.mapcalc",
+ expression="%s = if(row() >= 10 && row() <= 60, null(), row() + (10.0 * col()))" % (cls.name),
+ overwrite=True)
cls.runModule("r.colors", map=cls.name, color="elevation")
@classmethod
@@ -56,7 +55,7 @@
image = QImage(a.data, region.cols, region.rows,
QImage.Format_ARGB32)
- #image.save("data/a.png")
+ # image.save("data/a.png")
image.save(tmpfile)
self.assertFilesEqualMd5(tmpfile, "data/a.png")
@@ -73,7 +72,7 @@
tmpfile = tmpfile + ".png"
# With array as argument
- array = np.ndarray((region.rows*region.cols*4), np.uint8)
+ array = np.ndarray((region.rows * region.cols * 4), np.uint8)
raster2numpy_img(rastname=self.name, region=region,
color="ARGB", array=array)
@@ -80,7 +79,7 @@
image = QImage(array.data,
region.cols, region.rows, QImage.Format_ARGB32)
- #image.save("data/b.png")
+ # image.save("data/b.png")
image.save(tmpfile)
self.assertFilesEqualMd5(tmpfile, "data/b.png")
@@ -97,7 +96,7 @@
tmpfile = tmpfile + ".png"
# With array as argument
- array = np.ndarray((region.rows*region.cols*4), np.uint8)
+ array = np.ndarray((region.rows * region.cols * 4), np.uint8)
raster2numpy_img(rastname=self.name, region=region,
color="ARGB", array=array)
@@ -104,7 +103,7 @@
image = QImage(array.data,
region.cols, region.rows, QImage.Format_ARGB32)
- #image.save("data/c.png")
+ # image.save("data/c.png")
image.save(tmpfile)
self.assertFilesEqualMd5(tmpfile, "data/c.png")
@@ -121,7 +120,7 @@
tmpfile = tmpfile + ".png"
# With array as argument
- array = np.ndarray((region.rows*region.cols*4), np.uint8)
+ array = np.ndarray((region.rows * region.cols * 4), np.uint8)
raster2numpy_img(rastname=self.name, region=region,
color="RGB", array=array)
@@ -128,7 +127,7 @@
image = QImage(array.data,
region.cols, region.rows, QImage.Format_RGB32)
- #image.save("data/d.png")
+ # image.save("data/d.png")
image.save(tmpfile)
self.assertFilesEqualMd5(tmpfile, "data/d.png")
@@ -149,7 +148,7 @@
image = QImage(array.data,
region.cols, region.rows, QImage.Format_RGB32)
- #image.save("data/e.png")
+ # image.save("data/e.png")
image.save(tmpfile)
self.assertFilesEqualMd5(tmpfile, "data/e.png")
@@ -162,7 +161,7 @@
a = raster2numpy_img(self.name, region)
- self.assertEqual(len(a), region.rows * region.cols*4)
+ self.assertEqual(len(a), region.rows * region.cols * 4)
def test_resampling_to_numpy_img_2(self):
@@ -173,7 +172,7 @@
a = raster2numpy_img(self.name, region)
- self.assertEqual(len(a), region.rows * region.cols*4)
+ self.assertEqual(len(a), region.rows * region.cols * 4)
def test_resampling_to_numpy_img_3(self):
@@ -184,7 +183,7 @@
a = raster2numpy_img(self.name, region, color="GRAY1")
- self.assertEqual(len(a), region.rows * region.cols*1)
+ self.assertEqual(len(a), region.rows * region.cols * 1)
def test_resampling_to_numpy_img_4(self):
@@ -195,7 +194,7 @@
a = raster2numpy_img(self.name, region, color="GRAY2")
- self.assertEqual(len(a), region.rows * region.cols*1)
+ self.assertEqual(len(a), region.rows * region.cols * 1)
if __name__ == '__main__':
test()
Modified: grass/trunk/lib/python/pygrass/raster/testsuite/test_raster_region.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/testsuite/test_raster_region.py 2018-03-03 11:42:02 UTC (rev 72316)
+++ grass/trunk/lib/python/pygrass/raster/testsuite/test_raster_region.py 2018-03-03 12:15:41 UTC (rev 72317)
@@ -1,12 +1,12 @@
# -*- coding: utf-8
from grass.gunittest.case import TestCase
from grass.gunittest.main import test
-from unittest import skip
from grass.pygrass.raster import RasterRow
from grass.pygrass.raster import raster2numpy
from grass.pygrass.gis.region import Region
+
class RasterRowRegionTestCase(TestCase):
name = "RasterRowRegionTestCase_map"
@@ -16,13 +16,13 @@
"""Create test raster map and region"""
cls.use_temp_region()
cls.runModule("g.region", n=40, s=0, e=40, w=0, res=10)
- cls.runModule("r.mapcalc", expression="%s = row() + (10.0 * col())"%(cls.name),
- overwrite=True)
+ cls.runModule("r.mapcalc", expression="%s = row() + (10.0 * col())" % (cls.name),
+ overwrite=True)
@classmethod
def tearDownClass(cls):
"""Remove the generated vector map, if exist"""
- cls.runModule("g.remove", flags='f', type='raster',
+ cls.runModule("g.remove", flags='f', type='raster',
name=cls.name)
cls.del_temp_region()
@@ -42,8 +42,8 @@
rast.set_region(region)
rast.open(mode='r')
- self.assertItemsEqual(rast[0].tolist(), [22,22,22,22,22,32,32,32,32,32])
- self.assertItemsEqual(rast[5].tolist(), [23,23,23,23,23,33,33,33,33,33])
+ self.assertItemsEqual(rast[0].tolist(), [22, 22, 22, 22, 22, 32, 32, 32, 32, 32])
+ self.assertItemsEqual(rast[5].tolist(), [23, 23, 23, 23, 23, 33, 33, 33, 33, 33])
rast.close()
@@ -74,8 +74,8 @@
[nan, nan, nan, nan, nan, nan, nan, nan]
"""
- self.assertItemsEqual(rast[2].tolist()[2:6], [11.,21.,31.,41.])
- self.assertItemsEqual(rast[5].tolist()[2:6], [14.,24.,34.,44.])
+ self.assertItemsEqual(rast[2].tolist()[2:6], [11., 21., 31., 41.])
+ self.assertItemsEqual(rast[5].tolist()[2:6], [14., 24., 34., 44.])
rast.close()
More information about the grass-commit
mailing list