|
@@ -29,8 +29,8 @@ from .checkers import (check_text_ellipsis,
|
|
|
from .utils import safe_repr
|
|
|
from .gutils import is_map_in_mapset
|
|
|
|
|
|
-
|
|
|
-if sys.version_info[0] == 2:
|
|
|
+pyversion = sys.version_info[0]
|
|
|
+if pyversion == 2:
|
|
|
from StringIO import StringIO
|
|
|
else:
|
|
|
from io import StringIO
|
|
@@ -169,6 +169,14 @@ class TestCase(unittest.TestCase):
|
|
|
If you need to test the actual newline characters, use the standard
|
|
|
string comparison and functions such as ``find()``.
|
|
|
"""
|
|
|
+ # SimpleModule delivers bytes for stderr and stdout
|
|
|
+ # Instead of decoding stdout and stderr in every test, decoding
|
|
|
+ # is done here
|
|
|
+ if pyversion == 3:
|
|
|
+ if isinstance(first, bytes):
|
|
|
+ first = decode(first)
|
|
|
+ if isinstance(second, bytes):
|
|
|
+ second = decode(second)
|
|
|
if os.linesep != '\n':
|
|
|
if os.linesep in first:
|
|
|
first = first.replace(os.linesep, '\n')
|
|
@@ -185,6 +193,12 @@ class TestCase(unittest.TestCase):
|
|
|
|
|
|
See :func:`check_text_ellipsis` for details of behavior.
|
|
|
"""
|
|
|
+ # SimpleModule delivers bytes for stderr and stdout
|
|
|
+ # Instead of decoding stdout and stderr in every test, decoding
|
|
|
+ # is done here
|
|
|
+ if pyversion == 3:
|
|
|
+ if isinstance(actual, bytes):
|
|
|
+ actual = decode(actual)
|
|
|
self.assertTrue(isinstance(actual, str), (
|
|
|
'actual argument is not a string'))
|
|
|
self.assertTrue(isinstance(reference, str), (
|
|
@@ -404,6 +418,12 @@ class TestCase(unittest.TestCase):
|
|
|
This function does not test geometry itself just the region of the
|
|
|
vector map and number of features.
|
|
|
"""
|
|
|
+ # SimpleModule delivers bytes for stderr and stdout
|
|
|
+ # Instead of decoding stdout and stderr in every test, decoding
|
|
|
+ # is done here
|
|
|
+ if pyversion == 3:
|
|
|
+ if isinstance(actual, bytes):
|
|
|
+ actual = decode(actual)
|
|
|
module = SimpleModule('v.info', flags='t', map=reference)
|
|
|
self.runModule(module)
|
|
|
ref_topo = text_to_keyvalue(decode(module.outputs.stdout), sep='=')
|
|
@@ -1152,8 +1172,8 @@ class TestCase(unittest.TestCase):
|
|
|
module.run()
|
|
|
self.grass_modules.append(module.name)
|
|
|
except CalledModuleError:
|
|
|
- print(module.outputs.stdout)
|
|
|
- print(module.outputs.stderr)
|
|
|
+ print(decode(module.outputs.stdout))
|
|
|
+ print(decode(module.outputs.stderr))
|
|
|
# TODO: message format
|
|
|
# TODO: stderr?
|
|
|
stdmsg = ('Running <{m.name}> module ended'
|
|
@@ -1165,8 +1185,8 @@ class TestCase(unittest.TestCase):
|
|
|
errors=decode(module.outputs.stderr)
|
|
|
))
|
|
|
self.fail(self._formatMessage(msg, stdmsg))
|
|
|
- print(module.outputs.stdout)
|
|
|
- print(module.outputs.stderr)
|
|
|
+ print(decode(module.outputs.stdout))
|
|
|
+ print(decode(module.outputs.stderr))
|
|
|
# log these to final report
|
|
|
# TODO: always or only if the calling test method failed?
|
|
|
# in any case, this must be done before self.fail()
|
|
@@ -1186,11 +1206,11 @@ class TestCase(unittest.TestCase):
|
|
|
module.run()
|
|
|
self.grass_modules.append(module.name)
|
|
|
except CalledModuleError:
|
|
|
- print(module.outputs.stdout)
|
|
|
- print(module.outputs.stderr)
|
|
|
+ print(decode(module.outputs.stdout))
|
|
|
+ print(decode(module.outputs.stderr))
|
|
|
else:
|
|
|
- print(module.outputs.stdout)
|
|
|
- print(module.outputs.stderr)
|
|
|
+ print(decode(module.outputs.stdout))
|
|
|
+ print(decode(module.outputs.stderr))
|
|
|
stdmsg = ('Running <%s> ended with zero (successful) return code'
|
|
|
' when expecting module to fail' % module.get_python())
|
|
|
self.fail(self._formatMessage(msg, stdmsg))
|