2007-02-28 21:43:54 +00:00
|
|
|
|
#!/usr/bin/env python
|
2015-10-09 17:12:48 +00:00
|
|
|
|
# -*- coding: utf-8 -*-
|
2009-03-30 21:35:00 +00:00
|
|
|
|
#
|
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
|
# or more contributor license agreements. See the NOTICE file
|
|
|
|
|
# distributed with this work for additional information
|
|
|
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
|
|
|
# to you under the Apache License, Version 2.0 (the
|
|
|
|
|
# "License"); you may not use this file except in compliance
|
|
|
|
|
# with the License. You may obtain a copy of the License at
|
|
|
|
|
#
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
#
|
|
|
|
|
# Unless required by applicable law or agreed to in writing,
|
|
|
|
|
# software distributed under the License is distributed on an
|
|
|
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
|
# KIND, either express or implied. See the License for the
|
|
|
|
|
# specific language governing permissions and limitations
|
|
|
|
|
# under the License.
|
|
|
|
|
#
|
|
|
|
|
|
2015-09-23 19:16:50 +00:00
|
|
|
|
import glob
|
|
|
|
|
import os
|
|
|
|
|
import sys
|
2007-02-28 21:43:54 +00:00
|
|
|
|
import time
|
2015-09-23 19:16:50 +00:00
|
|
|
|
import unittest
|
2007-10-05 00:13:24 +00:00
|
|
|
|
from optparse import OptionParser
|
2007-02-28 21:43:54 +00:00
|
|
|
|
|
2015-11-06 12:24:24 +00:00
|
|
|
|
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.*')
|
2011-09-11 18:16:21 +00:00
|
|
|
|
|
2015-09-23 19:16:50 +00:00
|
|
|
|
|
2007-10-05 00:13:24 +00:00
|
|
|
|
class AbstractTest(unittest.TestCase):
|
|
|
|
|
def setUp(self):
|
2009-01-31 21:59:32 +00:00
|
|
|
|
if options.http_path:
|
2011-03-22 18:06:04 +00:00
|
|
|
|
self.transport = THttpClient.THttpClient(options.host, port=options.port, path=options.http_path)
|
2007-10-05 00:13:24 +00:00
|
|
|
|
else:
|
2011-03-22 18:06:04 +00:00
|
|
|
|
if options.ssl:
|
|
|
|
|
from thrift.transport import TSSLSocket
|
|
|
|
|
socket = TSSLSocket.TSSLSocket(options.host, options.port, validate=False)
|
|
|
|
|
else:
|
|
|
|
|
socket = TSocket.TSocket(options.host, options.port)
|
2009-01-31 21:59:32 +00:00
|
|
|
|
# frame or buffer depending upon args
|
2014-05-31 20:22:07 +00:00
|
|
|
|
self.transport = TTransport.TBufferedTransport(socket)
|
|
|
|
|
if options.trans == 'framed':
|
2009-01-31 21:59:32 +00:00
|
|
|
|
self.transport = TTransport.TFramedTransport(socket)
|
2014-05-31 20:22:07 +00:00
|
|
|
|
elif options.trans == 'buffered':
|
2009-01-31 21:59:32 +00:00
|
|
|
|
self.transport = TTransport.TBufferedTransport(socket)
|
2014-05-31 20:22:07 +00:00
|
|
|
|
elif options.trans == '':
|
|
|
|
|
raise AssertionError('Unknown --transport option: %s' % options.trans)
|
2011-03-22 18:06:04 +00:00
|
|
|
|
if options.zlib:
|
|
|
|
|
self.transport = TZlibTransport.TZlibTransport(self.transport, 9)
|
2007-10-05 00:13:24 +00:00
|
|
|
|
self.transport.open()
|
2015-11-06 12:24:24 +00:00
|
|
|
|
protocol = self.get_protocol(self.transport)
|
2014-07-10 03:37:12 +00:00
|
|
|
|
self.client = ThriftTest.Client(protocol)
|
2008-02-06 22:18:40 +00:00
|
|
|
|
|
2007-10-05 00:13:24 +00:00
|
|
|
|
def tearDown(self):
|
|
|
|
|
self.transport.close()
|
|
|
|
|
|
|
|
|
|
def testVoid(self):
|
2015-09-23 19:16:50 +00:00
|
|
|
|
print('testVoid')
|
2007-10-05 00:13:24 +00:00
|
|
|
|
self.client.testVoid()
|
2008-02-06 22:18:40 +00:00
|
|
|
|
|
2007-10-05 00:13:24 +00:00
|
|
|
|
def testString(self):
|
2015-09-23 19:16:50 +00:00
|
|
|
|
print('testString')
|
2011-03-22 18:06:04 +00:00
|
|
|
|
self.assertEqual(self.client.testString('Python' * 20), 'Python' * 20)
|
2011-03-21 17:38:22 +00:00
|
|
|
|
self.assertEqual(self.client.testString(''), '')
|
2015-11-06 12:24:16 +00:00
|
|
|
|
s1 = u'\b\t\n/\\\\\r{}:パイソン"'
|
|
|
|
|
s2 = u"""Afrikaans, Alemannisch, Aragonés, العربية, مصرى,
|
2015-10-09 17:12:48 +00:00
|
|
|
|
Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška,
|
|
|
|
|
Беларуская, Беларуская (тарашкевіца), Български, Bamanankan,
|
|
|
|
|
বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн,
|
|
|
|
|
Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg,
|
|
|
|
|
Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English,
|
|
|
|
|
Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt,
|
|
|
|
|
Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego,
|
|
|
|
|
Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski,
|
|
|
|
|
Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia,
|
|
|
|
|
Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa,
|
|
|
|
|
ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар,
|
|
|
|
|
Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino,
|
|
|
|
|
Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa
|
|
|
|
|
Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa
|
|
|
|
|
Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands,
|
|
|
|
|
Norsk (nynorsk), Norsk (bokmål), Nouormand, Diné bizaad,
|
|
|
|
|
Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو,
|
|
|
|
|
Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română,
|
|
|
|
|
Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple
|
|
|
|
|
English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk,
|
|
|
|
|
Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog,
|
|
|
|
|
Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük,
|
|
|
|
|
Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文,
|
|
|
|
|
Bân-lâm-gú, 粵語"""
|
2016-01-06 11:44:17 +00:00
|
|
|
|
if sys.version_info[0] == 2 and os.environ.get('THRIFT_TEST_PY_NO_UTF8STRINGS'):
|
2015-11-06 12:24:16 +00:00
|
|
|
|
s1 = s1.encode('utf8')
|
|
|
|
|
s2 = s2.encode('utf8')
|
|
|
|
|
self.assertEqual(self.client.testString(s1), s1)
|
|
|
|
|
self.assertEqual(self.client.testString(s2), s2)
|
2007-10-05 00:13:24 +00:00
|
|
|
|
|
2015-09-21 04:53:25 +00:00
|
|
|
|
def testBool(self):
|
2015-09-23 19:16:50 +00:00
|
|
|
|
print('testBool')
|
2015-09-21 04:53:25 +00:00
|
|
|
|
self.assertEqual(self.client.testBool(True), True)
|
|
|
|
|
self.assertEqual(self.client.testBool(False), False)
|
|
|
|
|
|
2007-10-05 00:13:24 +00:00
|
|
|
|
def testByte(self):
|
2015-09-23 19:16:50 +00:00
|
|
|
|
print('testByte')
|
2007-10-05 00:13:24 +00:00
|
|
|
|
self.assertEqual(self.client.testByte(63), 63)
|
2011-03-21 17:38:22 +00:00
|
|
|
|
self.assertEqual(self.client.testByte(-127), -127)
|
2007-10-05 00:13:24 +00:00
|
|
|
|
|
|
|
|
|
def testI32(self):
|
2015-09-23 19:16:50 +00:00
|
|
|
|
print('testI32')
|
2007-10-05 00:13:24 +00:00
|
|
|
|
self.assertEqual(self.client.testI32(-1), -1)
|
|
|
|
|
self.assertEqual(self.client.testI32(0), 0)
|
|
|
|
|
|
|
|
|
|
def testI64(self):
|
2015-09-23 19:16:50 +00:00
|
|
|
|
print('testI64')
|
2011-03-21 17:38:22 +00:00
|
|
|
|
self.assertEqual(self.client.testI64(1), 1)
|
2007-10-05 00:13:24 +00:00
|
|
|
|
self.assertEqual(self.client.testI64(-34359738368), -34359738368)
|
|
|
|
|
|
|
|
|
|
def testDouble(self):
|
2015-09-23 19:16:50 +00:00
|
|
|
|
print('testDouble')
|
2007-10-05 00:13:24 +00:00
|
|
|
|
self.assertEqual(self.client.testDouble(-5.235098235), -5.235098235)
|
2011-03-21 17:38:22 +00:00
|
|
|
|
self.assertEqual(self.client.testDouble(0), 0)
|
|
|
|
|
self.assertEqual(self.client.testDouble(-1), -1)
|
2015-10-09 18:11:49 +00:00
|
|
|
|
self.assertEqual(self.client.testDouble(-0.000341012439638598279), -0.000341012439638598279)
|
2007-10-05 00:13:24 +00:00
|
|
|
|
|
2015-09-23 19:16:50 +00:00
|
|
|
|
def testBinary(self):
|
|
|
|
|
print('testBinary')
|
|
|
|
|
val = bytearray([i for i in range(0, 256)])
|
|
|
|
|
self.assertEqual(bytearray(self.client.testBinary(bytes(val))), val)
|
|
|
|
|
|
2007-10-05 00:13:24 +00:00
|
|
|
|
def testStruct(self):
|
2015-09-23 19:16:50 +00:00
|
|
|
|
print('testStruct')
|
2007-10-05 00:13:24 +00:00
|
|
|
|
x = Xtruct()
|
|
|
|
|
x.string_thing = "Zero"
|
|
|
|
|
x.byte_thing = 1
|
|
|
|
|
x.i32_thing = -3
|
|
|
|
|
x.i64_thing = -5
|
|
|
|
|
y = self.client.testStruct(x)
|
2011-03-21 17:38:22 +00:00
|
|
|
|
self.assertEqual(y, x)
|
|
|
|
|
|
|
|
|
|
def testNest(self):
|
2015-09-23 19:16:50 +00:00
|
|
|
|
print('testNest')
|
|
|
|
|
inner = Xtruct(string_thing="Zero", byte_thing=1, i32_thing=-3, i64_thing=-5)
|
2012-11-02 00:05:42 +00:00
|
|
|
|
x = Xtruct2(struct_thing=inner, byte_thing=0, i32_thing=0)
|
2011-03-21 17:38:22 +00:00
|
|
|
|
y = self.client.testNest(x)
|
|
|
|
|
self.assertEqual(y, x)
|
|
|
|
|
|
|
|
|
|
def testMap(self):
|
2015-09-23 19:16:50 +00:00
|
|
|
|
print('testMap')
|
2015-11-06 12:24:24 +00:00
|
|
|
|
x = {0: 1, 1: 2, 2: 3, 3: 4, -1: -2}
|
2011-03-21 17:38:22 +00:00
|
|
|
|
y = self.client.testMap(x)
|
|
|
|
|
self.assertEqual(y, x)
|
|
|
|
|
|
|
|
|
|
def testSet(self):
|
2015-09-23 19:16:50 +00:00
|
|
|
|
print('testSet')
|
2011-03-21 17:38:22 +00:00
|
|
|
|
x = set([8, 1, 42])
|
|
|
|
|
y = self.client.testSet(x)
|
|
|
|
|
self.assertEqual(y, x)
|
|
|
|
|
|
|
|
|
|
def testList(self):
|
2015-09-23 19:16:50 +00:00
|
|
|
|
print('testList')
|
2011-03-21 17:38:22 +00:00
|
|
|
|
x = [1, 4, 9, -42]
|
|
|
|
|
y = self.client.testList(x)
|
|
|
|
|
self.assertEqual(y, x)
|
|
|
|
|
|
|
|
|
|
def testEnum(self):
|
2015-09-28 17:16:53 +00:00
|
|
|
|
print('testEnum')
|
2011-03-21 17:38:22 +00:00
|
|
|
|
x = Numberz.FIVE
|
|
|
|
|
y = self.client.testEnum(x)
|
|
|
|
|
self.assertEqual(y, x)
|
|
|
|
|
|
|
|
|
|
def testTypedef(self):
|
2015-09-28 17:16:53 +00:00
|
|
|
|
print('testTypedef')
|
2015-11-06 12:24:24 +00:00
|
|
|
|
x = 0xffffffffffffff # 7 bytes of 0xff
|
2011-03-21 17:38:22 +00:00
|
|
|
|
y = self.client.testTypedef(x)
|
|
|
|
|
self.assertEqual(y, x)
|
|
|
|
|
|
|
|
|
|
def testMapMap(self):
|
2015-09-28 17:16:53 +00:00
|
|
|
|
print('testMapMap')
|
2015-11-17 02:01:41 +00:00
|
|
|
|
x = {
|
|
|
|
|
-4: {-4: -4, -3: -3, -2: -2, -1: -1},
|
|
|
|
|
4: {4: 4, 3: 3, 2: 2, 1: 1},
|
|
|
|
|
}
|
|
|
|
|
y = self.client.testMapMap(42)
|
2015-09-28 17:16:53 +00:00
|
|
|
|
self.assertEqual(y, x)
|
2007-10-05 00:13:24 +00:00
|
|
|
|
|
2011-03-21 17:38:22 +00:00
|
|
|
|
def testMulti(self):
|
2015-09-28 17:16:53 +00:00
|
|
|
|
print('testMulti')
|
2012-11-02 00:05:42 +00:00
|
|
|
|
xpected = Xtruct(string_thing='Hello2', byte_thing=74, i32_thing=0xff00ff, i64_thing=0xffffffffd0d0)
|
2011-03-21 17:38:22 +00:00
|
|
|
|
y = self.client.testMulti(xpected.byte_thing,
|
2015-11-06 12:24:24 +00:00
|
|
|
|
xpected.i32_thing,
|
|
|
|
|
xpected.i64_thing,
|
|
|
|
|
{0: 'abc'},
|
|
|
|
|
Numberz.FIVE,
|
|
|
|
|
0xf0f0f0)
|
2011-03-21 17:38:22 +00:00
|
|
|
|
self.assertEqual(y, xpected)
|
2007-10-05 00:13:24 +00:00
|
|
|
|
|
|
|
|
|
def testException(self):
|
2015-09-28 17:16:53 +00:00
|
|
|
|
print('testException')
|
2007-10-05 00:13:24 +00:00
|
|
|
|
self.client.testException('Safe')
|
|
|
|
|
try:
|
|
|
|
|
self.client.testException('Xception')
|
|
|
|
|
self.fail("should have gotten exception")
|
2015-09-28 17:16:53 +00:00
|
|
|
|
except Xception as x:
|
2007-10-05 00:13:24 +00:00
|
|
|
|
self.assertEqual(x.errorCode, 1001)
|
|
|
|
|
self.assertEqual(x.message, 'Xception')
|
2011-11-01 21:03:33 +00:00
|
|
|
|
# TODO ensure same behavior for repr within generated python variants
|
2011-09-11 18:16:21 +00:00
|
|
|
|
# ensure exception's repr method works
|
2015-11-06 12:24:24 +00:00
|
|
|
|
# x_repr = repr(x)
|
|
|
|
|
# self.assertEqual(x_repr, 'Xception(errorCode=1001, message=\'Xception\')')
|
2007-10-05 00:13:24 +00:00
|
|
|
|
|
2008-06-10 22:55:26 +00:00
|
|
|
|
try:
|
2015-09-28 17:16:53 +00:00
|
|
|
|
self.client.testException('TException')
|
|
|
|
|
self.fail("should have gotten exception")
|
|
|
|
|
except TException as x:
|
2008-06-10 22:55:26 +00:00
|
|
|
|
pass
|
|
|
|
|
|
2015-09-28 17:16:53 +00:00
|
|
|
|
# Should not throw
|
|
|
|
|
self.client.testException('success')
|
|
|
|
|
|
|
|
|
|
def testMultiException(self):
|
|
|
|
|
print('testMultiException')
|
|
|
|
|
try:
|
|
|
|
|
self.client.testMultiException('Xception', 'ignore')
|
|
|
|
|
except Xception as ex:
|
|
|
|
|
self.assertEqual(ex.errorCode, 1001)
|
|
|
|
|
self.assertEqual(ex.message, 'This is an Xception')
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
self.client.testMultiException('Xception2', 'ignore')
|
|
|
|
|
except Xception2 as ex:
|
|
|
|
|
self.assertEqual(ex.errorCode, 2002)
|
|
|
|
|
self.assertEqual(ex.struct_thing.string_thing, 'This is an Xception2')
|
|
|
|
|
|
|
|
|
|
y = self.client.testMultiException('success', 'foobar')
|
|
|
|
|
self.assertEqual(y.string_thing, 'foobar')
|
|
|
|
|
|
2009-03-24 20:01:58 +00:00
|
|
|
|
def testOneway(self):
|
2015-09-28 17:16:53 +00:00
|
|
|
|
print('testOneway')
|
2008-02-18 02:11:48 +00:00
|
|
|
|
start = time.time()
|
2015-11-06 12:24:24 +00:00
|
|
|
|
self.client.testOneway(1) # type is int, not float
|
2008-02-18 02:11:48 +00:00
|
|
|
|
end = time.time()
|
2011-03-21 17:38:22 +00:00
|
|
|
|
self.assertTrue(end - start < 3,
|
2009-03-24 20:01:58 +00:00
|
|
|
|
"oneway sleep took %f sec" % (end - start))
|
2014-05-31 20:22:07 +00:00
|
|
|
|
|
2009-12-03 01:18:44 +00:00
|
|
|
|
def testOnewayThenNormal(self):
|
2015-09-28 17:16:53 +00:00
|
|
|
|
print('testOnewayThenNormal')
|
2015-11-06 12:24:24 +00:00
|
|
|
|
self.client.testOneway(1) # type is int, not float
|
2009-12-03 01:18:44 +00:00
|
|
|
|
self.assertEqual(self.client.testString('Python'), 'Python')
|
2008-02-18 02:11:48 +00:00
|
|
|
|
|
2014-05-03 15:51:21 +00:00
|
|
|
|
|
2007-10-05 00:13:24 +00:00
|
|
|
|
class NormalBinaryTest(AbstractTest):
|
2015-11-06 12:24:24 +00:00
|
|
|
|
def get_protocol(self, transport):
|
|
|
|
|
return TBinaryProtocol.TBinaryProtocolFactory().getProtocol(transport)
|
2007-10-05 00:13:24 +00:00
|
|
|
|
|
2015-11-06 12:24:16 +00:00
|
|
|
|
|
2011-03-21 17:38:22 +00:00
|
|
|
|
class CompactTest(AbstractTest):
|
2015-11-06 12:24:24 +00:00
|
|
|
|
def get_protocol(self, transport):
|
|
|
|
|
return TCompactProtocol.TCompactProtocolFactory().getProtocol(transport)
|
2011-03-21 17:38:22 +00:00
|
|
|
|
|
2015-11-06 12:24:16 +00:00
|
|
|
|
|
2012-11-02 00:05:42 +00:00
|
|
|
|
class JSONTest(AbstractTest):
|
2015-11-06 12:24:24 +00:00
|
|
|
|
def get_protocol(self, transport):
|
|
|
|
|
return TJSONProtocol.TJSONProtocolFactory().getProtocol(transport)
|
2012-11-02 00:05:42 +00:00
|
|
|
|
|
2015-11-06 12:24:16 +00:00
|
|
|
|
|
2007-10-05 00:13:24 +00:00
|
|
|
|
class AcceleratedBinaryTest(AbstractTest):
|
2015-11-06 12:24:24 +00:00
|
|
|
|
def get_protocol(self, transport):
|
|
|
|
|
return TBinaryProtocol.TBinaryProtocolAcceleratedFactory().getProtocol(transport)
|
2007-10-05 00:13:24 +00:00
|
|
|
|
|
2015-11-06 12:24:16 +00:00
|
|
|
|
|
2008-02-15 01:10:23 +00:00
|
|
|
|
def suite():
|
|
|
|
|
suite = unittest.TestSuite()
|
|
|
|
|
loader = unittest.TestLoader()
|
2015-11-06 12:24:16 +00:00
|
|
|
|
if options.proto == 'binary': # look for --proto on cmdline
|
2011-03-21 17:38:22 +00:00
|
|
|
|
suite.addTest(loader.loadTestsFromTestCase(NormalBinaryTest))
|
|
|
|
|
elif options.proto == 'accel':
|
|
|
|
|
suite.addTest(loader.loadTestsFromTestCase(AcceleratedBinaryTest))
|
|
|
|
|
elif options.proto == 'compact':
|
|
|
|
|
suite.addTest(loader.loadTestsFromTestCase(CompactTest))
|
2012-11-02 00:05:42 +00:00
|
|
|
|
elif options.proto == 'json':
|
|
|
|
|
suite.addTest(loader.loadTestsFromTestCase(JSONTest))
|
2011-03-21 17:38:22 +00:00
|
|
|
|
else:
|
2014-05-31 20:22:07 +00:00
|
|
|
|
raise AssertionError('Unknown protocol given with --protocol: %s' % options.proto)
|
2008-02-15 01:10:23 +00:00
|
|
|
|
return suite
|
2007-10-05 00:13:24 +00:00
|
|
|
|
|
2015-11-06 12:24:16 +00:00
|
|
|
|
|
2008-11-07 23:09:31 +00:00
|
|
|
|
class OwnArgsTestProgram(unittest.TestProgram):
|
|
|
|
|
def parseArgs(self, argv):
|
|
|
|
|
if args:
|
|
|
|
|
self.testNames = args
|
|
|
|
|
else:
|
2015-11-06 12:24:24 +00:00
|
|
|
|
self.testNames = ([self.defaultTest])
|
2008-11-07 23:09:31 +00:00
|
|
|
|
self.createTests()
|
|
|
|
|
|
2008-02-15 01:10:23 +00:00
|
|
|
|
if __name__ == "__main__":
|
2015-11-06 12:24:24 +00:00
|
|
|
|
parser = OptionParser()
|
|
|
|
|
parser.add_option('--libpydir', type='string', dest='libpydir',
|
|
|
|
|
help='include this directory in sys.path for locating library code')
|
|
|
|
|
parser.add_option('--genpydir', type='string', dest='genpydir',
|
|
|
|
|
help='include this directory in sys.path for locating generated code')
|
|
|
|
|
parser.add_option("--port", type="int", dest="port",
|
|
|
|
|
help="connect to server at port")
|
|
|
|
|
parser.add_option("--host", type="string", dest="host",
|
|
|
|
|
help="connect to server")
|
|
|
|
|
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("--http", dest="http_path",
|
|
|
|
|
help="Use the HTTP transport with the specified path")
|
|
|
|
|
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.set_defaults(framed=False, http_path=None, verbose=1, host='localhost', port=9090, proto='binary')
|
|
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
|
2016-01-06 11:44:17 +00:00
|
|
|
|
if options.genpydir:
|
|
|
|
|
sys.path.insert(0, os.path.join(SCRIPT_DIR, options.genpydir))
|
2015-11-06 12:24:24 +00:00
|
|
|
|
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, Xtruct2, Numberz, Xception, Xception2
|
|
|
|
|
from thrift.Thrift import TException
|
|
|
|
|
from thrift.transport import TTransport
|
|
|
|
|
from thrift.transport import TSocket
|
|
|
|
|
from thrift.transport import THttpClient
|
|
|
|
|
from thrift.transport import TZlibTransport
|
|
|
|
|
from thrift.protocol import TBinaryProtocol
|
|
|
|
|
from thrift.protocol import TCompactProtocol
|
|
|
|
|
from thrift.protocol import TJSONProtocol
|
|
|
|
|
|
2011-09-11 18:16:21 +00:00
|
|
|
|
OwnArgsTestProgram(defaultTest="suite", testRunner=unittest.TextTestRunner(verbosity=1))
|