From 1f554e1a9c643a717f8687f62596ae9ae3479234 Mon Sep 17 00:00:00 2001 From: Roger Meier Date: Sat, 5 Jan 2013 20:38:35 +0100 Subject: [PATCH] THRIFT-1797 Python implementation of TSimpleJSONProtocol Improve Test Suite according to test/ThriftTest.thrift Patch: Avi Flamholz --- .gitignore | 1 + test/py/TestServer.py | 41 ++++++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 375b27e8..403321ed 100644 --- a/.gitignore +++ b/.gitignore @@ -261,3 +261,4 @@ gen-* /ylwrap .project .pydevproject +*.swp diff --git a/test/py/TestServer.py b/test/py/TestServer.py index 1eae0976..334f25c8 100755 --- a/test/py/TestServer.py +++ b/test/py/TestServer.py @@ -48,6 +48,7 @@ sys.path.insert(0, options.genpydir) from ThriftTest import ThriftTest from ThriftTest.ttypes import * +from thrift.Thrift import TException from thrift.transport import TTransport from thrift.transport import TSocket from thrift.transport import TZlibTransport @@ -102,16 +103,24 @@ class TestHandler: print 'testStruct({%s, %d, %d, %d})' % (thing.string_thing, thing.byte_thing, thing.i32_thing, thing.i64_thing) return thing - def testException(self, str): - if options.verbose > 1: - print 'testException(%s)' % str - if str == 'Xception': - x = Xception() - x.errorCode = 1001 - x.message = str - raise x - elif str == "throw_undeclared": - raise ValueError("Exception test PASSES.") + def testException(self, arg): + #if options.verbose > 1: + print '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: + print '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: @@ -153,13 +162,19 @@ class TestHandler: def testMapMap(self, thing): if options.verbose > 1: print 'testMapMap(%s)' % thing - return thing + return {thing: {thing: thing}} + + def testInsanity(self, argument): + if options.verbose > 1: + print 'testInsanity(%s)' % argument + return {123489: {Numberz.ONE:argument}} def testMulti(self, arg0, arg1, arg2, arg3, arg4, arg5): if options.verbose > 1: print 'testMulti(%s)' % [arg0, arg1, arg2, arg3, arg4, arg5] - x = Xtruct(string_thing='Hello2', byte_thing=arg0, i32_thing=arg1, i64_thing=arg2) - return x + return Xtruct(string_thing='Hello2', + byte_thing=arg0, i32_thing=arg1, i64_thing=arg2) + # set up the protocol factory form the --proto option pfactory_cls = PROT_FACTORIES.get(options.proto, None) -- 2.17.1