[GRASS-SVN] r74416 - grass/trunk/lib/python/gunittest

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Apr 24 04:34:05 PDT 2019


Author: sbl
Date: 2019-04-24 04:34:05 -0700 (Wed, 24 Apr 2019)
New Revision: 74416

Modified:
   grass/trunk/lib/python/gunittest/case.py
   grass/trunk/lib/python/gunittest/checkers.py
   grass/trunk/lib/python/gunittest/gmodules.py
   grass/trunk/lib/python/gunittest/invoker.py
Log:
make multirunner pass with Py 2 and 3

Modified: grass/trunk/lib/python/gunittest/case.py
===================================================================
--- grass/trunk/lib/python/gunittest/case.py	2019-04-22 15:58:00 UTC (rev 74415)
+++ grass/trunk/lib/python/gunittest/case.py	2019-04-24 11:34:05 UTC (rev 74416)
@@ -1105,7 +1105,7 @@
             # 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

Modified: grass/trunk/lib/python/gunittest/checkers.py
===================================================================
--- grass/trunk/lib/python/gunittest/checkers.py	2019-04-22 15:58:00 UTC (rev 74415)
+++ grass/trunk/lib/python/gunittest/checkers.py	2019-04-24 11:34:05 UTC (rev 74416)
@@ -14,6 +14,8 @@
 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 @@
         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 @@
                 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()
 
 

Modified: grass/trunk/lib/python/gunittest/gmodules.py
===================================================================
--- grass/trunk/lib/python/gunittest/gmodules.py	2019-04-22 15:58:00 UTC (rev 74415)
+++ grass/trunk/lib/python/gunittest/gmodules.py	2019-04-24 11:34:05 UTC (rev 74416)
@@ -11,7 +11,7 @@
 
 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 @@
     # 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

Modified: grass/trunk/lib/python/gunittest/invoker.py
===================================================================
--- grass/trunk/lib/python/gunittest/invoker.py	2019-04-22 15:58:00 UTC (rev 74415)
+++ grass/trunk/lib/python/gunittest/invoker.py	2019-04-24 11:34:05 UTC (rev 74416)
@@ -212,11 +212,17 @@
             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(



More information about the grass-commit mailing list