Opened 5 years ago

Closed 5 years ago

#3783 closed defect (fixed)

Python 3: ./raster/r.patch/testsuite/test_rpatch_artificial.py is broken

Reported by: pmav99 Owned by: grass-dev@…
Priority: normal Milestone:
Component: Tests Version: svn-trunk
Keywords: Cc:
CPU: Unspecified Platform: Unspecified

Description (last modified by pmav99)

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

Change History (3)

comment:1 by pmav99, 5 years ago

Description: modified (diff)

comment:2 by neteler, 5 years ago

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)

comment:3 by neteler, 5 years ago

Resolution: fixed
Status: newclosed

In 74310:

testsuite: Python3 fix for test_rpatch_artificial.py (fixes #3783) (contributed by pmav99)

Note: See TracTickets for help on using tickets.