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

#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&gt;
GRASS GIS <https://grass.osgeo.org>

#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
Resolution: | Keywords:
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------
Description changed by pmav99:

Old description:

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

New description:

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 = '"{diff}" = "{first}" - "{second}"'.format(
+ diff=diff,
+ first=first,
+ second=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#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>

#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
Resolution: | Keywords:
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by neteler):

It is difficult to extract patches from the text description of trac.
Would you mind to attach them to the ticket as attachments?

(yes, I am also looking fwd to migrate to git)

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3783#comment:2&gt;
GRASS GIS <https://grass.osgeo.org>

#3783: Python 3: ./raster/r.patch/testsuite/test_rpatch_artificial.py is broken
--------------------------+-------------------------
  Reporter: pmav99 | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone:
Component: Tests | Version: svn-trunk
Resolution: fixed | Keywords:
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------
Changes (by neteler):

* status: new => closed
* resolution: => fixed

Comment:

In [changeset:"74310" 74310]:
{{{
#!CommitTicketReference repository="" revision="74310"
testsuite: Python3 fix for test_rpatch_artificial.py (fixes #3783)
(contributed by pmav99)
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3783#comment:3&gt;
GRASS GIS <https://grass.osgeo.org>