blob: 21641622808cc8fd5f6bc89b25c3e9c64a41887a [file] [log] [blame]
Mark Slee57cc25e2007-02-28 21:43:54 +00001#!/usr/bin/env python
Nobuaki Sukegawa64b8f6c2015-10-10 02:12:48 +09002# -*- coding: utf-8 -*-
David Reissea2cba82009-03-30 21:35:00 +00003#
4# Licensed to the Apache Software Foundation (ASF) under one
5# or more contributor license agreements. See the NOTICE file
6# distributed with this work for additional information
7# regarding copyright ownership. The ASF licenses this file
8# to you under the Apache License, Version 2.0 (the
9# "License"); you may not use this file except in compliance
10# with the License. You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing,
15# software distributed under the License is distributed on an
16# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17# KIND, either express or implied. See the License for the
18# specific language governing permissions and limitations
19# under the License.
20#
21
Jens Geyerd629ea02015-09-23 21:16:50 +020022import os
23import sys
Mark Slee57cc25e2007-02-28 21:43:54 +000024import time
Jens Geyerd629ea02015-09-23 21:16:50 +020025import unittest
Mark Slee5299a952007-10-05 00:13:24 +000026from optparse import OptionParser
Mark Slee57cc25e2007-02-28 21:43:54 +000027
Nobuaki Sukegawa7af189a2016-02-11 16:21:01 +090028from util import local_libpath
29
Nobuaki Sukegawaa185d7e2015-11-06 21:24:24 +090030SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
Roger Meierf4eec7a2011-09-11 18:16:21 +000031
Jens Geyerd629ea02015-09-23 21:16:50 +020032
Mark Slee5299a952007-10-05 00:13:24 +000033class AbstractTest(unittest.TestCase):
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090034 def setUp(self):
James E. King III6f8c99e2018-03-24 16:32:02 -040035 if options.trans == 'http':
36 uri = '{0}://{1}:{2}{3}'.format(('https' if options.ssl else 'http'),
37 options.host,
38 options.port,
39 (options.http_path if options.http_path else '/'))
40 if options.ssl:
41 __cafile = os.path.join(os.path.dirname(SCRIPT_DIR), "keys", "CA.pem")
42 __certfile = os.path.join(os.path.dirname(SCRIPT_DIR), "keys", "client.crt")
43 __keyfile = os.path.join(os.path.dirname(SCRIPT_DIR), "keys", "client.key")
44 self.transport = THttpClient.THttpClient(uri, cafile=__cafile, cert_file=__certfile, key_file=__keyfile)
45 else:
46 self.transport = THttpClient.THttpClient(uri)
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090047 else:
48 if options.ssl:
49 from thrift.transport import TSSLSocket
50 socket = TSSLSocket.TSSLSocket(options.host, options.port, validate=False)
51 else:
52 socket = TSocket.TSocket(options.host, options.port)
53 # frame or buffer depending upon args
54 self.transport = TTransport.TBufferedTransport(socket)
55 if options.trans == 'framed':
56 self.transport = TTransport.TFramedTransport(socket)
57 elif options.trans == 'buffered':
58 self.transport = TTransport.TBufferedTransport(socket)
59 elif options.trans == '':
60 raise AssertionError('Unknown --transport option: %s' % options.trans)
61 if options.zlib:
62 self.transport = TZlibTransport.TZlibTransport(self.transport, 9)
63 self.transport.open()
64 protocol = self.get_protocol(self.transport)
65 self.client = ThriftTest.Client(protocol)
James E. King III20685442018-04-10 10:30:51 -040066 # for multiplexed services:
67 protocol2 = self.get_protocol2(self.transport)
68 self.client2 = SecondService.Client(protocol2) if protocol2 is not None else None
David Reiss0c90f6f2008-02-06 22:18:40 +000069
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090070 def tearDown(self):
71 self.transport.close()
Mark Sleefc89d392006-09-04 00:04:39 +000072
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090073 def testVoid(self):
74 print('testVoid')
75 self.client.testVoid()
David Reiss0c90f6f2008-02-06 22:18:40 +000076
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +090077 def testString(self):
78 print('testString')
79 self.assertEqual(self.client.testString('Python' * 20), 'Python' * 20)
80 self.assertEqual(self.client.testString(''), '')
81 s1 = u'\b\t\n/\\\\\r{}:パイソン"'
82 s2 = u"""Afrikaans, Alemannisch, Aragonés, العربية, مصرى,
Nobuaki Sukegawa64b8f6c2015-10-10 02:12:48 +090083 Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška,
84 Беларуская, Беларуская (тарашкевіца), Български, Bamanankan,
85 বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн,
86 Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg,
87 Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English,
88 Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt,
89 Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego,
90 Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski,
91 Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia,
92 Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa,
93 ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар,
94 Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino,
95 Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa
96 Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa
97 Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, ‪
98 Norsk (nynorsk)‬, ‪Norsk (bokmål)‬, Nouormand, Diné bizaad,
99 Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو,
100 Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română,
101 Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple
102 English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk,
103 Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog,
104 Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük,
105 Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文,
106 Bân-lâm-gú, 粵語"""
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900107 if sys.version_info[0] == 2 and os.environ.get('THRIFT_TEST_PY_NO_UTF8STRINGS'):
108 s1 = s1.encode('utf8')
109 s2 = s2.encode('utf8')
110 self.assertEqual(self.client.testString(s1), s1)
111 self.assertEqual(self.client.testString(s2), s2)
Mark Sleec9676562006-09-05 17:34:52 +0000112
James E. King III20685442018-04-10 10:30:51 -0400113 def testMultiplexed(self):
114 if self.client2 is not None:
115 print('testMultiplexed')
116 self.assertEqual(self.client2.secondtestString('foobar'), 'testString("foobar")')
117
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900118 def testBool(self):
119 print('testBool')
120 self.assertEqual(self.client.testBool(True), True)
121 self.assertEqual(self.client.testBool(False), False)
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +0900122
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900123 def testByte(self):
124 print('testByte')
125 self.assertEqual(self.client.testByte(63), 63)
126 self.assertEqual(self.client.testByte(-127), -127)
Mark Sleec98d0502006-09-06 02:42:25 +0000127
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900128 def testI32(self):
129 print('testI32')
130 self.assertEqual(self.client.testI32(-1), -1)
131 self.assertEqual(self.client.testI32(0), 0)
Mark Sleec9676562006-09-05 17:34:52 +0000132
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900133 def testI64(self):
134 print('testI64')
135 self.assertEqual(self.client.testI64(1), 1)
136 self.assertEqual(self.client.testI64(-34359738368), -34359738368)
Mark Sleec98d0502006-09-06 02:42:25 +0000137
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900138 def testDouble(self):
139 print('testDouble')
140 self.assertEqual(self.client.testDouble(-5.235098235), -5.235098235)
141 self.assertEqual(self.client.testDouble(0), 0)
142 self.assertEqual(self.client.testDouble(-1), -1)
143 self.assertEqual(self.client.testDouble(-0.000341012439638598279), -0.000341012439638598279)
Mark Sleec9676562006-09-05 17:34:52 +0000144
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900145 def testBinary(self):
146 print('testBinary')
147 val = bytearray([i for i in range(0, 256)])
148 self.assertEqual(bytearray(self.client.testBinary(bytes(val))), val)
Jens Geyerd629ea02015-09-23 21:16:50 +0200149
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900150 def testStruct(self):
151 print('testStruct')
152 x = Xtruct()
153 x.string_thing = "Zero"
154 x.byte_thing = 1
155 x.i32_thing = -3
156 x.i64_thing = -5
157 y = self.client.testStruct(x)
158 self.assertEqual(y, x)
Mark Sleefc89d392006-09-04 00:04:39 +0000159
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900160 def testNest(self):
161 print('testNest')
162 inner = Xtruct(string_thing="Zero", byte_thing=1, i32_thing=-3, i64_thing=-5)
163 x = Xtruct2(struct_thing=inner, byte_thing=0, i32_thing=0)
164 y = self.client.testNest(x)
165 self.assertEqual(y, x)
Bryan Duxbury59d4efd2011-03-21 17:38:22 +0000166
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900167 def testMap(self):
168 print('testMap')
169 x = {0: 1, 1: 2, 2: 3, 3: 4, -1: -2}
170 y = self.client.testMap(x)
171 self.assertEqual(y, x)
Bryan Duxbury59d4efd2011-03-21 17:38:22 +0000172
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900173 def testSet(self):
174 print('testSet')
175 x = set([8, 1, 42])
176 y = self.client.testSet(x)
177 self.assertEqual(y, x)
Bryan Duxbury59d4efd2011-03-21 17:38:22 +0000178
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900179 def testList(self):
180 print('testList')
181 x = [1, 4, 9, -42]
182 y = self.client.testList(x)
183 self.assertEqual(y, x)
Bryan Duxbury59d4efd2011-03-21 17:38:22 +0000184
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900185 def testEnum(self):
186 print('testEnum')
187 x = Numberz.FIVE
188 y = self.client.testEnum(x)
189 self.assertEqual(y, x)
Bryan Duxbury59d4efd2011-03-21 17:38:22 +0000190
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900191 def testTypedef(self):
192 print('testTypedef')
193 x = 0xffffffffffffff # 7 bytes of 0xff
194 y = self.client.testTypedef(x)
195 self.assertEqual(y, x)
Bryan Duxbury59d4efd2011-03-21 17:38:22 +0000196
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900197 def testMapMap(self):
198 print('testMapMap')
199 x = {
200 -4: {-4: -4, -3: -3, -2: -2, -1: -1},
201 4: {4: 4, 3: 3, 2: 2, 1: 1},
202 }
203 y = self.client.testMapMap(42)
204 self.assertEqual(y, x)
Bryan Duxbury59d4efd2011-03-21 17:38:22 +0000205
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900206 def testMulti(self):
207 print('testMulti')
208 xpected = Xtruct(string_thing='Hello2', byte_thing=74, i32_thing=0xff00ff, i64_thing=0xffffffffd0d0)
209 y = self.client.testMulti(xpected.byte_thing,
210 xpected.i32_thing,
211 xpected.i64_thing,
212 {0: 'abc'},
213 Numberz.FIVE,
214 0xf0f0f0)
215 self.assertEqual(y, xpected)
Mark Sleec9676562006-09-05 17:34:52 +0000216
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900217 def testException(self):
218 print('testException')
219 self.client.testException('Safe')
220 try:
221 self.client.testException('Xception')
222 self.fail("should have gotten exception")
223 except Xception as x:
224 self.assertEqual(x.errorCode, 1001)
225 self.assertEqual(x.message, 'Xception')
226 # TODO ensure same behavior for repr within generated python variants
227 # ensure exception's repr method works
228 # x_repr = repr(x)
229 # self.assertEqual(x_repr, 'Xception(errorCode=1001, message=\'Xception\')')
Mark Sleec9676562006-09-05 17:34:52 +0000230
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900231 try:
232 self.client.testException('TException')
233 self.fail("should have gotten exception")
234 except TException as x:
235 pass
David Reissbcaa2ad2008-06-10 22:55:26 +0000236
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900237 # Should not throw
238 self.client.testException('success')
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900239
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900240 def testMultiException(self):
241 print('testMultiException')
242 try:
243 self.client.testMultiException('Xception', 'ignore')
244 except Xception as ex:
245 self.assertEqual(ex.errorCode, 1001)
246 self.assertEqual(ex.message, 'This is an Xception')
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900247
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900248 try:
249 self.client.testMultiException('Xception2', 'ignore')
250 except Xception2 as ex:
251 self.assertEqual(ex.errorCode, 2002)
252 self.assertEqual(ex.struct_thing.string_thing, 'This is an Xception2')
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900253
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900254 y = self.client.testMultiException('success', 'foobar')
255 self.assertEqual(y.string_thing, 'foobar')
Nobuaki Sukegawa01ede042015-09-29 02:16:53 +0900256
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900257 def testOneway(self):
258 print('testOneway')
259 start = time.time()
260 self.client.testOneway(1) # type is int, not float
261 end = time.time()
262 self.assertTrue(end - start < 3,
263 "oneway sleep took %f sec" % (end - start))
Roger Meier76150722014-05-31 22:22:07 +0200264
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900265 def testOnewayThenNormal(self):
266 print('testOnewayThenNormal')
267 self.client.testOneway(1) # type is int, not float
268 self.assertEqual(self.client.testString('Python'), 'Python')
David Reissdb893b62008-02-18 02:11:48 +0000269
Roger Meier879cab22014-05-03 17:51:21 +0200270
James E. King III20685442018-04-10 10:30:51 -0400271class MultiplexedOptionalTest(AbstractTest):
272 def get_protocol2(self, transport):
273 return None
274
275
276class BinaryTest(MultiplexedOptionalTest):
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900277 def get_protocol(self, transport):
278 return TBinaryProtocol.TBinaryProtocolFactory().getProtocol(transport)
Mark Sleefc89d392006-09-04 00:04:39 +0000279
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +0900280
James E. King III20685442018-04-10 10:30:51 -0400281class MultiplexedBinaryTest(MultiplexedOptionalTest):
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900282 def get_protocol(self, transport):
James E. King III20685442018-04-10 10:30:51 -0400283 wrapped_proto = TBinaryProtocol.TBinaryProtocolFactory().getProtocol(transport)
284 return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "ThriftTest")
285
286 def get_protocol2(self, transport):
287 wrapped_proto = TBinaryProtocol.TBinaryProtocolFactory().getProtocol(transport)
288 return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "SecondService")
Bryan Duxbury59d4efd2011-03-21 17:38:22 +0000289
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +0900290
James E. King III20685442018-04-10 10:30:51 -0400291class AcceleratedBinaryTest(MultiplexedOptionalTest):
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900292 def get_protocol(self, transport):
Nobuaki Sukegawa7af189a2016-02-11 16:21:01 +0900293 return TBinaryProtocol.TBinaryProtocolAcceleratedFactory(fallback=False).getProtocol(transport)
Mark Sleea3302652006-10-25 19:03:32 +0000294
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +0900295
James E. King III20685442018-04-10 10:30:51 -0400296class MultiplexedAcceleratedBinaryTest(MultiplexedOptionalTest):
297 def get_protocol(self, transport):
298 wrapped_proto = TBinaryProtocol.TBinaryProtocolAcceleratedFactory(fallback=False).getProtocol(transport)
299 return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "ThriftTest")
300
301 def get_protocol2(self, transport):
302 wrapped_proto = TBinaryProtocol.TBinaryProtocolAcceleratedFactory(fallback=False).getProtocol(transport)
303 return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "SecondService")
304
305
306class CompactTest(MultiplexedOptionalTest):
307 def get_protocol(self, transport):
308 return TCompactProtocol.TCompactProtocolFactory().getProtocol(transport)
309
310
311class MultiplexedCompactTest(MultiplexedOptionalTest):
312 def get_protocol(self, transport):
313 wrapped_proto = TCompactProtocol.TCompactProtocolFactory().getProtocol(transport)
314 return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "ThriftTest")
315
316 def get_protocol2(self, transport):
317 wrapped_proto = TCompactProtocol.TCompactProtocolFactory().getProtocol(transport)
318 return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "SecondService")
319
320
321class AcceleratedCompactTest(MultiplexedOptionalTest):
Nobuaki Sukegawa6525f6a2016-02-11 13:58:39 +0900322 def get_protocol(self, transport):
Nobuaki Sukegawa7af189a2016-02-11 16:21:01 +0900323 return TCompactProtocol.TCompactProtocolAcceleratedFactory(fallback=False).getProtocol(transport)
Nobuaki Sukegawa6525f6a2016-02-11 13:58:39 +0900324
325
James E. King III20685442018-04-10 10:30:51 -0400326class MultiplexedAcceleratedCompactTest(MultiplexedOptionalTest):
327 def get_protocol(self, transport):
328 wrapped_proto = TCompactProtocol.TCompactProtocolAcceleratedFactory(fallback=False).getProtocol(transport)
329 return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "ThriftTest")
330
331 def get_protocol2(self, transport):
332 wrapped_proto = TCompactProtocol.TCompactProtocolAcceleratedFactory(fallback=False).getProtocol(transport)
333 return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "SecondService")
334
335
336class JSONTest(MultiplexedOptionalTest):
337 def get_protocol(self, transport):
338 return TJSONProtocol.TJSONProtocolFactory().getProtocol(transport)
339
340
341class MultiplexedJSONTest(MultiplexedOptionalTest):
342 def get_protocol(self, transport):
343 wrapped_proto = TJSONProtocol.TJSONProtocolFactory().getProtocol(transport)
344 return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "ThriftTest")
345
346 def get_protocol2(self, transport):
347 wrapped_proto = TJSONProtocol.TJSONProtocolFactory().getProtocol(transport)
348 return TMultiplexedProtocol.TMultiplexedProtocol(wrapped_proto, "SecondService")
349
350
David Reiss9ff3b9d2008-02-15 01:10:23 +0000351def suite():
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900352 suite = unittest.TestSuite()
353 loader = unittest.TestLoader()
354 if options.proto == 'binary': # look for --proto on cmdline
James E. King III20685442018-04-10 10:30:51 -0400355 suite.addTest(loader.loadTestsFromTestCase(BinaryTest))
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900356 elif options.proto == 'accel':
357 suite.addTest(loader.loadTestsFromTestCase(AcceleratedBinaryTest))
Nobuaki Sukegawa6525f6a2016-02-11 13:58:39 +0900358 elif options.proto == 'accelc':
359 suite.addTest(loader.loadTestsFromTestCase(AcceleratedCompactTest))
James E. King III20685442018-04-10 10:30:51 -0400360 elif options.proto == 'compact':
361 suite.addTest(loader.loadTestsFromTestCase(CompactTest))
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900362 elif options.proto == 'json':
363 suite.addTest(loader.loadTestsFromTestCase(JSONTest))
James E. King III20685442018-04-10 10:30:51 -0400364 elif options.proto == 'multi':
365 suite.addTest(loader.loadTestsFromTestCase(MultiplexedBinaryTest))
366 elif options.proto == 'multia':
367 suite.addTest(loader.loadTestsFromTestCase(MultiplexedAcceleratedBinaryTest))
368 elif options.proto == 'multiac':
369 suite.addTest(loader.loadTestsFromTestCase(MultiplexedAcceleratedCompactTest))
370 elif options.proto == 'multic':
371 suite.addTest(loader.loadTestsFromTestCase(MultiplexedCompactTest))
372 elif options.proto == 'multij':
373 suite.addTest(loader.loadTestsFromTestCase(MultiplexedJSONTest))
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900374 else:
375 raise AssertionError('Unknown protocol given with --protocol: %s' % options.proto)
376 return suite
Mark Slee5299a952007-10-05 00:13:24 +0000377
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +0900378
David Reiss74421272008-11-07 23:09:31 +0000379class OwnArgsTestProgram(unittest.TestProgram):
380 def parseArgs(self, argv):
381 if args:
382 self.testNames = args
383 else:
Nobuaki Sukegawaa185d7e2015-11-06 21:24:24 +0900384 self.testNames = ([self.defaultTest])
David Reiss74421272008-11-07 23:09:31 +0000385 self.createTests()
386
James E. King, III0ad20bd2017-09-30 15:44:16 -0700387
David Reiss9ff3b9d2008-02-15 01:10:23 +0000388if __name__ == "__main__":
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900389 parser = OptionParser()
390 parser.add_option('--libpydir', type='string', dest='libpydir',
391 help='include this directory in sys.path for locating library code')
392 parser.add_option('--genpydir', type='string', dest='genpydir',
393 help='include this directory in sys.path for locating generated code')
394 parser.add_option("--port", type="int", dest="port",
395 help="connect to server at port")
396 parser.add_option("--host", type="string", dest="host",
397 help="connect to server")
398 parser.add_option("--zlib", action="store_true", dest="zlib",
399 help="use zlib wrapper for compressed transport")
400 parser.add_option("--ssl", action="store_true", dest="ssl",
401 help="use SSL for encrypted transport")
402 parser.add_option("--http", dest="http_path",
403 help="Use the HTTP transport with the specified path")
404 parser.add_option('-v', '--verbose', action="store_const",
405 dest="verbose", const=2,
406 help="verbose output")
407 parser.add_option('-q', '--quiet', action="store_const",
408 dest="verbose", const=0,
409 help="minimal output")
410 parser.add_option('--protocol', dest="proto", type="string",
James E. King III20685442018-04-10 10:30:51 -0400411 help="protocol to use, one of: accel, accelc, binary, compact, json, multi, multia, multiac, multic, multij")
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900412 parser.add_option('--transport', dest="trans", type="string",
James E. King III6f8c99e2018-03-24 16:32:02 -0400413 help="transport to use, one of: buffered, framed, http")
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900414 parser.set_defaults(framed=False, http_path=None, verbose=1, host='localhost', port=9090, proto='binary')
415 options, args = parser.parse_args()
Nobuaki Sukegawaa185d7e2015-11-06 21:24:24 +0900416
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900417 if options.genpydir:
418 sys.path.insert(0, os.path.join(SCRIPT_DIR, options.genpydir))
Nobuaki Sukegawa7af189a2016-02-11 16:21:01 +0900419 sys.path.insert(0, local_libpath())
Nobuaki Sukegawaa185d7e2015-11-06 21:24:24 +0900420
James E. King III6f8c99e2018-03-24 16:32:02 -0400421 if options.http_path:
422 options.trans = 'http'
423
James E. King III20685442018-04-10 10:30:51 -0400424 from ThriftTest import SecondService
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900425 from ThriftTest import ThriftTest
426 from ThriftTest.ttypes import Xtruct, Xtruct2, Numberz, Xception, Xception2
427 from thrift.Thrift import TException
428 from thrift.transport import TTransport
429 from thrift.transport import TSocket
430 from thrift.transport import THttpClient
431 from thrift.transport import TZlibTransport
432 from thrift.protocol import TBinaryProtocol
433 from thrift.protocol import TCompactProtocol
434 from thrift.protocol import TJSONProtocol
James E. King III20685442018-04-10 10:30:51 -0400435 from thrift.protocol import TMultiplexedProtocol
Nobuaki Sukegawaa185d7e2015-11-06 21:24:24 +0900436
Nobuaki Sukegawa10308cb2016-02-03 01:57:03 +0900437 OwnArgsTestProgram(defaultTest="suite", testRunner=unittest.TextTestRunner(verbosity=1))