[GRASS-dev] [GRASS GIS] #3737: Testsuite gunittest/multirunner.py: TypeError: str expected, not bytes
GRASS GIS
trac at osgeo.org
Sat Jan 26 07:52:54 PST 2019
#3737: Testsuite gunittest/multirunner.py: TypeError: str expected, not bytes
--------------------------+--------------------------------
Reporter: AnikaBettge | Owner: grass-dev@…
Type: defect | Status: new
Priority: normal | Milestone: 7.8.0
Component: Python | Version: svn-trunk
Resolution: | Keywords: Python3, testsuite
CPU: x86-64 | Platform: Linux
--------------------------+--------------------------------
Comment (by pmav99):
In order to make `multirunner.py` run on Python 3 you need to apply
something like this.
{{{
@@ -64,13 +64,13 @@
# we assume that GRASS GIS' start script is available and in the PATH
# the shell=True is here because of MS Windows? (code taken from
wiki)
startcmd = grass7bin + ' --config path'
p = subprocess.Popen(startcmd, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
if p.returncode != 0:
print("ERROR: Cannot find GRASS GIS 7 start script (%s):\n%s" %
(startcmd, err), file=sys.stderr)
return 1
- gisbase = out.strip('\n')
+ gisbase = out.strip().decode("utf-8")
# set GISBASE environment variable
os.environ['GISBASE'] = gisbase
@@ -95,7 +95,7 @@
gsetup.init(gisbase, gisdb, location, mapset)
reports = []
- for location, location_type in itertools.izip(locations,
locations_types):
+ for location, location_type in zip(locations, locations_types):
# here it is quite a good place to parallelize
# including also type to make it unique and preserve it for sure
report = 'report_for_' + location + '_' + location_type
}}}
Specifying `\n` is probably redundant. `str.strip()` already strips that.
More specifically it strips all the characters contained in
`string.whitespace`.
Other than that, in python3 subprocess output is bytes. The
`.decode("utf-8")` call is converting the bytes to python3 strings which
are the equivalent of unicode strings in python2.
Note: the patch should work with python2 too, but I have not tested it.
--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3737#comment:1>
GRASS GIS <https://grass.osgeo.org>
More information about the grass-dev
mailing list