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 2016/02/04 06:28:46 UTC
[2/8] thrift git commit: THRIFT-3596 Better conformance to PEP8
http://git-wip-us.apache.org/repos/asf/thrift/blob/10308cb9/test/py/TestFrozen.py
----------------------------------------------------------------------
diff --git a/test/py/TestFrozen.py b/test/py/TestFrozen.py
index 76750ad..30a6a55 100755
--- a/test/py/TestFrozen.py
+++ b/test/py/TestFrozen.py
@@ -28,89 +28,89 @@ import unittest
class TestFrozenBase(unittest.TestCase):
- def _roundtrip(self, src, dst):
- otrans = TTransport.TMemoryBuffer()
- optoro = self.protocol(otrans)
- src.write(optoro)
- itrans = TTransport.TMemoryBuffer(otrans.getvalue())
- iproto = self.protocol(itrans)
- return dst.read(iproto) or dst
-
- def test_dict_is_hashable_only_after_frozen(self):
- d0 = {}
- self.assertFalse(isinstance(d0, collections.Hashable))
- d1 = TFrozenDict(d0)
- self.assertTrue(isinstance(d1, collections.Hashable))
-
- def test_struct_with_collection_fields(self):
- pass
-
- def test_set(self):
- """Test that annotated set field can be serialized and deserialized"""
- x = CompactProtoTestStruct(set_byte_map={
- frozenset([42, 100, -100]): 99,
- frozenset([0]): 100,
- frozenset([]): 0,
- })
- x2 = self._roundtrip(x, CompactProtoTestStruct())
- self.assertEqual(x2.set_byte_map[frozenset([42, 100, -100])], 99)
- self.assertEqual(x2.set_byte_map[frozenset([0])], 100)
- self.assertEqual(x2.set_byte_map[frozenset([])], 0)
-
- def test_map(self):
- """Test that annotated map field can be serialized and deserialized"""
- x = CompactProtoTestStruct(map_byte_map={
- TFrozenDict({42: 42, 100: -100}): 99,
- TFrozenDict({0: 0}): 100,
- TFrozenDict({}): 0,
- })
- x2 = self._roundtrip(x, CompactProtoTestStruct())
- self.assertEqual(x2.map_byte_map[TFrozenDict({42: 42, 100: -100})], 99)
- self.assertEqual(x2.map_byte_map[TFrozenDict({0: 0})], 100)
- self.assertEqual(x2.map_byte_map[TFrozenDict({})], 0)
-
- def test_list(self):
- """Test that annotated list field can be serialized and deserialized"""
- x = CompactProtoTestStruct(list_byte_map={
- (42, 100, -100): 99,
- (0,): 100,
- (): 0,
- })
- x2 = self._roundtrip(x, CompactProtoTestStruct())
- self.assertEqual(x2.list_byte_map[(42, 100, -100)], 99)
- self.assertEqual(x2.list_byte_map[(0,)], 100)
- self.assertEqual(x2.list_byte_map[()], 0)
-
- def test_empty_struct(self):
- """Test that annotated empty struct can be serialized and deserialized"""
- x = CompactProtoTestStruct(empty_struct_field=Empty())
- x2 = self._roundtrip(x, CompactProtoTestStruct())
- self.assertEqual(x2.empty_struct_field, Empty())
-
- def test_struct(self):
- """Test that annotated struct can be serialized and deserialized"""
- x = Wrapper(foo=Empty())
- self.assertEqual(x.foo, Empty())
- x2 = self._roundtrip(x, Wrapper)
- self.assertEqual(x2.foo, Empty())
+ def _roundtrip(self, src, dst):
+ otrans = TTransport.TMemoryBuffer()
+ optoro = self.protocol(otrans)
+ src.write(optoro)
+ itrans = TTransport.TMemoryBuffer(otrans.getvalue())
+ iproto = self.protocol(itrans)
+ return dst.read(iproto) or dst
+
+ def test_dict_is_hashable_only_after_frozen(self):
+ d0 = {}
+ self.assertFalse(isinstance(d0, collections.Hashable))
+ d1 = TFrozenDict(d0)
+ self.assertTrue(isinstance(d1, collections.Hashable))
+
+ def test_struct_with_collection_fields(self):
+ pass
+
+ def test_set(self):
+ """Test that annotated set field can be serialized and deserialized"""
+ x = CompactProtoTestStruct(set_byte_map={
+ frozenset([42, 100, -100]): 99,
+ frozenset([0]): 100,
+ frozenset([]): 0,
+ })
+ x2 = self._roundtrip(x, CompactProtoTestStruct())
+ self.assertEqual(x2.set_byte_map[frozenset([42, 100, -100])], 99)
+ self.assertEqual(x2.set_byte_map[frozenset([0])], 100)
+ self.assertEqual(x2.set_byte_map[frozenset([])], 0)
+
+ def test_map(self):
+ """Test that annotated map field can be serialized and deserialized"""
+ x = CompactProtoTestStruct(map_byte_map={
+ TFrozenDict({42: 42, 100: -100}): 99,
+ TFrozenDict({0: 0}): 100,
+ TFrozenDict({}): 0,
+ })
+ x2 = self._roundtrip(x, CompactProtoTestStruct())
+ self.assertEqual(x2.map_byte_map[TFrozenDict({42: 42, 100: -100})], 99)
+ self.assertEqual(x2.map_byte_map[TFrozenDict({0: 0})], 100)
+ self.assertEqual(x2.map_byte_map[TFrozenDict({})], 0)
+
+ def test_list(self):
+ """Test that annotated list field can be serialized and deserialized"""
+ x = CompactProtoTestStruct(list_byte_map={
+ (42, 100, -100): 99,
+ (0,): 100,
+ (): 0,
+ })
+ x2 = self._roundtrip(x, CompactProtoTestStruct())
+ self.assertEqual(x2.list_byte_map[(42, 100, -100)], 99)
+ self.assertEqual(x2.list_byte_map[(0,)], 100)
+ self.assertEqual(x2.list_byte_map[()], 0)
+
+ def test_empty_struct(self):
+ """Test that annotated empty struct can be serialized and deserialized"""
+ x = CompactProtoTestStruct(empty_struct_field=Empty())
+ x2 = self._roundtrip(x, CompactProtoTestStruct())
+ self.assertEqual(x2.empty_struct_field, Empty())
+
+ def test_struct(self):
+ """Test that annotated struct can be serialized and deserialized"""
+ x = Wrapper(foo=Empty())
+ self.assertEqual(x.foo, Empty())
+ x2 = self._roundtrip(x, Wrapper)
+ self.assertEqual(x2.foo, Empty())
class TestFrozen(TestFrozenBase):
- def protocol(self, trans):
- return TBinaryProtocol.TBinaryProtocolFactory().getProtocol(trans)
+ def protocol(self, trans):
+ return TBinaryProtocol.TBinaryProtocolFactory().getProtocol(trans)
class TestFrozenAccelerated(TestFrozenBase):
- def protocol(self, trans):
- return TBinaryProtocol.TBinaryProtocolAcceleratedFactory().getProtocol(trans)
+ def protocol(self, trans):
+ return TBinaryProtocol.TBinaryProtocolAcceleratedFactory().getProtocol(trans)
def suite():
- suite = unittest.TestSuite()
- loader = unittest.TestLoader()
- suite.addTest(loader.loadTestsFromTestCase(TestFrozen))
- suite.addTest(loader.loadTestsFromTestCase(TestFrozenAccelerated))
- return suite
+ suite = unittest.TestSuite()
+ loader = unittest.TestLoader()
+ suite.addTest(loader.loadTestsFromTestCase(TestFrozen))
+ suite.addTest(loader.loadTestsFromTestCase(TestFrozenAccelerated))
+ return suite
if __name__ == "__main__":
- unittest.main(defaultTest="suite", testRunner=unittest.TextTestRunner(verbosity=2))
+ unittest.main(defaultTest="suite", testRunner=unittest.TextTestRunner(verbosity=2))
http://git-wip-us.apache.org/repos/asf/thrift/blob/10308cb9/test/py/TestServer.py
----------------------------------------------------------------------
diff --git a/test/py/TestServer.py b/test/py/TestServer.py
index f12a9fe..ef93509 100755
--- a/test/py/TestServer.py
+++ b/test/py/TestServer.py
@@ -32,287 +32,287 @@ DEFAULT_LIBDIR_GLOB = os.path.join(ROOT_DIR, 'lib', 'py', 'build', 'lib.*')
class TestHandler(object):
- def testVoid(self):
- if options.verbose > 1:
- logging.info('testVoid()')
-
- def testString(self, str):
- if options.verbose > 1:
- logging.info('testString(%s)' % str)
- return str
-
- def testBool(self, boolean):
- if options.verbose > 1:
- logging.info('testBool(%s)' % str(boolean).lower())
- return boolean
-
- def testByte(self, byte):
- if options.verbose > 1:
- logging.info('testByte(%d)' % byte)
- return byte
-
- def testI16(self, i16):
- if options.verbose > 1:
- logging.info('testI16(%d)' % i16)
- return i16
-
- def testI32(self, i32):
- if options.verbose > 1:
- logging.info('testI32(%d)' % i32)
- return i32
-
- def testI64(self, i64):
- if options.verbose > 1:
- logging.info('testI64(%d)' % i64)
- return i64
-
- def testDouble(self, dub):
- if options.verbose > 1:
- logging.info('testDouble(%f)' % dub)
- return dub
-
- def testBinary(self, thing):
- if options.verbose > 1:
- logging.info('testBinary()') # TODO: hex output
- return thing
-
- def testStruct(self, thing):
- if options.verbose > 1:
- logging.info('testStruct({%s, %s, %s, %s})' % (thing.string_thing, thing.byte_thing, thing.i32_thing, thing.i64_thing))
- return thing
-
- def testException(self, arg):
- # if options.verbose > 1:
- logging.info('testException(%s)' % arg)
- if arg == 'Xception':
- raise Xception(errorCode=1001, message=arg)
- elif arg == 'TException':
- raise TException(message='This is a TException')
-
- def testMultiException(self, arg0, arg1):
- if options.verbose > 1:
- logging.info('testMultiException(%s, %s)' % (arg0, arg1))
- if arg0 == 'Xception':
- raise Xception(errorCode=1001, message='This is an Xception')
- elif arg0 == 'Xception2':
- raise Xception2(
- errorCode=2002,
- struct_thing=Xtruct(string_thing='This is an Xception2'))
- return Xtruct(string_thing=arg1)
-
- def testOneway(self, seconds):
- if options.verbose > 1:
- logging.info('testOneway(%d) => sleeping...' % seconds)
- time.sleep(seconds / 3) # be quick
- if options.verbose > 1:
- logging.info('done sleeping')
-
- def testNest(self, thing):
- if options.verbose > 1:
- logging.info('testNest(%s)' % thing)
- return thing
-
- def testMap(self, thing):
- if options.verbose > 1:
- logging.info('testMap(%s)' % thing)
- return thing
-
- def testStringMap(self, thing):
- if options.verbose > 1:
- logging.info('testStringMap(%s)' % thing)
- return thing
-
- def testSet(self, thing):
- if options.verbose > 1:
- logging.info('testSet(%s)' % thing)
- return thing
-
- def testList(self, thing):
- if options.verbose > 1:
- logging.info('testList(%s)' % thing)
- return thing
-
- def testEnum(self, thing):
- if options.verbose > 1:
- logging.info('testEnum(%s)' % thing)
- return thing
-
- def testTypedef(self, thing):
- if options.verbose > 1:
- logging.info('testTypedef(%s)' % thing)
- return thing
-
- def testMapMap(self, thing):
- if options.verbose > 1:
- logging.info('testMapMap(%s)' % thing)
- return {
- -4: {
- -4: -4,
- -3: -3,
- -2: -2,
- -1: -1,
- },
- 4: {
- 4: 4,
- 3: 3,
- 2: 2,
- 1: 1,
- },
- }
-
- def testInsanity(self, argument):
- if options.verbose > 1:
- logging.info('testInsanity(%s)' % argument)
- return {
- 1: {
- 2: argument,
- 3: argument,
- },
- 2: {6: Insanity()},
- }
-
- def testMulti(self, arg0, arg1, arg2, arg3, arg4, arg5):
- if options.verbose > 1:
- logging.info('testMulti(%s)' % [arg0, arg1, arg2, arg3, arg4, arg5])
- return Xtruct(string_thing='Hello2',
- byte_thing=arg0, i32_thing=arg1, i64_thing=arg2)
+ def testVoid(self):
+ if options.verbose > 1:
+ logging.info('testVoid()')
+
+ def testString(self, str):
+ if options.verbose > 1:
+ logging.info('testString(%s)' % str)
+ return str
+
+ def testBool(self, boolean):
+ if options.verbose > 1:
+ logging.info('testBool(%s)' % str(boolean).lower())
+ return boolean
+
+ def testByte(self, byte):
+ if options.verbose > 1:
+ logging.info('testByte(%d)' % byte)
+ return byte
+
+ def testI16(self, i16):
+ if options.verbose > 1:
+ logging.info('testI16(%d)' % i16)
+ return i16
+
+ def testI32(self, i32):
+ if options.verbose > 1:
+ logging.info('testI32(%d)' % i32)
+ return i32
+
+ def testI64(self, i64):
+ if options.verbose > 1:
+ logging.info('testI64(%d)' % i64)
+ return i64
+
+ def testDouble(self, dub):
+ if options.verbose > 1:
+ logging.info('testDouble(%f)' % dub)
+ return dub
+
+ def testBinary(self, thing):
+ if options.verbose > 1:
+ logging.info('testBinary()') # TODO: hex output
+ return thing
+
+ def testStruct(self, thing):
+ if options.verbose > 1:
+ logging.info('testStruct({%s, %s, %s, %s})' % (thing.string_thing, thing.byte_thing, thing.i32_thing, thing.i64_thing))
+ return thing
+
+ def testException(self, arg):
+ # if options.verbose > 1:
+ logging.info('testException(%s)' % arg)
+ if arg == 'Xception':
+ raise Xception(errorCode=1001, message=arg)
+ elif arg == 'TException':
+ raise TException(message='This is a TException')
+
+ def testMultiException(self, arg0, arg1):
+ if options.verbose > 1:
+ logging.info('testMultiException(%s, %s)' % (arg0, arg1))
+ if arg0 == 'Xception':
+ raise Xception(errorCode=1001, message='This is an Xception')
+ elif arg0 == 'Xception2':
+ raise Xception2(
+ errorCode=2002,
+ struct_thing=Xtruct(string_thing='This is an Xception2'))
+ return Xtruct(string_thing=arg1)
+
+ def testOneway(self, seconds):
+ if options.verbose > 1:
+ logging.info('testOneway(%d) => sleeping...' % seconds)
+ time.sleep(seconds / 3) # be quick
+ if options.verbose > 1:
+ logging.info('done sleeping')
+
+ def testNest(self, thing):
+ if options.verbose > 1:
+ logging.info('testNest(%s)' % thing)
+ return thing
+
+ def testMap(self, thing):
+ if options.verbose > 1:
+ logging.info('testMap(%s)' % thing)
+ return thing
+
+ def testStringMap(self, thing):
+ if options.verbose > 1:
+ logging.info('testStringMap(%s)' % thing)
+ return thing
+
+ def testSet(self, thing):
+ if options.verbose > 1:
+ logging.info('testSet(%s)' % thing)
+ return thing
+
+ def testList(self, thing):
+ if options.verbose > 1:
+ logging.info('testList(%s)' % thing)
+ return thing
+
+ def testEnum(self, thing):
+ if options.verbose > 1:
+ logging.info('testEnum(%s)' % thing)
+ return thing
+
+ def testTypedef(self, thing):
+ if options.verbose > 1:
+ logging.info('testTypedef(%s)' % thing)
+ return thing
+
+ def testMapMap(self, thing):
+ if options.verbose > 1:
+ logging.info('testMapMap(%s)' % thing)
+ return {
+ -4: {
+ -4: -4,
+ -3: -3,
+ -2: -2,
+ -1: -1,
+ },
+ 4: {
+ 4: 4,
+ 3: 3,
+ 2: 2,
+ 1: 1,
+ },
+ }
+
+ def testInsanity(self, argument):
+ if options.verbose > 1:
+ logging.info('testInsanity(%s)' % argument)
+ return {
+ 1: {
+ 2: argument,
+ 3: argument,
+ },
+ 2: {6: Insanity()},
+ }
+
+ def testMulti(self, arg0, arg1, arg2, arg3, arg4, arg5):
+ if options.verbose > 1:
+ logging.info('testMulti(%s)' % [arg0, arg1, arg2, arg3, arg4, arg5])
+ return Xtruct(string_thing='Hello2',
+ byte_thing=arg0, i32_thing=arg1, i64_thing=arg2)
def main(options):
- # set up the protocol factory form the --protocol option
- prot_factories = {
- 'binary': TBinaryProtocol.TBinaryProtocolFactory,
- 'accel': TBinaryProtocol.TBinaryProtocolAcceleratedFactory,
- 'compact': TCompactProtocol.TCompactProtocolFactory,
- 'json': TJSONProtocol.TJSONProtocolFactory,
- }
- pfactory_cls = prot_factories.get(options.proto, None)
- if pfactory_cls is None:
- raise AssertionError('Unknown --protocol option: %s' % options.proto)
- pfactory = pfactory_cls()
- try:
- pfactory.string_length_limit = options.string_limit
- pfactory.container_length_limit = options.container_limit
- except:
- # Ignore errors for those protocols that does not support length limit
- pass
-
- # get the server type (TSimpleServer, TNonblockingServer, etc...)
- if len(args) > 1:
- raise AssertionError('Only one server type may be specified, not multiple types.')
- server_type = args[0]
-
- # Set up the handler and processor objects
- handler = TestHandler()
- processor = ThriftTest.Processor(handler)
-
- # Handle THttpServer as a special case
- if server_type == 'THttpServer':
- server = THttpServer.THttpServer(processor, ('', options.port), pfactory)
- server.serve()
- sys.exit(0)
-
- # set up server transport and transport factory
-
- abs_key_path = os.path.join(os.path.dirname(SCRIPT_DIR), 'keys', 'server.pem')
-
- host = None
- if options.ssl:
- from thrift.transport import TSSLSocket
- transport = TSSLSocket.TSSLServerSocket(host, options.port, certfile=abs_key_path)
- else:
- transport = TSocket.TServerSocket(host, options.port)
- tfactory = TTransport.TBufferedTransportFactory()
- if options.trans == 'buffered':
- tfactory = TTransport.TBufferedTransportFactory()
- elif options.trans == 'framed':
- tfactory = TTransport.TFramedTransportFactory()
- elif options.trans == '':
- raise AssertionError('Unknown --transport option: %s' % options.trans)
- else:
+ # set up the protocol factory form the --protocol option
+ prot_factories = {
+ 'binary': TBinaryProtocol.TBinaryProtocolFactory,
+ 'accel': TBinaryProtocol.TBinaryProtocolAcceleratedFactory,
+ 'compact': TCompactProtocol.TCompactProtocolFactory,
+ 'json': TJSONProtocol.TJSONProtocolFactory,
+ }
+ pfactory_cls = prot_factories.get(options.proto, None)
+ if pfactory_cls is None:
+ raise AssertionError('Unknown --protocol option: %s' % options.proto)
+ pfactory = pfactory_cls()
+ try:
+ pfactory.string_length_limit = options.string_limit
+ pfactory.container_length_limit = options.container_limit
+ except:
+ # Ignore errors for those protocols that does not support length limit
+ pass
+
+ # get the server type (TSimpleServer, TNonblockingServer, etc...)
+ if len(args) > 1:
+ raise AssertionError('Only one server type may be specified, not multiple types.')
+ server_type = args[0]
+
+ # Set up the handler and processor objects
+ handler = TestHandler()
+ processor = ThriftTest.Processor(handler)
+
+ # Handle THttpServer as a special case
+ if server_type == 'THttpServer':
+ server = THttpServer.THttpServer(processor, ('', options.port), pfactory)
+ server.serve()
+ sys.exit(0)
+
+ # set up server transport and transport factory
+
+ abs_key_path = os.path.join(os.path.dirname(SCRIPT_DIR), 'keys', 'server.pem')
+
+ host = None
+ if options.ssl:
+ from thrift.transport import TSSLSocket
+ transport = TSSLSocket.TSSLServerSocket(host, options.port, certfile=abs_key_path)
+ else:
+ transport = TSocket.TServerSocket(host, options.port)
tfactory = TTransport.TBufferedTransportFactory()
- # if --zlib, then wrap server transport, and use a different transport factory
- if options.zlib:
- transport = TZlibTransport.TZlibTransport(transport) # wrap with zlib
- tfactory = TZlibTransport.TZlibTransportFactory()
-
- # do server-specific setup here:
- if server_type == "TNonblockingServer":
- server = TNonblockingServer.TNonblockingServer(processor, transport, inputProtocolFactory=pfactory)
- elif server_type == "TProcessPoolServer":
- import signal
- from thrift.server import TProcessPoolServer
- server = TProcessPoolServer.TProcessPoolServer(processor, transport, tfactory, pfactory)
- server.setNumWorkers(5)
-
- def set_alarm():
- def clean_shutdown(signum, frame):
- for worker in server.workers:
- if options.verbose > 0:
- logging.info('Terminating worker: %s' % worker)
- worker.terminate()
- if options.verbose > 0:
- logging.info('Requesting server to stop()')
- try:
- server.stop()
- except:
- pass
- signal.signal(signal.SIGALRM, clean_shutdown)
- signal.alarm(4)
- set_alarm()
- else:
- # look up server class dynamically to instantiate server
- ServerClass = getattr(TServer, server_type)
- server = ServerClass(processor, transport, tfactory, pfactory)
- # enter server main loop
- server.serve()
+ if options.trans == 'buffered':
+ tfactory = TTransport.TBufferedTransportFactory()
+ elif options.trans == 'framed':
+ tfactory = TTransport.TFramedTransportFactory()
+ elif options.trans == '':
+ raise AssertionError('Unknown --transport option: %s' % options.trans)
+ else:
+ tfactory = TTransport.TBufferedTransportFactory()
+ # if --zlib, then wrap server transport, and use a different transport factory
+ if options.zlib:
+ transport = TZlibTransport.TZlibTransport(transport) # wrap with zlib
+ tfactory = TZlibTransport.TZlibTransportFactory()
+
+ # do server-specific setup here:
+ if server_type == "TNonblockingServer":
+ server = TNonblockingServer.TNonblockingServer(processor, transport, inputProtocolFactory=pfactory)
+ elif server_type == "TProcessPoolServer":
+ import signal
+ from thrift.server import TProcessPoolServer
+ server = TProcessPoolServer.TProcessPoolServer(processor, transport, tfactory, pfactory)
+ server.setNumWorkers(5)
+
+ def set_alarm():
+ def clean_shutdown(signum, frame):
+ for worker in server.workers:
+ if options.verbose > 0:
+ logging.info('Terminating worker: %s' % worker)
+ worker.terminate()
+ if options.verbose > 0:
+ logging.info('Requesting server to stop()')
+ try:
+ server.stop()
+ except:
+ pass
+ signal.signal(signal.SIGALRM, clean_shutdown)
+ signal.alarm(4)
+ set_alarm()
+ else:
+ # look up server class dynamically to instantiate server
+ ServerClass = getattr(TServer, server_type)
+ server = ServerClass(processor, transport, tfactory, pfactory)
+ # enter server main loop
+ server.serve()
if __name__ == '__main__':
- parser = OptionParser()
- parser.add_option('--libpydir', type='string', dest='libpydir',
- help='include this directory to sys.path for locating library code')
- parser.add_option('--genpydir', type='string', dest='genpydir',
- default='gen-py',
- help='include this directory to sys.path for locating generated code')
- parser.add_option("--port", type="int", dest="port",
- help="port number for server to listen on")
- parser.add_option("--zlib", action="store_true", dest="zlib",
- help="use zlib wrapper for compressed transport")
- parser.add_option("--ssl", action="store_true", dest="ssl",
- help="use SSL for encrypted transport")
- 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('--protocol', dest="proto", type="string",
- help="protocol to use, one of: accel, binary, compact, json")
- parser.add_option('--transport', dest="trans", type="string",
- help="transport to use, one of: buffered, framed")
- parser.add_option('--container-limit', dest='container_limit', type='int', default=None)
- parser.add_option('--string-limit', dest='string_limit', type='int', default=None)
- parser.set_defaults(port=9090, verbose=1, proto='binary')
- options, args = parser.parse_args()
-
- # Print TServer log to stdout so that the test-runner can redirect it to log files
- logging.basicConfig(level=options.verbose)
-
- sys.path.insert(0, os.path.join(SCRIPT_DIR, options.genpydir))
- if options.libpydir:
- sys.path.insert(0, glob.glob(options.libpydir)[0])
- else:
- sys.path.insert(0, glob.glob(DEFAULT_LIBDIR_GLOB)[0])
-
- from ThriftTest import ThriftTest
- from ThriftTest.ttypes import Xtruct, Xception, Xception2, Insanity
- from thrift.Thrift import TException
- from thrift.transport import TTransport
- from thrift.transport import TSocket
- from thrift.transport import TZlibTransport
- from thrift.protocol import TBinaryProtocol
- from thrift.protocol import TCompactProtocol
- from thrift.protocol import TJSONProtocol
- from thrift.server import TServer, TNonblockingServer, THttpServer
-
- sys.exit(main(options))
+ parser = OptionParser()
+ parser.add_option('--libpydir', type='string', dest='libpydir',
+ help='include this directory to sys.path for locating library code')
+ parser.add_option('--genpydir', type='string', dest='genpydir',
+ default='gen-py',
+ help='include this directory to sys.path for locating generated code')
+ parser.add_option("--port", type="int", dest="port",
+ help="port number for server to listen on")
+ parser.add_option("--zlib", action="store_true", dest="zlib",
+ help="use zlib wrapper for compressed transport")
+ parser.add_option("--ssl", action="store_true", dest="ssl",
+ help="use SSL for encrypted transport")
+ 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('--protocol', dest="proto", type="string",
+ help="protocol to use, one of: accel, binary, compact, json")
+ parser.add_option('--transport', dest="trans", type="string",
+ help="transport to use, one of: buffered, framed")
+ parser.add_option('--container-limit', dest='container_limit', type='int', default=None)
+ parser.add_option('--string-limit', dest='string_limit', type='int', default=None)
+ parser.set_defaults(port=9090, verbose=1, proto='binary')
+ options, args = parser.parse_args()
+
+ # Print TServer log to stdout so that the test-runner can redirect it to log files
+ logging.basicConfig(level=options.verbose)
+
+ sys.path.insert(0, os.path.join(SCRIPT_DIR, options.genpydir))
+ if options.libpydir:
+ sys.path.insert(0, glob.glob(options.libpydir)[0])
+ else:
+ sys.path.insert(0, glob.glob(DEFAULT_LIBDIR_GLOB)[0])
+
+ from ThriftTest import ThriftTest
+ from ThriftTest.ttypes import Xtruct, Xception, Xception2, Insanity
+ from thrift.Thrift import TException
+ from thrift.transport import TTransport
+ from thrift.transport import TSocket
+ from thrift.transport import TZlibTransport
+ from thrift.protocol import TBinaryProtocol
+ from thrift.protocol import TCompactProtocol
+ from thrift.protocol import TJSONProtocol
+ from thrift.server import TServer, TNonblockingServer, THttpServer
+
+ sys.exit(main(options))
http://git-wip-us.apache.org/repos/asf/thrift/blob/10308cb9/test/py/TestSocket.py
----------------------------------------------------------------------
diff --git a/test/py/TestSocket.py b/test/py/TestSocket.py
index a01be85..9b578cc 100755
--- a/test/py/TestSocket.py
+++ b/test/py/TestSocket.py
@@ -68,10 +68,10 @@ class TimeoutTest(unittest.TestCase):
self.assert_(time.time() - starttime < 5.0)
if __name__ == '__main__':
- suite = unittest.TestSuite()
- loader = unittest.TestLoader()
+ 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/10308cb9/test/test.py
----------------------------------------------------------------------
diff --git a/test/test.py b/test/test.py
index a5bcd9b..42babeb 100755
--- a/test/test.py
+++ b/test/test.py
@@ -46,124 +46,124 @@ CONFIG_FILE = 'tests.json'
def run_cross_tests(server_match, client_match, jobs, skip_known_failures, retry_count):
- logger = multiprocessing.get_logger()
- logger.debug('Collecting tests')
- with open(path_join(TEST_DIR, CONFIG_FILE), 'r') as fp:
- j = json.load(fp)
- tests = crossrunner.collect_cross_tests(j, server_match, client_match)
- if not tests:
- print('No test found that matches the criteria', file=sys.stderr)
- print(' servers: %s' % server_match, file=sys.stderr)
- print(' clients: %s' % client_match, file=sys.stderr)
- return False
- if skip_known_failures:
- logger.debug('Skipping known failures')
- known = crossrunner.load_known_failures(TEST_DIR)
- tests = list(filter(lambda t: crossrunner.test_name(**t) not in known, tests))
-
- dispatcher = crossrunner.TestDispatcher(TEST_DIR, ROOT_DIR, TEST_DIR_RELATIVE, jobs)
- logger.debug('Executing %d tests' % len(tests))
- try:
- for r in [dispatcher.dispatch(test, retry_count) for test in tests]:
- r.wait()
- logger.debug('Waiting for completion')
- return dispatcher.wait()
- except (KeyboardInterrupt, SystemExit):
- logger.debug('Interrupted, shutting down')
- dispatcher.terminate()
- return False
+ logger = multiprocessing.get_logger()
+ logger.debug('Collecting tests')
+ with open(path_join(TEST_DIR, CONFIG_FILE), 'r') as fp:
+ j = json.load(fp)
+ tests = crossrunner.collect_cross_tests(j, server_match, client_match)
+ if not tests:
+ print('No test found that matches the criteria', file=sys.stderr)
+ print(' servers: %s' % server_match, file=sys.stderr)
+ print(' clients: %s' % client_match, file=sys.stderr)
+ return False
+ if skip_known_failures:
+ logger.debug('Skipping known failures')
+ known = crossrunner.load_known_failures(TEST_DIR)
+ tests = list(filter(lambda t: crossrunner.test_name(**t) not in known, tests))
+
+ dispatcher = crossrunner.TestDispatcher(TEST_DIR, ROOT_DIR, TEST_DIR_RELATIVE, jobs)
+ logger.debug('Executing %d tests' % len(tests))
+ try:
+ for r in [dispatcher.dispatch(test, retry_count) for test in tests]:
+ r.wait()
+ logger.debug('Waiting for completion')
+ return dispatcher.wait()
+ except (KeyboardInterrupt, SystemExit):
+ logger.debug('Interrupted, shutting down')
+ dispatcher.terminate()
+ return False
def run_feature_tests(server_match, feature_match, jobs, skip_known_failures, retry_count):
- basedir = path_join(ROOT_DIR, FEATURE_DIR_RELATIVE)
- logger = multiprocessing.get_logger()
- logger.debug('Collecting tests')
- with open(path_join(TEST_DIR, CONFIG_FILE), 'r') as fp:
- j = json.load(fp)
- with open(path_join(basedir, CONFIG_FILE), 'r') as fp:
- j2 = json.load(fp)
- tests = crossrunner.collect_feature_tests(j, j2, server_match, feature_match)
- if not tests:
- print('No test found that matches the criteria', file=sys.stderr)
- print(' servers: %s' % server_match, file=sys.stderr)
- print(' features: %s' % feature_match, file=sys.stderr)
- return False
- if skip_known_failures:
- logger.debug('Skipping known failures')
- known = crossrunner.load_known_failures(basedir)
- tests = list(filter(lambda t: crossrunner.test_name(**t) not in known, tests))
-
- dispatcher = crossrunner.TestDispatcher(TEST_DIR, ROOT_DIR, FEATURE_DIR_RELATIVE, jobs)
- logger.debug('Executing %d tests' % len(tests))
- try:
- for r in [dispatcher.dispatch(test, retry_count) for test in tests]:
- r.wait()
- logger.debug('Waiting for completion')
- return dispatcher.wait()
- except (KeyboardInterrupt, SystemExit):
- logger.debug('Interrupted, shutting down')
- dispatcher.terminate()
- return False
+ basedir = path_join(ROOT_DIR, FEATURE_DIR_RELATIVE)
+ logger = multiprocessing.get_logger()
+ logger.debug('Collecting tests')
+ with open(path_join(TEST_DIR, CONFIG_FILE), 'r') as fp:
+ j = json.load(fp)
+ with open(path_join(basedir, CONFIG_FILE), 'r') as fp:
+ j2 = json.load(fp)
+ tests = crossrunner.collect_feature_tests(j, j2, server_match, feature_match)
+ if not tests:
+ print('No test found that matches the criteria', file=sys.stderr)
+ print(' servers: %s' % server_match, file=sys.stderr)
+ print(' features: %s' % feature_match, file=sys.stderr)
+ return False
+ if skip_known_failures:
+ logger.debug('Skipping known failures')
+ known = crossrunner.load_known_failures(basedir)
+ tests = list(filter(lambda t: crossrunner.test_name(**t) not in known, tests))
+
+ dispatcher = crossrunner.TestDispatcher(TEST_DIR, ROOT_DIR, FEATURE_DIR_RELATIVE, jobs)
+ logger.debug('Executing %d tests' % len(tests))
+ try:
+ for r in [dispatcher.dispatch(test, retry_count) for test in tests]:
+ r.wait()
+ logger.debug('Waiting for completion')
+ return dispatcher.wait()
+ except (KeyboardInterrupt, SystemExit):
+ logger.debug('Interrupted, shutting down')
+ dispatcher.terminate()
+ return False
def default_concurrenty():
- try:
- return int(os.environ.get('THRIFT_CROSSTEST_CONCURRENCY'))
- except (TypeError, ValueError):
- # Since much time is spent sleeping, use many threads
- return int(multiprocessing.cpu_count() * 1.25) + 1
+ try:
+ return int(os.environ.get('THRIFT_CROSSTEST_CONCURRENCY'))
+ except (TypeError, ValueError):
+ # Since much time is spent sleeping, use many threads
+ return int(multiprocessing.cpu_count() * 1.25) + 1
def main(argv):
- parser = argparse.ArgumentParser()
- parser.add_argument('--server', default='', nargs='*',
- help='list of servers to test')
- parser.add_argument('--client', default='', nargs='*',
- help='list of clients to test')
- parser.add_argument('-F', '--features', nargs='*', default=None,
- help='run server feature tests instead of cross language tests')
- parser.add_argument('-s', '--skip-known-failures', action='store_true', dest='skip_known_failures',
- help='do not execute tests that are known to fail')
- parser.add_argument('-r', '--retry-count', type=int,
- default=0, help='maximum retry on failure')
- parser.add_argument('-j', '--jobs', type=int,
- default=default_concurrenty(),
- help='number of concurrent test executions')
-
- g = parser.add_argument_group(title='Advanced')
- g.add_argument('-v', '--verbose', action='store_const',
- dest='log_level', const=logging.DEBUG, default=logging.WARNING,
- help='show debug output for test runner')
- g.add_argument('-P', '--print-expected-failures', choices=['merge', 'overwrite'],
- dest='print_failures',
- help="generate expected failures based on last result and print to stdout")
- g.add_argument('-U', '--update-expected-failures', choices=['merge', 'overwrite'],
- dest='update_failures',
- help="generate expected failures based on last result and save to default file location")
- options = parser.parse_args(argv)
-
- logger = multiprocessing.log_to_stderr()
- logger.setLevel(options.log_level)
-
- if options.features is not None and options.client:
- print('Cannot specify both --features and --client ', file=sys.stderr)
- return 1
-
- # Allow multiple args separated with ',' for backward compatibility
- server_match = list(chain(*[x.split(',') for x in options.server]))
- client_match = list(chain(*[x.split(',') for x in options.client]))
-
- if options.update_failures or options.print_failures:
- dire = path_join(ROOT_DIR, FEATURE_DIR_RELATIVE) if options.features is not None else TEST_DIR
- res = crossrunner.generate_known_failures(
- dire, options.update_failures == 'overwrite',
- options.update_failures, options.print_failures)
- elif options.features is not None:
- features = options.features or ['.*']
- res = run_feature_tests(server_match, features, options.jobs, options.skip_known_failures, options.retry_count)
- else:
- res = run_cross_tests(server_match, client_match, options.jobs, options.skip_known_failures, options.retry_count)
- return 0 if res else 1
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--server', default='', nargs='*',
+ help='list of servers to test')
+ parser.add_argument('--client', default='', nargs='*',
+ help='list of clients to test')
+ parser.add_argument('-F', '--features', nargs='*', default=None,
+ help='run server feature tests instead of cross language tests')
+ parser.add_argument('-s', '--skip-known-failures', action='store_true', dest='skip_known_failures',
+ help='do not execute tests that are known to fail')
+ parser.add_argument('-r', '--retry-count', type=int,
+ default=0, help='maximum retry on failure')
+ parser.add_argument('-j', '--jobs', type=int,
+ default=default_concurrenty(),
+ help='number of concurrent test executions')
+
+ g = parser.add_argument_group(title='Advanced')
+ g.add_argument('-v', '--verbose', action='store_const',
+ dest='log_level', const=logging.DEBUG, default=logging.WARNING,
+ help='show debug output for test runner')
+ g.add_argument('-P', '--print-expected-failures', choices=['merge', 'overwrite'],
+ dest='print_failures',
+ help="generate expected failures based on last result and print to stdout")
+ g.add_argument('-U', '--update-expected-failures', choices=['merge', 'overwrite'],
+ dest='update_failures',
+ help="generate expected failures based on last result and save to default file location")
+ options = parser.parse_args(argv)
+
+ logger = multiprocessing.log_to_stderr()
+ logger.setLevel(options.log_level)
+
+ if options.features is not None and options.client:
+ print('Cannot specify both --features and --client ', file=sys.stderr)
+ return 1
+
+ # Allow multiple args separated with ',' for backward compatibility
+ server_match = list(chain(*[x.split(',') for x in options.server]))
+ client_match = list(chain(*[x.split(',') for x in options.client]))
+
+ if options.update_failures or options.print_failures:
+ dire = path_join(ROOT_DIR, FEATURE_DIR_RELATIVE) if options.features is not None else TEST_DIR
+ res = crossrunner.generate_known_failures(
+ dire, options.update_failures == 'overwrite',
+ options.update_failures, options.print_failures)
+ elif options.features is not None:
+ features = options.features or ['.*']
+ res = run_feature_tests(server_match, features, options.jobs, options.skip_known_failures, options.retry_count)
+ else:
+ res = run_cross_tests(server_match, client_match, options.jobs, options.skip_known_failures, options.retry_count)
+ return 0 if res else 1
if __name__ == '__main__':
- sys.exit(main(sys.argv[1:]))
+ sys.exit(main(sys.argv[1:]))
http://git-wip-us.apache.org/repos/asf/thrift/blob/10308cb9/tutorial/php/runserver.py
----------------------------------------------------------------------
diff --git a/tutorial/php/runserver.py b/tutorial/php/runserver.py
index ae29fed..077daa1 100755
--- a/tutorial/php/runserver.py
+++ b/tutorial/php/runserver.py
@@ -26,7 +26,8 @@ import CGIHTTPServer
# chdir(2) into the tutorial directory.
os.chdir(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
+
class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
- cgi_directories = ['/php']
+ cgi_directories = ['/php']
BaseHTTPServer.HTTPServer(('', 8080), Handler).serve_forever()