Pārlūkot izejas kodu

make multirunner pass with Py 2 and 3

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@74416 15284696-431f-4ddb-bdfa-cd5b030d7da7
Stefan Blumentrath 6 gadi atpakaļ
vecāks
revīzija
59981b5271

+ 1 - 1
lib/python/gunittest/case.py

@@ -1105,7 +1105,7 @@ class TestCase(unittest.TestCase):
             # here exception raised by run() with finish_=True would be
             # almost enough but we want some additional info to be included
             # in the test report
-            errors = module.outputs.stderr
+            errors = decode(module.outputs.stderr)
             # provide diagnostic at least in English locale
             # TODO: standardized error code would be handy here
             import re

+ 5 - 3
lib/python/gunittest/checkers.py

@@ -14,6 +14,8 @@ import sys
 import re
 import doctest
 
+from grass.script.utils import decode, encode, _get_encoding
+
 try:
     from grass.script.core import KeyValue
 except (ImportError, AttributeError):
@@ -593,7 +595,7 @@ def text_file_md5(filename, exclude_lines=None, exclude_re=None,
         regexp = re.compile(exclude_re)
     if prepend_lines:
         for line in prepend_lines:
-            hasher.update(line)
+            hasher.update(line if sys.version_info[0] == 2 else encode(line))
     with open(filename, 'r') as f:
         for line in f:
             # replace platform newlines by standard newline
@@ -603,10 +605,10 @@ def text_file_md5(filename, exclude_lines=None, exclude_re=None,
                 continue
             if exclude_re and regexp.match(line):
                 continue
-            hasher.update(line.encode("utf-8"))
+            hasher.update(line if sys.version_info[0] == 2 else encode(line))
     if append_lines:
         for line in append_lines:
-            hasher.update(line)
+            hasher.update(line if sys.version_info[0] == 2 else encode(line))
     return hasher.hexdigest()
 
 

+ 3 - 3
lib/python/gunittest/gmodules.py

@@ -11,7 +11,7 @@ for details.
 
 import subprocess
 from grass.script.core import start_command
-from grass.script.utils import decode
+from grass.script.utils import encode, decode
 from grass.exceptions import CalledModuleError
 from grass.pygrass.modules import Module
 
@@ -126,8 +126,8 @@ def call_module(module, stdin=None,
     # for no stdout, output is None which is out interface
     # for stderr=STDOUT or no stderr, errors is None
     # which is fine for CalledModuleError
-    output, errors = process.communicate(input=stdin)
+    output, errors = process.communicate(input=encode(decode(stdin)) if stdin else None)
     returncode = process.poll()
     if returncode:
         raise CalledModuleError(returncode, module, kwargs, errors)
-    return output
+    return decode(output) if output else None

+ 8 - 2
lib/python/gunittest/invoker.py

@@ -212,11 +212,17 @@ class GrassTestFilesInvoker(object):
             except:
                 idx += 1
                 pass
-                    
+
         with open(stdout_path, 'w') as stdout_file:
             stdout_file.write(stdout)
         with open(stderr_path, 'w') as stderr_file:
-            stderr_file.write(stderr)
+            if type(stderr) == 'bytes':
+                stderr_file.write(decode(stderr))
+            else:
+                if isinstance(stderr, str):
+                    stderr_file.write(stderr)
+                else:
+                    stderr_file.write(stderr.encode('utf8'))
         self._file_anonymizer.anonymize([stdout_path, stderr_path])
 
         test_summary = update_keyval_file(