You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ns...@apache.org on 2015/11/23 15:17:54 UTC

[1/3] thrift git commit: THRIFT-3439 Run make cross using Python3 when available Client: Test Patch: Nobuaki Sukegawa

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 <ns...@apache.org>
Authored: Sun Nov 22 01:13:48 2015 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
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
 


[3/3] thrift git commit: THRIFT-3442 Run CMake tests on Appveyor Client: Test Patch: Nobuaki Sukegawa

Posted by ns...@apache.org.
THRIFT-3442 Run CMake tests on Appveyor
Client: Test
Patch: Nobuaki Sukegawa

This closes #713


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

Branch: refs/heads/master
Commit: e8c71d8cc9d0138cd7f48616ce64b50ae0a1b932
Parents: cacce2f
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Mon Nov 23 19:51:37 2015 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Mon Nov 23 22:45:25 2015 +0900

----------------------------------------------------------------------
 appveyor.yml                    | 60 ++++++++++++++++++++++++++----------
 build/cmake/DefineOptions.cmake |  4 +++
 build/cmake/FindLibevent.cmake  |  6 ++--
 lib/cpp/test/CMakeLists.txt     | 24 ++-------------
 lib/hs/CMakeLists.txt           |  9 +++++-
 test/hs/CMakeLists.txt          | 11 +++++--
 test/hs/TestClient.hs           |  1 -
 test/hs/TestServer.hs           |  4 +--
 8 files changed, 73 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/e8c71d8c/appveyor.yml
----------------------------------------------------------------------
diff --git a/appveyor.yml b/appveyor.yml
index 0c5bfdf..13afbff 100755
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -18,36 +18,62 @@
 
 # build Apache Thrift on AppVeyor - https://ci.appveyor.com
 
+shallow_clone: true
+clone_depth: 10
+
 version: '{build}'
 os:
-- Windows Server 2012 R2
-- Visual Studio 2014 CTP4
-- Visual Studio 2015 CTP
-- Visual Studio 2015 CTP 6
-- Visual Studio 2015 Preview
+# - Windows Server 2012 R2
+- Visual Studio 2015
 
 environment:
   BOOST_ROOT: c:\Libraries\boost
   BOOST_LIBRARYDIR: c:\Libraries\boost\stage\lib
 
 install:
-- cinst cmake
-- cinst nsis
-- cinst ant
+- '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64'
+  # Zlib
+- appveyor DownloadFile https://github.com/madler/zlib/archive/v1.2.8.tar.gz
+- 7z x v1.2.8.tar.gz -so | 7z x -si -ttar
+- cd zlib-1.2.8
+- cmake -G "Visual Studio 14 2015 Win64" .
+- cmake --build . --config release
+- cd ..
+  # OpenSSL
+- appveyor DownloadFile https://slproweb.com/download/Win64OpenSSL-1_0_2d.exe
+- ps: Start-Process Win64OpenSSL-1_0_2d.exe -ArgumentList "/silent /verysilent /sp- /suppressmsgboxes" -Wait
+  # Libevent
+- appveyor DownloadFile https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz
+- 7z x libevent-2.0.22-stable.tar.gz -so | 7z x -si -ttar
+- cd libevent-2.0.22-stable
+- nmake -f Makefile.nmake
+- mkdir lib
+- move *.lib lib\
+- move WIN32-Code\event2\* include\event2\
+- move *.h include\
+- cd ..
 - cinst winflexbison
+- cinst nsis
+# TODO: Enable Java build
+# - cinst ant -ignoreDependencies
+# TODO: Enable Haskell build
+# - cinst HaskellPlatform -version 2014.2.0.0
+
 
 build_script:
-- set PATH=C:\ProgramData\chocolatey\bin;C:\tools\apache-ant-1.9.4\bin;%PATH%
-- mv C:\ProgramData\chocolatey\bin\win_bison.exe C:\ProgramData\chocolatey\bin\bison.exe
-- mv C:\ProgramData\chocolatey\bin\win_flex.exe C:\ProgramData\chocolatey\bin\flex.exe
-- set JAVA_HOME=C:\Program Files\Java\jdk1.7.0
-- set PATH=%JAVA_HOME%\bin;%PATH%
+# - set PATH=C:\ProgramData\chocolatey\bin;C:\tools\apache-ant-1.9.4\bin;%PATH%
+# - set JAVA_HOME=C:\Program Files\Java\jdk1.7.0
+# - set PATH=%JAVA_HOME%\bin;%PATH%
+# - set PATH=%PATH%;C:\Program Files (x86)\Haskell Platform\2014.2.0.0\bin
+# - set PATH=%PATH%;C:\Program Files (x86)\Haskell Platform\2014.2.0.0\lib\extralibs\bin
+- set PATH=C:\Python27-x64;%PATH%
 - mkdir cmake-build
 - cd cmake-build
-- cmake -DBUILD_TESTING=OFF ..
-- cmake --build .
+- cmake -G "Visual Studio 14 2015 Win64" -DWITH_JAVA=OFF -DWITH_SHARED_LIB=OFF -DLIBEVENT_ROOT=%APPVEYOR_BUILD_FOLDER%\libevent-2.0.22-stable -DZLIB_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.8 -DZLIB_LIBRARY=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.8\release\zlibstatic.lib -DBOOST_ROOT="%BOOST_ROOT% -DBOOST_LIBRARYDIR="%BOOST_LIBRARYDIR% ..
+# - cmake --build .
 - cmake --build . --config Release
-- cpack
+# TODO: Fix cpack
+# - cpack
+- ctest -C Release -VV -E "(concurrency_test|processor_test|python_test$)"
 
-#TODO enable testing
 #TODO make it perfect ;-r

