Repository: thrift
Updated Branches:
  refs/heads/master 69826b21e -> e8c71d8cc


THRIFT-3439 Run make cross using Python3 when available
Client: Test
Patch: Nobuaki Sukegawa

This closes #710


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/2de2700c
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/2de2700c
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/2de2700c

Branch: refs/heads/master
Commit: 2de2700c34bde8d7576da148852c43a32c11e94a
Parents: 69826b2
Author: Nobuaki Sukegawa <[email protected]>
Authored: Sun Nov 22 01:13:48 2015 +0900
Committer: Nobuaki Sukegawa <[email protected]>
Committed: Mon Nov 23 21:24:00 2015 +0900

----------------------------------------------------------------------
 test/crossrunner/compat.py | 21 +++++++++++++++++++++
 test/crossrunner/report.py | 12 ++++--------
 test/crossrunner/run.py    | 13 +++++--------
 test/crossrunner/test.py   | 11 +++--------
 4 files changed, 33 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/2de2700c/test/crossrunner/compat.py
----------------------------------------------------------------------
diff --git a/test/crossrunner/compat.py b/test/crossrunner/compat.py
new file mode 100644
index 0000000..70992f6
--- /dev/null
+++ b/test/crossrunner/compat.py
@@ -0,0 +1,21 @@
+import os
+import sys
+
+if sys.version_info[0] == 2:
+  _ENCODE = sys.getfilesystemencoding()
+
+  def path_join(*args):
+    bin_args = map(lambda a: a.decode(_ENCODE), args)
+    return os.path.join(*bin_args).encode(_ENCODE)
+
+  def str_join(s, l):
+    bin_args = map(lambda a: a.decode(_ENCODE), l)
+    b = s.decode(_ENCODE)
+    return b.join(bin_args).encode(_ENCODE)
+
+else:
+
+  path_join = os.path.join
+
+  def str_join(s, l):
+    return s.join(l)

http://git-wip-us.apache.org/repos/asf/thrift/blob/2de2700c/test/crossrunner/report.py
----------------------------------------------------------------------
diff --git a/test/crossrunner/report.py b/test/crossrunner/report.py
index 6ffc8e2..bcfe181 100644
--- a/test/crossrunner/report.py
+++ b/test/crossrunner/report.py
@@ -28,7 +28,8 @@ import sys
 import time
 import traceback
 
-from crossrunner.test import TestEntry
+from .compat import path_join, str_join
+from .test import TestEntry
 
 LOG_DIR = 'log'
 RESULT_HTML = 'result.html'
@@ -84,7 +85,7 @@ class TestReporter(object):
   @classmethod
   def test_logfile(cls, test_name, prog_kind, dir=None):
     relpath = os.path.join('log', '%s_%s.log' % (test_name, prog_kind))
-    return relpath if not dir else 
os.path.realpath(os.path.join(dir.decode(sys.getfilesystemencoding()), 
relpath.decode(sys.getfilesystemencoding())).encode(sys.getfilesystemencoding()))
    
+    return relpath if not dir else os.path.realpath(path_join(dir, relpath))
 
   def _start(self):
     self._start_time = time.time()
@@ -194,13 +195,8 @@ class ExecReporter(TestReporter):
     self.out.close()
 
   def _print_header(self):
-    tmp = list()
-    joined = ''
-    for item in self._prog.command:
-      tmp.append( item.decode(sys.getfilesystemencoding()))
-    joined = ' '.join(tmp).encode(sys.getfilesystemencoding())    
     self._print_date()
-    self.out.write('Executing: %s\n' % joined)
+    self.out.write('Executing: %s\n' % str_join(' ', self._prog.command))
     self.out.write('Directory: %s\n' % self._prog.workdir)
     self.out.write('config:delay: %s\n' % self._test.delay)
     self.out.write('config:timeout: %s\n' % self._test.timeout)

http://git-wip-us.apache.org/repos/asf/thrift/blob/2de2700c/test/crossrunner/run.py
----------------------------------------------------------------------
diff --git a/test/crossrunner/run.py b/test/crossrunner/run.py
index 8de6ba9..129016c 100644
--- a/test/crossrunner/run.py
+++ b/test/crossrunner/run.py
@@ -31,8 +31,9 @@ import threading
 import time
 import traceback
 
-from crossrunner.test import TestEntry, domain_socket_path
-from crossrunner.report import ExecReporter, SummaryReporter
+from .compat import str_join
+from .test import TestEntry, domain_socket_path
+from .report import ExecReporter, SummaryReporter
 
 RESULT_TIMEOUT = 128
 RESULT_ERROR = 64
@@ -82,16 +83,12 @@ class ExecutionContext(object):
     return args
 
   def start(self, timeout=0):
-    tmp = list()
-    joined = ''
-    for item in self.cmd:
-      tmp.append( item.decode(sys.getfilesystemencoding()))
-    joined = ' '.join(tmp).encode(sys.getfilesystemencoding())    
+    joined = str_join(' ', self.cmd)
     self._log.debug('COMMAND: %s', joined)
     self._log.debug('WORKDIR: %s', self.cwd)
     self._log.debug('LOGFILE: %s', self.report.logpath)
     self.report.begin()
-    self.proc = subprocess.Popen(tmp, **self._popen_args())
+    self.proc = subprocess.Popen(self.cmd, **self._popen_args())
     if timeout > 0:
       self.timer = threading.Timer(timeout, self._expire)
       self.timer.start()

http://git-wip-us.apache.org/repos/asf/thrift/blob/2de2700c/test/crossrunner/test.py
----------------------------------------------------------------------
diff --git a/test/crossrunner/test.py b/test/crossrunner/test.py
index 6a30b3e..63219e1 100644
--- a/test/crossrunner/test.py
+++ b/test/crossrunner/test.py
@@ -21,6 +21,7 @@ import copy
 import multiprocessing
 import os
 import sys
+from .compat import path_join
 
 from crossrunner.util import merge_dict
 
@@ -51,9 +52,7 @@ class TestProgram(object):
   def _fix_cmd_path(self, cmd):
     # if the arg is a file in the current directory, make it path
     def abs_if_exists(arg):
-      p = self.workdir.decode(sys.getfilesystemencoding())
-      p = os.path.join(p, arg.decode(sys.getfilesystemencoding()))
-      p = p.encode(sys.getfilesystemencoding())
+      p = path_join(self.workdir, arg)
       return p if os.path.exists(p) else arg
 
     if cmd[0] == 'python':
@@ -115,11 +114,7 @@ class TestEntry(object):
     if os.path.isabs(path):
       path = os.path.realpath(path)
     else:
-      tmp  = self.testdir.decode(sys.getfilesystemencoding())
-      path = path.decode(sys.getfilesystemencoding())
-      path = os.path.join(tmp, path)
-      path = path.encode(sys.getfilesystemencoding())
-      path = os.path.realpath(path)
+      path = os.path.realpath(path_join(self.testdir, path))
     config.update({key: path})
     return config
 

Reply via email to