[GRASS-dev] [GRASS GIS] #3783: Python 3: ./raster/r.patch/testsuite/test_rpatch_artificial.py is broken

GRASS GIS trac at osgeo.org
Wed Mar 6 23:40:30 PST 2019


#3783: Python 3: ./raster/r.patch/testsuite/test_rpatch_artificial.py is broken
-------------------------+-------------------------
 Reporter:  pmav99       |      Owner:  grass-dev@…
     Type:  defect       |     Status:  new
 Priority:  normal       |  Milestone:
Component:  Tests        |    Version:  svn-trunk
 Keywords:               |        CPU:  Unspecified
 Platform:  Unspecified  |
-------------------------+-------------------------
 This is the traceback:
 {{{
 ======================================================================
 ERROR: test_patching_cell (__main__.TestSmallDataNoOverlap)
 Test patching two neighboring CELL raster maps
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "raster/r.patch/testsuite/test_rpatch_artificial.py", line 162, in
 test_patching_cell
     self.cell_patched_ref, precision=0)
   File "etc/python/grass/gunittest/case.py", line 767, in
 assertRastersNoDifference
     'assertRastersNoDifference')
   File "etc/python/grass/gunittest/case.py", line 681, in
 _compute_difference_raster
     s=second))
   File "etc/python/grass/gunittest/gmodules.py", line 128, in call_module
     output, errors = process.communicate(input=stdin)
   File "/usr/lib/python3.7/subprocess.py", line 939, in communicate
     stdout, stderr = self._communicate(input, endtime, timeout)
   File "/usr/lib/python3.7/subprocess.py", line 1666, in _communicate
     input_view = memoryview(self._input)
 TypeError: memoryview: a bytes-like object is required, not 'str'
 }}}

 This is the the suggested fix (git diff):
 {{{
 diff --git a/lib/python/gunittest/case.py b/lib/python/gunittest/case.py
 index cf995e4b2..d94a72b69 100644
 --- a/lib/python/gunittest/case.py
 +++ b/lib/python/gunittest/case.py
 @@ -675,10 +675,12 @@ class TestCase(unittest.TestCase):
          """
          diff = self._get_unique_name('compute_difference_raster_' +
 name_part
                                       + '_' + first + '_minus_' + second)
 -        call_module('r.mapcalc',
 -                    stdin='"{d}" = "{f}" - "{s}"'.format(d=diff,
 -                                                         f=first,
 -                                                         s=second))
 +        expression = '"{d}" = "{f}" - "{s}"'.format(
 +            d=diff,
 +            f=first,
 +            s=second
 +        )
 +        call_module('r.mapcalc', stdin=expression.encode("utf-8"))
          return diff

      # TODO: name of map generation is repeted three times
 }}}

 Works on both Python 2 and Python 3

-- 
Ticket URL: <https://trac.osgeo.org/grass/ticket/3783>
GRASS GIS <https://grass.osgeo.org>



More information about the grass-dev mailing list