diff options
author | Nobuaki Sukegawa <nsuke@apache.org> | 2016-02-03 01:57:03 +0900 |
---|---|---|
committer | Nobuaki Sukegawa <nsuke@apache.org> | 2016-02-04 14:28:24 +0900 |
commit | 10308cb975ac090584068d0470b81e41555b2f35 (patch) | |
tree | bc0bb670626a8a196dc00df6429ae4dcc838b4c4 /test/features | |
parent | d094e79de7e0bd61320f006c83c0de669363bce8 (diff) | |
download | thrift-10308cb975ac090584068d0470b81e41555b2f35.tar.gz |
THRIFT-3596 Better conformance to PEP8
This closes #832
Diffstat (limited to 'test/features')
-rw-r--r-- | test/features/container_limit.py | 106 | ||||
-rw-r--r-- | test/features/local_thrift/__init__.py | 12 | ||||
-rw-r--r-- | test/features/string_limit.py | 88 | ||||
-rw-r--r-- | test/features/theader_binary.py | 84 | ||||
-rw-r--r-- | test/features/util.py | 42 |
5 files changed, 166 insertions, 166 deletions
diff --git a/test/features/container_limit.py b/test/features/container_limit.py index 4a7da6065..beed0c5ec 100644 --- a/test/features/container_limit.py +++ b/test/features/container_limit.py @@ -10,63 +10,63 @@ from thrift.Thrift import TMessageType, TType # TODO: generate from ThriftTest.thrift def test_list(proto, value): - method_name = 'testList' - ttype = TType.LIST - etype = TType.I32 - proto.writeMessageBegin(method_name, TMessageType.CALL, 3) - proto.writeStructBegin(method_name + '_args') - proto.writeFieldBegin('thing', ttype, 1) - proto.writeListBegin(etype, len(value)) - for e in value: - proto.writeI32(e) - proto.writeListEnd() - proto.writeFieldEnd() - proto.writeFieldStop() - proto.writeStructEnd() - proto.writeMessageEnd() - proto.trans.flush() + method_name = 'testList' + ttype = TType.LIST + etype = TType.I32 + proto.writeMessageBegin(method_name, TMessageType.CALL, 3) + proto.writeStructBegin(method_name + '_args') + proto.writeFieldBegin('thing', ttype, 1) + proto.writeListBegin(etype, len(value)) + for e in value: + proto.writeI32(e) + proto.writeListEnd() + proto.writeFieldEnd() + proto.writeFieldStop() + proto.writeStructEnd() + proto.writeMessageEnd() + proto.trans.flush() - _, mtype, _ = proto.readMessageBegin() - assert mtype == TMessageType.REPLY - proto.readStructBegin() - _, ftype, fid = proto.readFieldBegin() - assert fid == 0 - assert ftype == ttype - etype2, len2 = proto.readListBegin() - assert etype == etype2 - assert len2 == len(value) - for i in range(len2): - v = proto.readI32() - assert v == value[i] - proto.readListEnd() - proto.readFieldEnd() - _, ftype, _ = proto.readFieldBegin() - assert ftype == TType.STOP - proto.readStructEnd() - proto.readMessageEnd() + _, mtype, _ = proto.readMessageBegin() + assert mtype == TMessageType.REPLY + proto.readStructBegin() + _, ftype, fid = proto.readFieldBegin() + assert fid == 0 + assert ftype == ttype + etype2, len2 = proto.readListBegin() + assert etype == etype2 + assert len2 == len(value) + for i in range(len2): + v = proto.readI32() + assert v == value[i] + proto.readListEnd() + proto.readFieldEnd() + _, ftype, _ = proto.readFieldBegin() + assert ftype == TType.STOP + proto.readStructEnd() + proto.readMessageEnd() def main(argv): - p = argparse.ArgumentParser() - add_common_args(p) - p.add_argument('--limit', type=int) - args = p.parse_args() - proto = init_protocol(args) - # TODO: test set and map - test_list(proto, list(range(args.limit - 1))) - test_list(proto, list(range(args.limit - 1))) - print('[OK]: limit - 1') - test_list(proto, list(range(args.limit))) - test_list(proto, list(range(args.limit))) - print('[OK]: just limit') - try: - test_list(proto, list(range(args.limit + 1))) - except: - print('[OK]: limit + 1') - else: - print('[ERROR]: limit + 1') - assert False + p = argparse.ArgumentParser() + add_common_args(p) + p.add_argument('--limit', type=int) + args = p.parse_args() + proto = init_protocol(args) + # TODO: test set and map + test_list(proto, list(range(args.limit - 1))) + test_list(proto, list(range(args.limit - 1))) + print('[OK]: limit - 1') + test_list(proto, list(range(args.limit))) + test_list(proto, list(range(args.limit))) + print('[OK]: just limit') + try: + test_list(proto, list(range(args.limit + 1))) + except: + print('[OK]: limit + 1') + else: + print('[ERROR]: limit + 1') + assert False if __name__ == '__main__': - sys.exit(main(sys.argv[1:])) + sys.exit(main(sys.argv[1:])) diff --git a/test/features/local_thrift/__init__.py b/test/features/local_thrift/__init__.py index 383ee5f40..0a0bb0b66 100644 --- a/test/features/local_thrift/__init__.py +++ b/test/features/local_thrift/__init__.py @@ -5,10 +5,10 @@ SCRIPT_DIR = os.path.realpath(os.path.dirname(__file__)) ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(SCRIPT_DIR))) if sys.version_info[0] == 2: - import glob - libdir = glob.glob(os.path.join(ROOT_DIR, 'lib', 'py', 'build', 'lib.*'))[0] - sys.path.insert(0, libdir) - thrift = __import__('thrift') + import glob + libdir = glob.glob(os.path.join(ROOT_DIR, 'lib', 'py', 'build', 'lib.*'))[0] + sys.path.insert(0, libdir) + thrift = __import__('thrift') else: - sys.path.insert(0, os.path.join(ROOT_DIR, 'lib', 'py', 'build', 'lib')) - thrift = __import__('thrift') + sys.path.insert(0, os.path.join(ROOT_DIR, 'lib', 'py', 'build', 'lib')) + thrift = __import__('thrift') diff --git a/test/features/string_limit.py b/test/features/string_limit.py index b4d48acdb..3c68b3ea3 100644 --- a/test/features/string_limit.py +++ b/test/features/string_limit.py @@ -10,52 +10,52 @@ from thrift.Thrift import TMessageType, TType # TODO: generate from ThriftTest.thrift def test_string(proto, value): - method_name = 'testString' - ttype = TType.STRING - proto.writeMessageBegin(method_name, TMessageType.CALL, 3) - proto.writeStructBegin(method_name + '_args') - proto.writeFieldBegin('thing', ttype, 1) - proto.writeString(value) - proto.writeFieldEnd() - proto.writeFieldStop() - proto.writeStructEnd() - proto.writeMessageEnd() - proto.trans.flush() - - _, mtype, _ = proto.readMessageBegin() - assert mtype == TMessageType.REPLY - proto.readStructBegin() - _, ftype, fid = proto.readFieldBegin() - assert fid == 0 - assert ftype == ttype - result = proto.readString() - proto.readFieldEnd() - _, ftype, _ = proto.readFieldBegin() - assert ftype == TType.STOP - proto.readStructEnd() - proto.readMessageEnd() - assert value == result + method_name = 'testString' + ttype = TType.STRING + proto.writeMessageBegin(method_name, TMessageType.CALL, 3) + proto.writeStructBegin(method_name + '_args') + proto.writeFieldBegin('thing', ttype, 1) + proto.writeString(value) + proto.writeFieldEnd() + proto.writeFieldStop() + proto.writeStructEnd() + proto.writeMessageEnd() + proto.trans.flush() + + _, mtype, _ = proto.readMessageBegin() + assert mtype == TMessageType.REPLY + proto.readStructBegin() + _, ftype, fid = proto.readFieldBegin() + assert fid == 0 + assert ftype == ttype + result = proto.readString() + proto.readFieldEnd() + _, ftype, _ = proto.readFieldBegin() + assert ftype == TType.STOP + proto.readStructEnd() + proto.readMessageEnd() + assert value == result def main(argv): - p = argparse.ArgumentParser() - add_common_args(p) - p.add_argument('--limit', type=int) - args = p.parse_args() - proto = init_protocol(args) - test_string(proto, 'a' * (args.limit - 1)) - test_string(proto, 'a' * (args.limit - 1)) - print('[OK]: limit - 1') - test_string(proto, 'a' * args.limit) - test_string(proto, 'a' * args.limit) - print('[OK]: just limit') - try: - test_string(proto, 'a' * (args.limit + 1)) - except: - print('[OK]: limit + 1') - else: - print('[ERROR]: limit + 1') - assert False + p = argparse.ArgumentParser() + add_common_args(p) + p.add_argument('--limit', type=int) + args = p.parse_args() + proto = init_protocol(args) + test_string(proto, 'a' * (args.limit - 1)) + test_string(proto, 'a' * (args.limit - 1)) + print('[OK]: limit - 1') + test_string(proto, 'a' * args.limit) + test_string(proto, 'a' * args.limit) + print('[OK]: just limit') + try: + test_string(proto, 'a' * (args.limit + 1)) + except: + print('[OK]: limit + 1') + else: + print('[ERROR]: limit + 1') + assert False if __name__ == '__main__': - main(sys.argv[1:]) + main(sys.argv[1:]) diff --git a/test/features/theader_binary.py b/test/features/theader_binary.py index 62a26715d..02e010b8b 100644 --- a/test/features/theader_binary.py +++ b/test/features/theader_binary.py @@ -14,57 +14,57 @@ from thrift.protocol.TCompactProtocol import TCompactProtocol def test_void(proto): - proto.writeMessageBegin('testVoid', TMessageType.CALL, 3) - proto.writeStructBegin('testVoid_args') - proto.writeFieldStop() - proto.writeStructEnd() - proto.writeMessageEnd() - proto.trans.flush() + proto.writeMessageBegin('testVoid', TMessageType.CALL, 3) + proto.writeStructBegin('testVoid_args') + proto.writeFieldStop() + proto.writeStructEnd() + proto.writeMessageEnd() + proto.trans.flush() - _, mtype, _ = proto.readMessageBegin() - assert mtype == TMessageType.REPLY - proto.readStructBegin() - _, ftype, _ = proto.readFieldBegin() - assert ftype == TType.STOP - proto.readStructEnd() - proto.readMessageEnd() + _, mtype, _ = proto.readMessageBegin() + assert mtype == TMessageType.REPLY + proto.readStructBegin() + _, ftype, _ = proto.readFieldBegin() + assert ftype == TType.STOP + proto.readStructEnd() + proto.readMessageEnd() # THeader stack should accept binary protocol with optionally framed transport def main(argv): - p = argparse.ArgumentParser() - add_common_args(p) - # Since THeaderTransport acts as framed transport when detected frame, we - # cannot use --transport=framed as it would result in 2 layered frames. - p.add_argument('--override-transport') - p.add_argument('--override-protocol') - args = p.parse_args() - assert args.protocol == 'header' - assert args.transport == 'buffered' - assert not args.ssl + p = argparse.ArgumentParser() + add_common_args(p) + # Since THeaderTransport acts as framed transport when detected frame, we + # cannot use --transport=framed as it would result in 2 layered frames. + p.add_argument('--override-transport') + p.add_argument('--override-protocol') + args = p.parse_args() + assert args.protocol == 'header' + assert args.transport == 'buffered' + assert not args.ssl - sock = TSocket(args.host, args.port, socket_family=socket.AF_INET) - if not args.override_transport or args.override_transport == 'buffered': - trans = TBufferedTransport(sock) - elif args.override_transport == 'framed': - print('TFRAMED') - trans = TFramedTransport(sock) - else: - raise ValueError('invalid transport') - trans.open() + sock = TSocket(args.host, args.port, socket_family=socket.AF_INET) + if not args.override_transport or args.override_transport == 'buffered': + trans = TBufferedTransport(sock) + elif args.override_transport == 'framed': + print('TFRAMED') + trans = TFramedTransport(sock) + else: + raise ValueError('invalid transport') + trans.open() - if not args.override_protocol or args.override_protocol == 'binary': - proto = TBinaryProtocol(trans) - elif args.override_protocol == 'compact': - proto = TCompactProtocol(trans) - else: - raise ValueError('invalid transport') + if not args.override_protocol or args.override_protocol == 'binary': + proto = TBinaryProtocol(trans) + elif args.override_protocol == 'compact': + proto = TCompactProtocol(trans) + else: + raise ValueError('invalid transport') - test_void(proto) - test_void(proto) + test_void(proto) + test_void(proto) - trans.close() + trans.close() if __name__ == '__main__': - sys.exit(main(sys.argv[1:])) + sys.exit(main(sys.argv[1:])) diff --git a/test/features/util.py b/test/features/util.py index e36413629..e4997d0b7 100644 --- a/test/features/util.py +++ b/test/features/util.py @@ -11,30 +11,30 @@ from thrift.protocol.TJSONProtocol import TJSONProtocol def add_common_args(p): - p.add_argument('--host', default='localhost') - p.add_argument('--port', type=int, default=9090) - p.add_argument('--protocol', default='binary') - p.add_argument('--transport', default='buffered') - p.add_argument('--ssl', action='store_true') + p.add_argument('--host', default='localhost') + p.add_argument('--port', type=int, default=9090) + p.add_argument('--protocol', default='binary') + p.add_argument('--transport', default='buffered') + p.add_argument('--ssl', action='store_true') def parse_common_args(argv): - p = argparse.ArgumentParser() - add_common_args(p) - return p.parse_args(argv) + p = argparse.ArgumentParser() + add_common_args(p) + return p.parse_args(argv) def init_protocol(args): - sock = TSocket(args.host, args.port, socket_family=socket.AF_INET) - sock.setTimeout(500) - trans = { - 'buffered': TBufferedTransport, - 'framed': TFramedTransport, - 'http': THttpClient, - }[args.transport](sock) - trans.open() - return { - 'binary': TBinaryProtocol, - 'compact': TCompactProtocol, - 'json': TJSONProtocol, - }[args.protocol](trans) + sock = TSocket(args.host, args.port, socket_family=socket.AF_INET) + sock.setTimeout(500) + trans = { + 'buffered': TBufferedTransport, + 'framed': TFramedTransport, + 'http': THttpClient, + }[args.transport](sock) + trans.open() + return { + 'binary': TBinaryProtocol, + 'compact': TCompactProtocol, + 'json': TJSONProtocol, + }[args.protocol](trans) |