[GRASS-SVN] r74032 - in grass/trunk/lib/python: ctypes/ctypesgencore/parser gunittest

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jan 27 20:53:12 PST 2019


Author: annakrat
Date: 2019-01-27 20:53:12 -0800 (Sun, 27 Jan 2019)
New Revision: 74032

Modified:
   grass/trunk/lib/python/ctypes/ctypesgencore/parser/lextab.py
   grass/trunk/lib/python/gunittest/invoker.py
   grass/trunk/lib/python/gunittest/multirunner.py
Log:
gunittest: first part of fixes for #3737

Modified: grass/trunk/lib/python/ctypes/ctypesgencore/parser/lextab.py
===================================================================
--- grass/trunk/lib/python/ctypes/ctypesgencore/parser/lextab.py	2019-01-27 20:56:28 UTC (rev 74031)
+++ grass/trunk/lib/python/ctypes/ctypesgencore/parser/lextab.py	2019-01-28 04:53:12 UTC (rev 74032)
@@ -1,8 +1,8 @@
 # lextab.py. This file automatically created by PLY (version 2.2). Don't edit!
-_lextokens    = {'PP_END_DEFINE': None, 'DIV_ASSIGN': None, 'AND_OP': None, 'PERIOD': None, 'PTR_OP': None, 'PP_MACRO_PARAM': None, 'OTHER': None, 'IDENTIFIER': None, 'PP_STRINGIFY': None, 'XOR_ASSIGN': None, 'PP_DEFINE_NAME': None, 'ELLIPSIS': None, 'INC_OP': None, 'GE_OP': None, 'LEFT_ASSIGN': None, 'MUL_ASSIGN': None, 'RIGHT_ASSIGN': None, 'SUB_ASSIGN': None, 'LPAREN': None, 'PP_IDENTIFIER_PASTE': None, 'PP_DEFINE': None, 'OR_ASSIGN': None, 'ADD_ASSIGN': None, 'HEADER_NAME': None, 'LE_OP': None, 'LEFT_OP': None, 'PP_NUMBER': None, 'DEC_OP': None, 'RIGHT_OP': None, 'MOD_ASSIGN': None, 'STRING_LITERAL': None, 'EQ_OP': None, 'OR_OP': None, 'AND_ASSIGN': None, 'CHARACTER_CONSTANT': None, 'PP_DEFINE_MACRO_NAME': None, 'NE_OP': None, 'NEWLINE': None}
+_lextokens    = {'LE_OP': None, 'DEC_OP': None, 'DIV_ASSIGN': None, 'XOR_ASSIGN': None, 'CHARACTER_CONSTANT': None, 'PP_IDENTIFIER_PASTE': None, 'PP_MACRO_PARAM': None, 'HEADER_NAME': None, 'STRING_LITERAL': None, 'OTHER': None, 'RIGHT_ASSIGN': None, 'PERIOD': None, 'PP_DEFINE': None, 'LEFT_ASSIGN': None, 'AND_OP': None, 'PP_NUMBER': None, 'PP_DEFINE_MACRO_NAME': None, 'ADD_ASSIGN': None, 'PP_END_DEFINE': None, 'EQ_OP': None, 'OR_OP': None, 'OR_ASSIGN': None, 'MOD_ASSIGN': None, 'ELLIPSIS': None, 'AND_ASSIGN': None, 'LEFT_OP': None, 'NE_OP': None, 'RIGHT_OP': None, 'GE_OP': None, 'NEWLINE': None, 'INC_OP': None, 'SUB_ASSIGN': None, 'PTR_OP': None, 'LPAREN': None, 'PP_STRINGIFY': None, 'MUL_ASSIGN': None, 'IDENTIFIER': None, 'PP_DEFINE_NAME': None}
 _lexreflags   = 0
 _lexliterals  = ''
 _lexstateinfo = {'DEFINE': 'exclusive', 'INITIAL': 'inclusive'}