http://git-wip-us.apache.org/repos/asf/thrift/blob/e8c71d8c/build/cmake/DefineOptions.cmake
----------------------------------------------------------------------
diff --git a/build/cmake/DefineOptions.cmake b/build/cmake/DefineOptions.cmake
index 8f7659e..4fb086c 100644
--- a/build/cmake/DefineOptions.cmake
+++ b/build/cmake/DefineOptions.cmake
@@ -49,6 +49,10 @@ CMAKE_DEPENDENT_OPTION(BUILD_CPP "Build C++ library" ON
 # but in future other libraries might reuse them.
 # So they are not dependent on WITH_CPP but setting them without WITH_CPP currently
 # has no effect.
+if(ZLIB_LIBRARY)
+    # FindZLIB.cmake does not normalize path so we need to do it ourselves.
+    file(TO_CMAKE_PATH ${ZLIB_LIBRARY} ZLIB_LIBRARY)
+endif()
 find_package(ZLIB QUIET)
 CMAKE_DEPENDENT_OPTION(WITH_ZLIB "Build with ZLIB support" ON
                        "ZLIB_FOUND" OFF)

http://git-wip-us.apache.org/repos/asf/thrift/blob/e8c71d8c/build/cmake/FindLibevent.cmake
----------------------------------------------------------------------
diff --git a/build/cmake/FindLibevent.cmake b/build/cmake/FindLibevent.cmake
index 1eac315..2bcd709 100644
--- a/build/cmake/FindLibevent.cmake
+++ b/build/cmake/FindLibevent.cmake
@@ -6,14 +6,16 @@
 # LIBEVENT_LIBRARIES, LibEvent libraries
 # Libevent_FOUND, If false, do not try to use libevent
 
-set(LibEvent_EXTRA_PREFIXES /usr/local /opt/local "$ENV{HOME}")
+set(LIBEVENT_ROOT CACHE PATH "Root directory of libevent installation")
+set(LibEvent_EXTRA_PREFIXES /usr/local /opt/local "$ENV{HOME}" ${LIBEVENT_ROOT})
 foreach(prefix ${LibEvent_EXTRA_PREFIXES})
   list(APPEND LibEvent_INCLUDE_PATHS "${prefix}/include")
   list(APPEND LibEvent_LIBRARIES_PATHS "${prefix}/lib")
 endforeach()
 
 find_path(LIBEVENT_INCLUDE_DIRS event.h PATHS ${LibEvent_INCLUDE_PATHS})
-find_library(LIBEVENT_LIBRARIES NAMES event PATHS ${LibEvent_LIBRARIES_PATHS})
+# "lib" prefix is needed on Windows
+find_library(LIBEVENT_LIBRARIES NAMES event libevent PATHS ${LibEvent_LIBRARIES_PATHS})
 
 if (LIBEVENT_LIBRARIES AND LIBEVENT_INCLUDE_DIRS)
   set(Libevent_FOUND TRUE)

http://git-wip-us.apache.org/repos/asf/thrift/blob/e8c71d8c/lib/cpp/test/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/lib/cpp/test/CMakeLists.txt b/lib/cpp/test/CMakeLists.txt
index 491d343..5d017b4 100644
--- a/lib/cpp/test/CMakeLists.txt
+++ b/lib/cpp/test/CMakeLists.txt
@@ -63,7 +63,7 @@ add_executable(Benchmark Benchmark.cpp)
 target_link_libraries(Benchmark testgencpp)
 LINK_AGAINST_THRIFT_LIBRARY(Benchmark thrift)
 add_test(NAME Benchmark COMMAND Benchmark)
-target_link_libraries(Benchmark testgencpp ${ZLIB_LIBRARIES})
+target_link_libraries(Benchmark testgencpp)
 
 set(UnitTest_SOURCES
     UnitTestMain.cpp
@@ -81,8 +81,7 @@ if(NOT WITH_BOOSTTHREADS AND NOT WITH_STDTHREADS AND NOT MSVC)
 endif()
 
 add_executable(UnitTests ${UnitTest_SOURCES})
-target_link_libraries(UnitTests testgencpp ${Boost_LIBRARIES}
-    ${ZLIB_LIBRARIES})
+target_link_libraries(UnitTests testgencpp ${Boost_LIBRARIES})
 LINK_AGAINST_THRIFT_LIBRARY(UnitTests thrift)
 add_test(NAME UnitTests COMMAND UnitTests)
 if ( MSVC )
@@ -105,7 +104,6 @@ add_executable(TInterruptTest ${TInterruptTest_SOURCES})
 target_link_libraries(TInterruptTest
     testgencpp
     ${Boost_LIBRARIES}
-    ${ZLIB_LIBRARIES}
 )
 LINK_AGAINST_THRIFT_LIBRARY(TInterruptTest thrift)
 if (NOT MSVC AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
@@ -117,7 +115,6 @@ add_executable(TServerIntegrationTest TServerIntegrationTest.cpp)
 target_link_libraries(TServerIntegrationTest
     testgencpp_cob
     ${Boost_LIBRARIES}
-    ${ZLIB_LIBRARIES}
 )
 LINK_AGAINST_THRIFT_LIBRARY(TServerIntegrationTest thrift)
 if (NOT MSVC AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
@@ -152,7 +149,6 @@ add_executable(EnumTest EnumTest.cpp)
 target_link_libraries(EnumTest
     testgencpp
     ${Boost_LIBRARIES}
-    ${ZLIB_LIBRARIES}
 )
 LINK_AGAINST_THRIFT_LIBRARY(EnumTest thrift)
 add_test(NAME EnumTest COMMAND EnumTest)
@@ -162,7 +158,6 @@ add_executable(TFileTransportTest TFileTransportTest.cpp)
 target_link_libraries(TFileTransportTest
     testgencpp
     ${Boost_LIBRARIES}
-    ${ZLIB_LIBRARIES}
 )
 LINK_AGAINST_THRIFT_LIBRARY(TFileTransportTest thrift)
 add_test(NAME TFileTransportTest COMMAND TFileTransportTest)
@@ -171,7 +166,6 @@ endif()
 add_executable(TFDTransportTest TFDTransportTest.cpp)
 target_link_libraries(TFDTransportTest
     ${Boost_LIBRARIES}
-    ${ZLIB_LIBRARIES}
 )
 LINK_AGAINST_THRIFT_LIBRARY(TFDTransportTest thrift)
 add_test(NAME TFDTransportTest COMMAND TFDTransportTest)
@@ -179,7 +173,6 @@ add_test(NAME TFDTransportTest COMMAND TFDTransportTest)
 add_executable(TPipedTransportTest TPipedTransportTest.cpp)
 target_link_libraries(TPipedTransportTest
     ${Boost_LIBRARIES}
-    ${ZLIB_LIBRARIES}
 )
 LINK_AGAINST_THRIFT_LIBRARY(TPipedTransportTest thrift)
 add_test(NAME TPipedTransportTest COMMAND TPipedTransportTest)
@@ -194,7 +187,6 @@ add_executable(AllProtocolsTest ${AllProtocolsTest_SOURCES})
 target_link_libraries(AllProtocolsTest
     testgencpp
     ${Boost_LIBRARIES}
-    ${ZLIB_LIBRARIES}
 )
 LINK_AGAINST_THRIFT_LIBRARY(AllProtocolsTest thrift)
 add_test(NAME AllProtocolsTest COMMAND AllProtocolsTest)
@@ -205,7 +197,6 @@ add_executable(DebugProtoTest DebugProtoTest.cpp)
 target_link_libraries(DebugProtoTest
     testgencpp
     ${Boost_LIBRARIES}
-    ${ZLIB_LIBRARIES}
 )
 LINK_AGAINST_THRIFT_LIBRARY(DebugProtoTest thrift)
 add_test(NAME DebugProtoTest COMMAND DebugProtoTest)
@@ -215,7 +206,6 @@ add_executable(JSONProtoTest JSONProtoTest.cpp)
 target_link_libraries(JSONProtoTest
     testgencpp
     ${Boost_LIBRARIES}
-    ${ZLIB_LIBRARIES}
 )
 LINK_AGAINST_THRIFT_LIBRARY(JSONProtoTest thrift)
 add_test(NAME JSONProtoTest COMMAND JSONProtoTest)
@@ -224,7 +214,6 @@ add_executable(OptionalRequiredTest OptionalRequiredTest.cpp)
 target_link_libraries(OptionalRequiredTest
     testgencpp
     ${Boost_LIBRARIES}
-    ${ZLIB_LIBRARIES}
 )
 LINK_AGAINST_THRIFT_LIBRARY(OptionalRequiredTest thrift)
 add_test(NAME OptionalRequiredTest COMMAND OptionalRequiredTest)
@@ -233,7 +222,6 @@ add_executable(RecursiveTest RecursiveTest.cpp)
 target_link_libraries(RecursiveTest
     testgencpp
     ${Boost_LIBRARIES}
-    ${ZLIB_LIBRARIES}
 )
 LINK_AGAINST_THRIFT_LIBRARY(RecursiveTest thrift)
 add_test(NAME RecursiveTest COMMAND RecursiveTest)
@@ -242,7 +230,6 @@ add_executable(SpecializationTest SpecializationTest.cpp)
 target_link_libraries(SpecializationTest
     testgencpp
     ${Boost_LIBRARIES}
-    ${ZLIB_LIBRARIES}
 )
 LINK_AGAINST_THRIFT_LIBRARY(SpecializationTest thrift)
 add_test(NAME SpecializationTest COMMAND SpecializationTest)
@@ -256,7 +243,6 @@ set(concurrency_test_SOURCES
 add_executable(concurrency_test ${concurrency_test_SOURCES})
 LINK_AGAINST_THRIFT_LIBRARY(concurrency_test thrift)
 add_test(NAME concurrency_test COMMAND concurrency_test)
-target_link_libraries(concurrency_test ${ZLIB_LIBRARIES})
 
 set(link_test_SOURCES
     link/LinkTest.cpp
@@ -268,7 +254,7 @@ set(link_test_SOURCES
 add_executable(link_test ${link_test_SOURCES})
 target_link_libraries(link_test testgencpp_cob)
 LINK_AGAINST_THRIFT_LIBRARY(link_test thrift)
-target_link_libraries(link_test testgencpp ${ZLIB_LIBRARIES})
+target_link_libraries(link_test testgencpp)
 add_test(NAME link_test COMMAND link_test)
 
 if(WITH_LIBEVENT)
@@ -284,7 +270,6 @@ add_executable(processor_test ${processor_test_SOURCES})
 target_link_libraries(processor_test
     testgencpp_cob
     ${Boost_LIBRARIES}
-    ${ZLIB_LIBRARIES}
 )
 LINK_AGAINST_THRIFT_LIBRARY(processor_test thrift)
 LINK_AGAINST_THRIFT_LIBRARY(processor_test thriftnb)
@@ -297,7 +282,6 @@ target_link_libraries(TNonblockingServerTest
     testgencpp_cob
     ${LIBEVENT_LIBRARIES}
     ${Boost_LIBRARIES}
-    ${ZLIB_LIBRARIES}
 )
 LINK_AGAINST_THRIFT_LIBRARY(TNonblockingServerTest thrift)
 LINK_AGAINST_THRIFT_LIBRARY(TNonblockingServerTest thriftnb)
@@ -309,7 +293,6 @@ add_executable(OpenSSLManualInitTest OpenSSLManualInitTest.cpp)
 target_link_libraries(OpenSSLManualInitTest
     ${OPENSSL_LIBRARIES}
     ${Boost_LIBRARIES}
-    ${ZLIB_LIBRARIES}
 )
 LINK_AGAINST_THRIFT_LIBRARY(OpenSSLManualInitTest thrift)
 add_test(NAME OpenSSLManualInitTest COMMAND OpenSSLManualInitTest)
@@ -318,7 +301,6 @@ add_executable(SecurityTest SecurityTest.cpp)
 target_link_libraries(SecurityTest
     testgencpp
     ${Boost_LIBRARIES}
-    ${ZLIB_LIBRARIES}
 )
 LINK_AGAINST_THRIFT_LIBRARY(SecurityTest thrift)
 if (NOT MSVC AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

http://git-wip-us.apache.org/repos/asf/thrift/blob/e8c71d8c/lib/hs/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/lib/hs/CMakeLists.txt b/lib/hs/CMakeLists.txt
index f28cb37..37ea288 100644
--- a/lib/hs/CMakeLists.txt
+++ b/lib/hs/CMakeLists.txt
@@ -48,11 +48,18 @@ foreach(SRC ${haskell_sources})
     endif()
 endforeach()
 
+if (CMAKE_BUILD_TYPE STREQUAL "Debug")
+  set(hs_optimize -O0)
+elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
+  set(hs_optimize -O1)
+endif()
+
 add_custom_command(
     OUTPUT ${haskell_artifacts}
     COMMAND ${CABAL} update
     # Build dependencies first without --builddir, otherwise it fails.
-    COMMAND ${CABAL} install --dependencies-only
+    COMMAND ${CABAL} install --only-dependencies
+    COMMAND ${CABAL} configure ${hs_optimize}
     COMMAND ${CABAL} install --builddir=${CMAKE_CURRENT_BINARY_DIR}/dist
     COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/thrift_cabal.stamp
     WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}

http://git-wip-us.apache.org/repos/asf/thrift/blob/e8c71d8c/test/hs/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/test/hs/CMakeLists.txt b/test/hs/CMakeLists.txt
index a65339d..eaca3fa 100644
--- a/test/hs/CMakeLists.txt
+++ b/test/hs/CMakeLists.txt
@@ -61,10 +61,17 @@ set(hs_crosstest_args
     -odir=${CMAKE_CURRENT_BINARY_DIR}
     -hidir=${CMAKE_CURRENT_BINARY_DIR}
 )
+
+if (CMAKE_BUILD_TYPE STREQUAL "Debug")
+  set(hs_optimize -O0)
+else()
+  set(hs_optimize -O1)
+endif()
+
 add_custom_command(
     OUTPUT ${hs_crosstest_apps}
-    COMMAND ${GHC} ${hs_crosstest_args} ${CMAKE_CURRENT_SOURCE_DIR}/TestServer.hs -o TestServer
-    COMMAND ${GHC} ${hs_crosstest_args} ${CMAKE_CURRENT_SOURCE_DIR}/TestClient.hs -o TestClient
+    COMMAND ${GHC} ${hs_optimize} ${hs_crosstest_args} ${CMAKE_CURRENT_SOURCE_DIR}/TestServer.hs -o TestServer
+    COMMAND ${GHC} ${hs_optimize} ${hs_crosstest_args} ${CMAKE_CURRENT_SOURCE_DIR}/TestClient.hs -o TestClient
     DEPENDS ${hs_test_gen} haskell_library TestServer.hs TestClient.hs
 )
 add_custom_target(haskell_crosstest ALL

http://git-wip-us.apache.org/repos/asf/thrift/blob/e8c71d8c/test/hs/TestClient.hs
----------------------------------------------------------------------
diff --git a/test/hs/TestClient.hs b/test/hs/TestClient.hs
index 057a560..0ebc0fd 100644
--- a/test/hs/TestClient.hs
+++ b/test/hs/TestClient.hs
@@ -29,7 +29,6 @@ import Network
 import Network.URI
 import System.Environment
 import System.Exit
-import System.Posix.Unistd
 import qualified Data.ByteString.Lazy as LBS
 import qualified Data.HashMap.Strict as Map
 import qualified Data.HashSet as Set

http://git-wip-us.apache.org/repos/asf/thrift/blob/e8c71d8c/test/hs/TestServer.hs
----------------------------------------------------------------------
diff --git a/test/hs/TestServer.hs b/test/hs/TestServer.hs
index 90ec11e..4a88649 100755
--- a/test/hs/TestServer.hs
+++ b/test/hs/TestServer.hs
@@ -31,7 +31,7 @@ import Network
 import System.Environment
 import System.Exit
 import System.IO
-import System.Posix.Unistd
+import Control.Concurrent (threadDelay)
 import qualified System.IO as IO
 import qualified Data.HashMap.Strict as Map
 import qualified Data.HashSet as Set
@@ -241,7 +241,7 @@ instance ThriftTest_Iface TestHandler where
 
   testOneway _ i = do
     System.IO.putStrLn $ "testOneway(" ++ show i ++ "): Sleeping..."
-    sleep (fromIntegral i)
+    threadDelay $ (fromIntegral i) * 1000000
     System.IO.putStrLn $ "testOneway(" ++ show i ++ "): done sleeping!"
 
 main :: IO ()


[2/3] thrift git commit: THRIFT-3440 Python make check takes too much time Client: Test Python Patch: Nobuaki Sukegawa

Posted by ns...@apache.org.
THRIFT-3440 Python make check takes too much time
Client: Test Python
Patch: Nobuaki Sukegawa

This closes #711


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

Branch: refs/heads/master
Commit: cacce2f1d503b7e98842308852237af53180fd87
Parents: 2de2700
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Sun Nov 8 23:43:55 2015 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Mon Nov 23 21:24:24 2015 +0900

----------------------------------------------------------------------
 test/py/RunClientServer.py         | 319 +++++++++++++++++++++-----------
 test/py/SerializationTest.py       |  17 +-
 test/py/TSimpleJSONProtocolTest.py |  21 +--
 test/py/TestEof.py                 |  16 +-
 test/py/TestSocket.py              |  26 +--
 test/py/TestSyntax.py              |   9 -
 6 files changed, 228 insertions(+), 180 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/cacce2f1/test/py/RunClientServer.py
----------------------------------------------------------------------
diff --git a/test/py/RunClientServer.py b/test/py/RunClientServer.py
index 7224bac..fa2a264 100755
--- a/test/py/RunClientServer.py
+++ b/test/py/RunClientServer.py
@@ -21,108 +21,92 @@
 
 from __future__ import division
 from __future__ import print_function
-import time
+import copy
+import glob
+import os
+import signal
 import socket
 import subprocess
 import sys
-import os
-import signal
+import time
 from optparse import OptionParser
 
-parser = OptionParser()
-parser.add_option('--genpydirs', type='string', dest='genpydirs',
-    default='default,slots,newstyle,newstyleslots,dynamic,dynamicslots',
-    help='directory extensions for generated code, used as suffixes for \"gen-py-*\" added sys.path for individual tests')
-parser.add_option("--port", type="int", dest="port", default=9090,
-    help="port number for server to listen on")
-parser.add_option('-v', '--verbose', action="store_const",
-    dest="verbose", const=2,
-    help="verbose output")
-parser.add_option('-q', '--quiet', action="store_const",
-    dest="verbose", const=0,
-    help="minimal output")
-parser.set_defaults(verbose=1)
-options, args = parser.parse_args()
-
-generated_dirs = []
-for gp_dir in options.genpydirs.split(','):
-  generated_dirs.append('gen-py-%s' % (gp_dir))
-
-SCRIPTS = ['TSimpleJSONProtocolTest.py',
-           'SerializationTest.py',
-           'TestEof.py',
-           'TestSyntax.py',
-           'TestSocket.py']
+SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
+ROOT_DIR = os.path.dirname(os.path.dirname(SCRIPT_DIR))
+DEFAULT_LIBDIR_GLOB = os.path.join(ROOT_DIR, 'lib', 'py', 'build', 'lib.*')
+DEFAULT_LIBDIR_PY3 = os.path.join(ROOT_DIR, 'lib', 'py', 'build', 'lib')
+
+SCRIPTS = [
+  'TSimpleJSONProtocolTest.py',
+  'SerializationTest.py',
+  'TestEof.py',
+  'TestSyntax.py',
+  'TestSocket.py',
+]
 FRAMED = ["TNonblockingServer"]
 SKIP_ZLIB = ['TNonblockingServer', 'THttpServer']
 SKIP_SSL = ['TNonblockingServer', 'THttpServer']
 EXTRA_DELAY = dict(TProcessPoolServer=5.5)
 
-PROTOS= [
-    'accel',
-    'binary',
-    'compact',
-    'json']
+PROTOS = [
+  'accel',
+  'binary',
+  'compact',
+  'json',
+]
 
 SERVERS = [
   "TSimpleServer",
   "TThreadedServer",
   "TThreadPoolServer",
-  "TProcessPoolServer", # new!
+  "TProcessPoolServer",
   "TForkingServer",
   "TNonblockingServer",
-  "THttpServer" ]
-
-# Test for presence of multiprocessing module, and if it is not present, then
-# remove it from the list of available servers.
-try:
-  import multiprocessing
-except:
-  print('Warning: the multiprocessing module is unavailable. Skipping tests for TProcessPoolServer')
-  SERVERS.remove('TProcessPoolServer')
-
-try:
-  import ssl
-except:
-  print('Warning, no ssl module available. Skipping all SSL tests.')
-  SKIP_SSL.extend(SERVERS)
-
-# commandline permits a single class name to be specified to override SERVERS=[...]
-if len(args) == 1:
-  if args[0] in SERVERS:
-    SERVERS = args
-  else:
-    print('Unavailable server type "%s", please choose one of: %s' % (args[0], SERVERS))
-    sys.exit(0)
+  "THttpServer",
+]
 
 
 def relfile(fname):
-    return os.path.join(os.path.dirname(__file__), fname)
+    return os.path.join(SCRIPT_DIR, fname)
 
-def runScriptTest(genpydir, script):
-  script_args = [sys.executable, relfile(script) ]
-  script_args.append('--genpydir=%s' % genpydir)
-  serverproc = subprocess.Popen(script_args)
+
+def setup_pypath(dirs):
+  env = copy.copy(os.environ)
+  pypath = env.get('PYTHONPATH', None)
+  if pypath:
+    dirs.append(pypath)
+  env['PYTHONPATH'] = ':'.join(dirs)
+  return env
+
+
+def runScriptTest(libdir, genpydir, script):
+  env = setup_pypath([libdir, genpydir])
+  script_args = [sys.executable, relfile(script)]
   print('\nTesting script: %s\n----' % (' '.join(script_args)))
-  ret = subprocess.call(script_args)
+  ret = subprocess.call(script_args, env=env)
   if ret != 0:
+    print('*** FAILED ***', file=sys.stderr)
+    print('LIBDIR: %s' % libdir, file=sys.stderr)
+    print('PY_GEN: %s' % genpydir, file=sys.stderr)
+    print('SCRIPT: %s' % script, file=sys.stderr)
     raise Exception("Script subprocess failed, retcode=%d, args: %s" % (ret, ' '.join(script_args)))
 
-def runServiceTest(genpydir, server_class, proto, port, use_zlib, use_ssl):
+
+def runServiceTest(libdir, genpydir, server_class, proto, port, use_zlib, use_ssl, verbose):
+  env = setup_pypath([libdir, genpydir])
   # Build command line arguments
-  server_args = [sys.executable, relfile('TestServer.py') ]
-  cli_args = [sys.executable, relfile('TestClient.py') ]
+  server_args = [sys.executable, relfile('TestServer.py')]
+  cli_args = [sys.executable, relfile('TestClient.py')]
   for which in (server_args, cli_args):
-    which.append('--genpydir=%s' % genpydir)
-    which.append('--protocol=%s' % proto) # accel, binary or compact
-    which.append('--port=%d' % port) # default to 9090
+    which.append('--protocol=%s' % proto)  # accel, binary, compact or json
+    which.append('--port=%d' % port)  # default to 9090
     if use_zlib:
       which.append('--zlib')
     if use_ssl:
       which.append('--ssl')
-    if options.verbose == 0:
+    if verbose == 0:
       which.append('-q')
-    if options.verbose == 2:
+    if verbose == 2:
       which.append('-v')
   # server-specific option to select server class
   server_args.append(server_class)
@@ -133,14 +117,14 @@ def runServiceTest(genpydir, server_class, proto, port, use_zlib, use_ssl):
      cli_args.append('--transport=buffered')
   if server_class == 'THttpServer':
     cli_args.append('--http=/')
-  if options.verbose > 0:
+  if verbose > 0:
     print('Testing server %s: %s' % (server_class, ' '.join(server_args)))
-  serverproc = subprocess.Popen(server_args)
+  serverproc = subprocess.Popen(server_args, env=env)
 
   def ensureServerAlive():
     if serverproc.poll() is not None:
       print(('FAIL: Server process (%s) failed with retcode %d')
-             % (' '.join(server_args), serverproc.returncode))
+            % (' '.join(server_args), serverproc.returncode))
       raise Exception('Server subprocess %s died, args: %s'
                       % (server_class, ' '.join(server_args)))
 
@@ -161,55 +145,166 @@ def runServiceTest(genpydir, server_class, proto, port, use_zlib, use_ssl):
     sock.close()
 
   try:
-    if options.verbose > 0:
+    if verbose > 0:
       print('Testing client: %s' % (' '.join(cli_args)))
-    ret = subprocess.call(cli_args)
+    ret = subprocess.call(cli_args, env=env)
     if ret != 0:
+      print('*** FAILED ***', file=sys.stderr)
+      print('LIBDIR: %s' % libdir, file=sys.stderr)
+      print('PY_GEN: %s' % genpydir, file=sys.stderr)
       raise Exception("Client subprocess failed, retcode=%d, args: %s" % (ret, ' '.join(cli_args)))
   finally:
     # check that server didn't die
     ensureServerAlive()
     extra_sleep = EXTRA_DELAY.get(server_class, 0)
-    if extra_sleep > 0 and options.verbose > 0:
+    if extra_sleep > 0 and verbose > 0:
       print('Giving %s (proto=%s,zlib=%s,ssl=%s) an extra %d seconds for child'
-             'processes to terminate via alarm'
-             % (server_class, proto, use_zlib, use_ssl, extra_sleep))
+            'processes to terminate via alarm'
+            % (server_class, proto, use_zlib, use_ssl, extra_sleep))
       time.sleep(extra_sleep)
     os.kill(serverproc.pid, signal.SIGKILL)
     serverproc.wait()
 
-test_count = 0
-# run tests without a client/server first
-print('----------------')
-print(' Executing individual test scripts with various generated code directories')
-print(' Directories to be tested: ' + ', '.join(generated_dirs))
-print(' Scripts to be tested: ' + ', '.join(SCRIPTS))
-print('----------------')
-for genpydir in generated_dirs:
-  for script in SCRIPTS:
-    runScriptTest(genpydir, script)
-
-print('----------------')
-print(' Executing Client/Server tests with various generated code directories')
-print(' Servers to be tested: ' + ', '.join(SERVERS))
-print(' Directories to be tested: ' + ', '.join(generated_dirs))
-print(' Protocols to be tested: ' + ', '.join(PROTOS))
-print(' Options to be tested: ZLIB(yes/no), SSL(yes/no)')
-print('----------------')
-for try_server in SERVERS:
+
+class TestCases(object):
+  def __init__(self, libdir, port, gendirs, servers, verbose):
+    self.libdir = libdir
+    self.port = port
+    self.verbose = verbose
+    self.gendirs = gendirs
+    self.servers = servers
+
+  def default_conf(self):
+    return {
+      'gendir': self.gendirs[0],
+      'server': self.servers[0],
+      'proto': PROTOS[0],
+      'zlib': False,
+      'ssl': False,
+    }
+
+  def run(self, conf, test_count):
+    with_zlib = conf['zlib']
+    with_ssl = conf['ssl']
+    try_server = conf['server']
+    try_proto = conf['proto']
+    genpydir = conf['gendir']
+    # skip any servers that don't work with the Zlib transport
+    if with_zlib and try_server in SKIP_ZLIB:
+      return False
+    # skip any servers that don't work with SSL
+    if with_ssl and try_server in SKIP_SSL:
+      return False
+    if self.verbose > 0:
+      print('\nTest run #%d:  (includes %s) Server=%s,  Proto=%s,  zlib=%s,  SSL=%s'
+            % (test_count, genpydir, try_server, try_proto, with_zlib, with_ssl))
+    runServiceTest(self.libdir, genpydir, try_server, try_proto, self.port, with_zlib, with_ssl, self.verbose)
+    if self.verbose > 0:
+      print('OK: Finished (includes %s)  %s / %s proto / zlib=%s / SSL=%s.   %d combinations tested.'
+            % (genpydir, try_server, try_proto, with_zlib, with_ssl, test_count))
+    return True
+
+  def test_feature(self, name, values):
+    test_count = 0
+    conf = self.default_conf()
+    for try_server in values:
+      conf[name] = try_server
+      if self.run(conf, test_count):
+        test_count += 1
+    return test_count
+
+  def run_all_tests(self):
+    test_count = 0
+    for try_server in self.servers:
+      for genpydir in self.gendirs:
+        for try_proto in PROTOS:
+          for with_zlib in (False, True):
+            # skip any servers that don't work with the Zlib transport
+            if with_zlib and try_server in SKIP_ZLIB:
+              continue
+            for with_ssl in (False, True):
+              # skip any servers that don't work with SSL
+              if with_ssl and try_server in SKIP_SSL:
+                continue
+              test_count += 1
+              if self.verbose > 0:
+                print('\nTest run #%d:  (includes %s) Server=%s,  Proto=%s,  zlib=%s,  SSL=%s'
+                      % (test_count, genpydir, try_server, try_proto, with_zlib, with_ssl))
+              runServiceTest(self.libdir, genpydir, try_server, try_proto, self.port, with_zlib, with_ssl)
+              if self.verbose > 0:
+                print('OK: Finished (includes %s)  %s / %s proto / zlib=%s / SSL=%s.   %d combinations tested.'
+                      % (genpydir, try_server, try_proto, with_zlib, with_ssl, test_count))
+    return test_count
+
+
+def default_libdir():
+  if sys.version_info[0] == 2:
+    return glob.glob(DEFAULT_LIBDIR_GLOB)[0]
+  else:
+    return DEFAULT_LIBDIR_PY3
+
+
+def main():
+  parser = OptionParser()
+  parser.add_option('--all', action="store_true", dest='all')
+  parser.add_option('--genpydirs', type='string', dest='genpydirs',
+                    default='default,slots,newstyle,newstyleslots,dynamic,dynamicslots',
+                    help='directory extensions for generated code, used as suffixes for \"gen-py-*\" added sys.path for individual tests')
+  parser.add_option("--port", type="int", dest="port", default=9090,
+                    help="port number for server to listen on")
+  parser.add_option('-v', '--verbose', action="store_const",
+                    dest="verbose", const=2,
+                    help="verbose output")
+  parser.add_option('-q', '--quiet', action="store_const",
+                    dest="verbose", const=0,
+                    help="minimal output")
+  parser.add_option('-L', '--libdir', dest="libdir", default=default_libdir(),
+                    help="directory path that contains Thrift Python library")
+  parser.set_defaults(verbose=1)
+  options, args = parser.parse_args()
+
+  generated_dirs = []
+  for gp_dir in options.genpydirs.split(','):
+    generated_dirs.append('gen-py-%s' % (gp_dir))
+
+  # commandline permits a single class name to be specified to override SERVERS=[...]
+  servers = SERVERS
+  if len(args) == 1:
+    if args[0] in SERVERS:
+      servers = args
+    else:
+      print('Unavailable server type "%s", please choose one of: %s' % (args[0], servers))
+      sys.exit(0)
+
+  tests = TestCases(options.libdir, options.port, generated_dirs, servers, options.verbose)
+
+  # run tests without a client/server first
+  print('----------------')
+  print(' Executing individual test scripts with various generated code directories')
+  print(' Directories to be tested: ' + ', '.join(generated_dirs))
+  print(' Scripts to be tested: ' + ', '.join(SCRIPTS))
+  print('----------------')
   for genpydir in generated_dirs:
-    for try_proto in PROTOS:
-      for with_zlib in (False, True):
-        # skip any servers that don't work with the Zlib transport
-        if with_zlib and try_server in SKIP_ZLIB:
-          continue
-        for with_ssl in (False, True):
-          # skip any servers that don't work with SSL
-          if with_ssl and try_server in SKIP_SSL:
-            continue
-          test_count += 1
-          if options.verbose > 0:
-            print('\nTest run #%d:  (includes %s) Server=%s,  Proto=%s,  zlib=%s,  SSL=%s' % (test_count, genpydir, try_server, try_proto, with_zlib, with_ssl))
-          runServiceTest(genpydir, try_server, try_proto, options.port, with_zlib, with_ssl)
-          if options.verbose > 0:
-            print('OK: Finished (includes %s)  %s / %s proto / zlib=%s / SSL=%s.   %d combinations tested.' % (genpydir, try_server, try_proto, with_zlib, with_ssl, test_count))
+    for script in SCRIPTS:
+      runScriptTest(options.libdir, genpydir, script)
+
+  print('----------------')
+  print(' Executing Client/Server tests with various generated code directories')
+  print(' Servers to be tested: ' + ', '.join(servers))
+  print(' Directories to be tested: ' + ', '.join(generated_dirs))
+  print(' Protocols to be tested: ' + ', '.join(PROTOS))
+  print(' Options to be tested: ZLIB(yes/no), SSL(yes/no)')
+  print('----------------')
+
+  if options.all:
+    tests.run_all_tests()
+  else:
+    tests.test_feature('gendir', generated_dirs)
+    tests.test_feature('server', servers)
+    tests.test_feature('proto', PROTOS)
+    tests.test_feature('zlib', [False, True])
+    tests.test_feature('ssl', [False, True])
+
+
+if __name__ == '__main__':
+  sys.exit(main())

http://git-wip-us.apache.org/repos/asf/thrift/blob/cacce2f1/test/py/SerializationTest.py
----------------------------------------------------------------------
diff --git a/test/py/SerializationTest.py b/test/py/SerializationTest.py
index 29f3656..99e0393 100755
--- a/test/py/SerializationTest.py
+++ b/test/py/SerializationTest.py
@@ -19,23 +19,13 @@
 # under the License.
 #
 
-import sys, glob
-from optparse import OptionParser
-parser = OptionParser()
-parser.add_option('--genpydir', type='string', dest='genpydir', default='gen-py')
-options, args = parser.parse_args()
-del sys.argv[1:] # clean up hack so unittest doesn't complain
-sys.path.insert(0, options.genpydir)
-sys.path.insert(0, glob.glob('../../lib/py/build/lib*')[0])
-
 from ThriftTest.ttypes import *
 from DebugProtoTest.ttypes import CompactProtoTestStruct, Empty
 from thrift.transport import TTransport
-from thrift.transport import TSocket
 from thrift.protocol import TBinaryProtocol, TCompactProtocol, TJSONProtocol
 from thrift.TSerialization import serialize, deserialize
 import unittest
-import time
+
 
 class AbstractTest(unittest.TestCase):
 
@@ -277,18 +267,23 @@ class AbstractTest(unittest.TestCase):
     for value in bad_values:
       self.assertRaises(Exception, self._serialize, value)
 
+
 class NormalBinaryTest(AbstractTest):
   protocol_factory = TBinaryProtocol.TBinaryProtocolFactory()
 
+
 class AcceleratedBinaryTest(AbstractTest):
   protocol_factory = TBinaryProtocol.TBinaryProtocolAcceleratedFactory()
 
+
 class CompactProtocolTest(AbstractTest):
   protocol_factory = TCompactProtocol.TCompactProtocolFactory()
 
+
 class JSONProtocolTest(AbstractTest):
   protocol_factory = TJSONProtocol.TJSONProtocolFactory()
 
+
 class AcceleratedFramedTest(unittest.TestCase):
   def testSplit(self):
     """Test FramedTransport and BinaryProtocolAccelerated

http://git-wip-us.apache.org/repos/asf/thrift/blob/cacce2f1/test/py/TSimpleJSONProtocolTest.py
----------------------------------------------------------------------
diff --git a/test/py/TSimpleJSONProtocolTest.py b/test/py/TSimpleJSONProtocolTest.py
index b8db932..1ed8c15 100644
--- a/test/py/TSimpleJSONProtocolTest.py
+++ b/test/py/TSimpleJSONProtocolTest.py
@@ -19,17 +19,7 @@
 # under the License.
 #
 
-import sys
-import glob
-from optparse import OptionParser
-parser = OptionParser()
-parser.add_option('--genpydir', type='string', dest='genpydir', default='gen-py')
-options, args = parser.parse_args()
-del sys.argv[1:] # clean up hack so unittest doesn't complain
-sys.path.insert(0, options.genpydir)
-sys.path.insert(0, glob.glob('../../lib/py/build/lib*')[0])
-
-from ThriftTest.ttypes import *
+from ThriftTest.ttypes import Bonk, VersioningTestV1, VersioningTestV2
 from thrift.protocol import TJSONProtocol
 from thrift.transport import TTransport
 
@@ -40,7 +30,7 @@ import unittest
 class SimpleJSONProtocolTest(unittest.TestCase):
   protocol_factory = TJSONProtocol.TSimpleJSONProtocolFactory()
 
-  def _assertDictEqual(self, a ,b, msg=None):
+  def _assertDictEqual(self, a, b, msg=None):
     if hasattr(self, 'assertDictEqual'):
       # assertDictEqual only in Python 2.7. Depends on your machine.
       self.assertDictEqual(a, b, msg)
@@ -89,9 +79,9 @@ class SimpleJSONProtocolTest(unittest.TestCase):
           newlong=4,
           newdouble=5.0,
           newstruct=Bonk(message="Hello!", type=123),
-          newlist=[7,8,9],
-          newset=set([42,1,8]),
-          newmap={1:2,2:3},
+          newlist=[7, 8, 9],
+          newset=set([42, 1, 8]),
+          newmap={1: 2, 2: 3},
           newstring="Hola!",
           end_in_both=54321)
       expected = dict(begin_in_both=v2obj.begin_in_both,
@@ -116,4 +106,3 @@ class SimpleJSONProtocolTest(unittest.TestCase):
 
 if __name__ == '__main__':
   unittest.main()
-

http://git-wip-us.apache.org/repos/asf/thrift/blob/cacce2f1/test/py/TestEof.py
----------------------------------------------------------------------
diff --git a/test/py/TestEof.py b/test/py/TestEof.py
index 7677de8..6614638 100755
--- a/test/py/TestEof.py
+++ b/test/py/TestEof.py
@@ -19,23 +19,12 @@
 # under the License.
 #
 
-import sys, glob
-from optparse import OptionParser
-parser = OptionParser()
-parser.add_option('--genpydir', type='string', dest='genpydir', default='gen-py')
-options, args = parser.parse_args()
-del sys.argv[1:] # clean up hack so unittest doesn't complain
-sys.path.insert(0, options.genpydir)
-sys.path.insert(0, glob.glob('../../lib/py/build/lib*')[0])
-
-from ThriftTest import ThriftTest
-from ThriftTest.ttypes import *
+from ThriftTest.ttypes import Xtruct
 from thrift.transport import TTransport
-from thrift.transport import TSocket
 from thrift.protocol import TBinaryProtocol
 from thrift.protocol import TCompactProtocol
 import unittest
-import time
+
 
 class TestEof(unittest.TestCase):
 
@@ -126,6 +115,7 @@ class TestEof(unittest.TestCase):
     self.eofTestHelper(TCompactProtocol.TCompactProtocolFactory())
     self.eofTestHelperStress(TCompactProtocol.TCompactProtocolFactory())
 
+
 def suite():
   suite = unittest.TestSuite()
   loader = unittest.TestLoader()

http://git-wip-us.apache.org/repos/asf/thrift/blob/cacce2f1/test/py/TestSocket.py
----------------------------------------------------------------------
diff --git a/test/py/TestSocket.py b/test/py/TestSocket.py
index 55e4996..a01be85 100755
--- a/test/py/TestSocket.py
+++ b/test/py/TestSocket.py
@@ -19,25 +19,12 @@
 # under the License.
 #
 
-import sys, glob
-from optparse import OptionParser
-parser = OptionParser()
-parser.add_option('--genpydir', type='string', dest='genpydir', default='gen-py')
-options, args = parser.parse_args()
-del sys.argv[1:] # clean up hack so unittest doesn't complain
-sys.path.insert(0, options.genpydir)
-sys.path.insert(0, glob.glob('../../lib/py/build/lib*')[0])
-
-from ThriftTest import ThriftTest
-from ThriftTest.ttypes import *
-from thrift.transport import TTransport
 from thrift.transport import TSocket
-from thrift.protocol import TBinaryProtocol
 import unittest
 import time
 import socket
 import random
-from optparse import OptionParser
+
 
 class TimeoutTest(unittest.TestCase):
     def setUp(self):
@@ -80,10 +67,11 @@ class TimeoutTest(unittest.TestCase):
         except:
             self.assert_(time.time() - starttime < 5.0)
 
-suite = unittest.TestSuite()
-loader = unittest.TestLoader()
+if __name__ == '__main__':
+  suite = unittest.TestSuite()
+  loader = unittest.TestLoader()
 
-suite.addTest(loader.loadTestsFromTestCase(TimeoutTest))
+  suite.addTest(loader.loadTestsFromTestCase(TimeoutTest))
 
-testRunner = unittest.TextTestRunner(verbosity=2)
-testRunner.run(suite)
+  testRunner = unittest.TextTestRunner(verbosity=2)
+  testRunner.run(suite)

http://git-wip-us.apache.org/repos/asf/thrift/blob/cacce2f1/test/py/TestSyntax.py
----------------------------------------------------------------------
diff --git a/test/py/TestSyntax.py b/test/py/TestSyntax.py
index cdf0e0d..c83f40e 100755
--- a/test/py/TestSyntax.py
+++ b/test/py/TestSyntax.py
@@ -19,15 +19,6 @@
 # under the License.
 #
 
-import sys, glob
-from optparse import OptionParser
-parser = OptionParser()
-parser.add_option('--genpydir', type='string', dest='genpydir', default='gen-py')
-options, args = parser.parse_args()
-del sys.argv[1:] # clean up hack so unittest doesn't complain
-sys.path.insert(0, options.genpydir)
-sys.path.insert(0, glob.glob('../../lib/py/build/lib*')[0])
-
 # Just import these generated files to make sure they are syntactically valid
 from DebugProtoTest import EmptyService
 from DebugProtoTest import Inherited