-_lexstatere   = {'DEFINE': [('(?P<t_ANY_directive>\\#\\s+(\\d+)\\s+"([^"]+)"[ \\d]*\\n)|(?P<t_ANY_punctuator>(\\.\\.\\.|\\|\\||\\+\\+|\\*=|\\|=|\\+=|>>=|\\^=|<<=|\\)|-=|<%|<<|%>|\\+|>>|<=|/=|->|!=|&&|\\*|\\[|\\?|--|>=|\\.|:>|&=|==|<:|%=|\\||\\^|/|:|{|~|,|>|-|%|}|;|!|=|&|]|<))', [None, ('t_ANY_directive', 'ANY_directive'), None, None, ('t_ANY_punctuator', 'ANY_punctuator')]), ('(?P<t_DEFINE_identifier>[a-zA-Z_]([a-zA-Z_]|[0-9])*)', [None, ('t_DEFINE_identifier', 'DEFINE_identifier')]), ('(?P<t_ANY_float>(?P<p1>[0-9]+)?(?P<dp>[.]?)(?P<p2>(?(p1)[0-9]*|[0-9]+))(?P<exp>(?:[Ee][+-]?[0-9]+)?)(?P<suf>([FfLl]|d[dfl]|D[DFL]|[fFdD][0-9]+x?)?)(?!\\w))', [None, ('t_ANY_float', 'ANY_float'), None, None, None, None, None]), ('(?P<t_ANY_int>(?P<p1>(?:0x[a-fA-F0-9]+)|(?:[0-9]+))(?P<suf>[uUlL]*))', [None, ('t_ANY_int', 'ANY_int'), None, None]), ('(?P<t_ANY_character_constant>L?\'(\\\\.|[^\\\\\'])+\')|(?P<t_ANY_string_literal>L?"(\\\\.|[^\\\\"])*")|(?P<t_ANY_lparen>\\()|(?P<t_DEFINE_newline>\\n)|(?P<t
 _DEFINE_pp_param_op>(\\#\\#)|(\\#))', [None, ('t_ANY_character_constant', 'ANY_character_constant'), None, ('t_ANY_string_literal', 'ANY_string_literal'), None, ('t_ANY_lparen', 'ANY_lparen'), ('t_DEFINE_newline', 'DEFINE_newline'), ('t_DEFINE_pp_param_op', 'DEFINE_pp_param_op')])], 'INITIAL': [('(?P<t_ANY_directive>\\#\\s+(\\d+)\\s+"([^"]+)"[ \\d]*\\n)|(?P<t_ANY_punctuator>(\\.\\.\\.|\\|\\||\\+\\+|\\*=|\\|=|\\+=|>>=|\\^=|<<=|\\)|-=|<%|<<|%>|\\+|>>|<=|/=|->|!=|&&|\\*|\\[|\\?|--|>=|\\.|:>|&=|==|<:|%=|\\||\\^|/|:|{|~|,|>|-|%|}|;|!|=|&|]|<))', [None, ('t_ANY_directive', 'ANY_directive'), None, None, ('t_ANY_punctuator', 'ANY_punctuator')]), ('(?P<t_INITIAL_identifier>[a-zA-Z_]([a-zA-Z_]|[0-9])*)', [None, ('t_INITIAL_identifier', 'INITIAL_identifier')]), ('(?P<t_ANY_float>(?P<p1>[0-9]+)?(?P<dp>[.]?)(?P<p2>(?(p1)[0-9]*|[0-9]+))(?P<exp>(?:[Ee][+-]?[0-9]+)?)(?P<suf>([FfLl]|d[dfl]|D[DFL]|[fFdD][0-9]+x?)?)(?!\\w))', [None, ('t_ANY_float', 'ANY_float'), None, None, None, None, None]), ('(?P<t
 _ANY_int>(?P<p1>(?:0x[a-fA-F0-9]+)|(?:[0-9]+))(?P<suf>[uUlL]*))', [None, ('t_ANY_int', 'ANY_int'), None, None]), ('(?P<t_ANY_character_constant>L?\'(\\\\.|[^\\\\\'])+\')|(?P<t_ANY_string_literal>L?"(\\\\.|[^\\\\"])*")|(?P<t_ANY_lparen>\\()|(?P<t_INITIAL_newline>\\n)|(?P<t_INITIAL_pp_define>\\#define)', [None, ('t_ANY_character_constant', 'ANY_character_constant'), None, ('t_ANY_string_literal', 'ANY_string_literal'), None, ('t_ANY_lparen', 'ANY_lparen'), ('t_INITIAL_newline', 'INITIAL_newline'), ('t_INITIAL_pp_define', 'INITIAL_pp_define')])]}
+_lexstatere   = {'DEFINE': [('(?P<t_ANY_directive>\\#\\s+(\\d+)\\s+"([^"]+)"[ \\d]*\\n)|(?P<t_ANY_punctuator>(\\.\\.\\.|\\+\\+|\\|\\||\\|=|\\*=|\\^=|>>=|\\+=|<<=|/=|:>|<:|->|&&|\\+|<=|!=|\\.|\\?|\\[|\\*|&=|\\^|\\)|--|==|>=|%=|>>|<<|%>|-=|\\||<%|~|<|;|/|!|&|}|>|,|:|]|{|%|=|-))', [None, ('t_ANY_directive', 'ANY_directive'), None, None, ('t_ANY_punctuator', 'ANY_punctuator')]), ('(?P<t_DEFINE_identifier>[a-zA-Z_]([a-zA-Z_]|[0-9])*)', [None, ('t_DEFINE_identifier', 'DEFINE_identifier')]), ('(?P<t_ANY_float>(?P<p1>[0-9]+)?(?P<dp>[.]?)(?P<p2>(?(p1)[0-9]*|[0-9]+))(?P<exp>(?:[Ee][+-]?[0-9]+)?)(?P<suf>([FfLl]|d[dfl]|D[DFL]|[fFdD][0-9]+x?)?)(?!\\w))', [None, ('t_ANY_float', 'ANY_float'), None, None, None, None, None]), ('(?P<t_ANY_int>(?P<p1>(?:0x[a-fA-F0-9]+)|(?:[0-9]+))(?P<suf>[uUlL]*))', [None, ('t_ANY_int', 'ANY_int'), None, None]), ('(?P<t_ANY_character_constant>L?\'(\\\\.|[^\\\\\'])+\')|(?P<t_ANY_string_literal>L?"(\\\\.|[^\\\\"])*")|(?P<t_ANY_lparen>\\()|(?P<t_DEFINE_newline>\\n)|(?P<t
 _DEFINE_pp_param_op>(\\#\\#)|(\\#))', [None, ('t_ANY_character_constant', 'ANY_character_constant'), None, ('t_ANY_string_literal', 'ANY_string_literal'), None, ('t_ANY_lparen', 'ANY_lparen'), ('t_DEFINE_newline', 'DEFINE_newline'), ('t_DEFINE_pp_param_op', 'DEFINE_pp_param_op')])], 'INITIAL': [('(?P<t_ANY_directive>\\#\\s+(\\d+)\\s+"([^"]+)"[ \\d]*\\n)|(?P<t_ANY_punctuator>(\\.\\.\\.|\\+\\+|\\|\\||\\|=|\\*=|\\^=|>>=|\\+=|<<=|/=|:>|<:|->|&&|\\+|<=|!=|\\.|\\?|\\[|\\*|&=|\\^|\\)|--|==|>=|%=|>>|<<|%>|-=|\\||<%|~|<|;|/|!|&|}|>|,|:|]|{|%|=|-))', [None, ('t_ANY_directive', 'ANY_directive'), None, None, ('t_ANY_punctuator', 'ANY_punctuator')]), ('(?P<t_INITIAL_identifier>[a-zA-Z_]([a-zA-Z_]|[0-9])*)', [None, ('t_INITIAL_identifier', 'INITIAL_identifier')]), ('(?P<t_ANY_float>(?P<p1>[0-9]+)?(?P<dp>[.]?)(?P<p2>(?(p1)[0-9]*|[0-9]+))(?P<exp>(?:[Ee][+-]?[0-9]+)?)(?P<suf>([FfLl]|d[dfl]|D[DFL]|[fFdD][0-9]+x?)?)(?!\\w))', [None, ('t_ANY_float', 'ANY_float'), None, None, None, None, None]), ('(?P<t
 _ANY_int>(?P<p1>(?:0x[a-fA-F0-9]+)|(?:[0-9]+))(?P<suf>[uUlL]*))', [None, ('t_ANY_int', 'ANY_int'), None, None]), ('(?P<t_ANY_character_constant>L?\'(\\\\.|[^\\\\\'])+\')|(?P<t_ANY_string_literal>L?"(\\\\.|[^\\\\"])*")|(?P<t_ANY_lparen>\\()|(?P<t_INITIAL_newline>\\n)|(?P<t_INITIAL_pp_define>\\#define)', [None, ('t_ANY_character_constant', 'ANY_character_constant'), None, ('t_ANY_string_literal', 'ANY_string_literal'), None, ('t_ANY_lparen', 'ANY_lparen'), ('t_INITIAL_newline', 'INITIAL_newline'), ('t_INITIAL_pp_define', 'INITIAL_pp_define')])]}
 _lexstateignore = {'DEFINE': ' \t\x0b\x0c\r', 'INITIAL': ' \t\x0b\x0c\r'}
 _lexstateerrorf = {'DEFINE': 't_DEFINE_error', 'INITIAL': 't_INITIAL_error'}

Modified: grass/trunk/lib/python/gunittest/invoker.py
===================================================================
--- grass/trunk/lib/python/gunittest/invoker.py	2019-01-27 20:56:28 UTC (rev 74031)
+++ grass/trunk/lib/python/gunittest/invoker.py	2019-01-28 04:53:12 UTC (rev 74032)
@@ -161,9 +161,11 @@
             # ignoring shebang line to use current Python
             # and also pass parameters to it
             # add also '-Qwarn'?
-            p = subprocess.Popen([sys.executable, '-tt', '-3',
-                                  module.abs_file_path],
-                                 cwd=cwd, env=env,
+            if sys.version_info.major >= 3:
+                args = [sys.executable, '-tt', module.abs_file_path]
+            else:
+                args = [sys.executable, '-tt', '-3', module.abs_file_path]
+            p = subprocess.Popen(args, cwd=cwd, env=env,
                                  stdout=stdout, stderr=stderr)
         elif module.file_type == 'sh':
             # ignoring shebang line to pass parameters to shell

Modified: grass/trunk/lib/python/gunittest/multirunner.py
===================================================================
--- grass/trunk/lib/python/gunittest/multirunner.py	2019-01-27 20:56:28 UTC (rev 74031)
+++ grass/trunk/lib/python/gunittest/multirunner.py	2019-01-28 04:53:12 UTC (rev 74032)
@@ -16,8 +16,51 @@
 import argparse
 import itertools
 import subprocess
+import locale
 
+try:
+    from itertools import izip as zip
+except ImportError:  # will be 3.x series
+    pass
 
+if sys.version_info.major >= 3:
+    unicode = str
+
+
+def _get_encoding():
+    encoding = locale.getdefaultlocale()[1]
+    if not encoding:
+        encoding = 'UTF-8'
+    return encoding
+
+
+def decode(bytes_, encoding=None):
+    if isinstance(bytes_, bytes):
+        return bytes_.decode(_get_encoding())
+    else:
+        return bytes_
+
+
+def encode(string, encoding=None):
+    if isinstance(string, unicode):
+        return string.encode(_get_encoding())
+    else:
+        return string
+
+
+def text_to_string(text):
+    """Convert text to str. Useful when passing text into environments,
+       in Python 2 it needs to be bytes on Windows, in Python 3 in needs unicode.
+    """
+    if sys.version[0] == '2':
+        # Python 2
+        return encode(text)
+    else:
+        # Python 3
+        return decode(text)
+
+
+
 def main():
     parser = argparse.ArgumentParser(
         description='Run tests with new')
@@ -70,10 +113,10 @@
     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 = decode(out.strip())
 
     # set GISBASE environment variable
-    os.environ['GISBASE'] = gisbase
+    os.environ['GISBASE'] = text_to_string(gisbase)
     # define GRASS Python environment
     grass_python_dir = os.path.join(gisbase, "etc", "python")
     sys.path.append(grass_python_dir)
@@ -82,7 +125,7 @@
     # define GRASS DATABASE
     
     # Set GISDBASE environment variable
-    os.environ['GISDBASE'] = gisdb
+    os.environ['GISDBASE'] = text_to_string(gisdb)
 
     # import GRASS Python package for initialization
     import grass.script.setup as gsetup
@@ -95,7 +138,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



More information about the grass-commit mailing list