THRIFT-3596 Better conformance to PEP8
This closes #832
diff --git a/test/py/FastbinaryTest.py b/test/py/FastbinaryTest.py
index 9d258fd..a8718dc 100755
--- a/test/py/FastbinaryTest.py
+++ b/test/py/FastbinaryTest.py
@@ -41,11 +41,11 @@
class TDevNullTransport(TTransport.TTransportBase):
- def __init__(self):
- pass
+ def __init__(self):
+ pass
- def isOpen(self):
- return True
+ def isOpen(self):
+ return True
ooe1 = OneOfEach()
ooe1.im_true = True
@@ -71,8 +71,8 @@
u"\xc7\x83\xe2\x80\xbc"
if sys.version_info[0] == 2 and os.environ.get('THRIFT_TEST_PY_NO_UTF8STRINGS'):
- ooe1.zomg_unicode = ooe1.zomg_unicode.encode('utf8')
- ooe2.zomg_unicode = ooe2.zomg_unicode.encode('utf8')
+ ooe1.zomg_unicode = ooe1.zomg_unicode.encode('utf8')
+ ooe2.zomg_unicode = ooe2.zomg_unicode.encode('utf8')
hm = HolyMoley(**{"big": [], "contain": set(), "bonks": {}})
hm.big.append(ooe1)
@@ -86,13 +86,13 @@
hm.bonks["nothing"] = []
hm.bonks["something"] = [
- Bonk(**{"type": 1, "message": "Wait."}),
- Bonk(**{"type": 2, "message": "What?"}),
+ Bonk(**{"type": 1, "message": "Wait."}),
+ Bonk(**{"type": 2, "message": "What?"}),
]
hm.bonks["poe"] = [
- Bonk(**{"type": 3, "message": "quoth"}),
- Bonk(**{"type": 4, "message": "the raven"}),
- Bonk(**{"type": 5, "message": "nevermore"}),
+ Bonk(**{"type": 3, "message": "quoth"}),
+ Bonk(**{"type": 4, "message": "the raven"}),
+ Bonk(**{"type": 5, "message": "nevermore"}),
]
rs = RandomStuff()
@@ -112,110 +112,110 @@
def check_write(o):
- trans_fast = TTransport.TMemoryBuffer()
- trans_slow = TTransport.TMemoryBuffer()
- prot_fast = TBinaryProtocol.TBinaryProtocolAccelerated(trans_fast)
- prot_slow = TBinaryProtocol.TBinaryProtocol(trans_slow)
+ trans_fast = TTransport.TMemoryBuffer()
+ trans_slow = TTransport.TMemoryBuffer()
+ prot_fast = TBinaryProtocol.TBinaryProtocolAccelerated(trans_fast)
+ prot_slow = TBinaryProtocol.TBinaryProtocol(trans_slow)
- o.write(prot_fast)
- o.write(prot_slow)
- ORIG = trans_slow.getvalue()
- MINE = trans_fast.getvalue()
- if ORIG != MINE:
- print("mine: %s\norig: %s" % (repr(MINE), repr(ORIG)))
+ o.write(prot_fast)
+ o.write(prot_slow)
+ ORIG = trans_slow.getvalue()
+ MINE = trans_fast.getvalue()
+ if ORIG != MINE:
+ print("mine: %s\norig: %s" % (repr(MINE), repr(ORIG)))
def check_read(o):
- prot = TBinaryProtocol.TBinaryProtocol(TTransport.TMemoryBuffer())
- o.write(prot)
+ prot = TBinaryProtocol.TBinaryProtocol(TTransport.TMemoryBuffer())
+ o.write(prot)
- slow_version_binary = prot.trans.getvalue()
+ slow_version_binary = prot.trans.getvalue()
- prot = TBinaryProtocol.TBinaryProtocolAccelerated(
- TTransport.TMemoryBuffer(slow_version_binary))
- c = o.__class__()
- c.read(prot)
- if c != o:
- print("copy: ")
- pprint(eval(repr(c)))
- print("orig: ")
- pprint(eval(repr(o)))
+ prot = TBinaryProtocol.TBinaryProtocolAccelerated(
+ TTransport.TMemoryBuffer(slow_version_binary))
+ c = o.__class__()
+ c.read(prot)
+ if c != o:
+ print("copy: ")
+ pprint(eval(repr(c)))
+ print("orig: ")
+ pprint(eval(repr(o)))
- prot = TBinaryProtocol.TBinaryProtocolAccelerated(
- TTransport.TBufferedTransport(
- TTransport.TMemoryBuffer(slow_version_binary)))
- c = o.__class__()
- c.read(prot)
- if c != o:
- print("copy: ")
- pprint(eval(repr(c)))
- print("orig: ")
- pprint(eval(repr(o)))
+ prot = TBinaryProtocol.TBinaryProtocolAccelerated(
+ TTransport.TBufferedTransport(
+ TTransport.TMemoryBuffer(slow_version_binary)))
+ c = o.__class__()
+ c.read(prot)
+ if c != o:
+ print("copy: ")
+ pprint(eval(repr(c)))
+ print("orig: ")
+ pprint(eval(repr(o)))
def do_test():
- check_write(hm)
- check_read(HolyMoley())
- no_set = deepcopy(hm)
- no_set.contain = set()
- check_read(no_set)
- check_write(rs)
- check_read(rs)
- check_write(rshuge)
- check_read(rshuge)
- check_write(my_zero)
- check_read(my_zero)
- check_read(Backwards(**{"first_tag2": 4, "second_tag1": 2}))
+ check_write(hm)
+ check_read(HolyMoley())
+ no_set = deepcopy(hm)
+ no_set.contain = set()
+ check_read(no_set)
+ check_write(rs)
+ check_read(rs)
+ check_write(rshuge)
+ check_read(rshuge)
+ check_write(my_zero)
+ check_read(my_zero)
+ check_read(Backwards(**{"first_tag2": 4, "second_tag1": 2}))
- # One case where the serialized form changes, but only superficially.
- o = Backwards(**{"first_tag2": 4, "second_tag1": 2})
- trans_fast = TTransport.TMemoryBuffer()
- trans_slow = TTransport.TMemoryBuffer()
- prot_fast = TBinaryProtocol.TBinaryProtocolAccelerated(trans_fast)
- prot_slow = TBinaryProtocol.TBinaryProtocol(trans_slow)
+ # One case where the serialized form changes, but only superficially.
+ o = Backwards(**{"first_tag2": 4, "second_tag1": 2})
+ trans_fast = TTransport.TMemoryBuffer()
+ trans_slow = TTransport.TMemoryBuffer()
+ prot_fast = TBinaryProtocol.TBinaryProtocolAccelerated(trans_fast)
+ prot_slow = TBinaryProtocol.TBinaryProtocol(trans_slow)
- o.write(prot_fast)
- o.write(prot_slow)
- ORIG = trans_slow.getvalue()
- MINE = trans_fast.getvalue()
- assert id(ORIG) != id(MINE)
+ o.write(prot_fast)
+ o.write(prot_slow)
+ ORIG = trans_slow.getvalue()
+ MINE = trans_fast.getvalue()
+ assert id(ORIG) != id(MINE)
- prot = TBinaryProtocol.TBinaryProtocolAccelerated(TTransport.TMemoryBuffer())
- o.write(prot)
- prot = TBinaryProtocol.TBinaryProtocol(
- TTransport.TMemoryBuffer(prot.trans.getvalue()))
- c = o.__class__()
- c.read(prot)
- if c != o:
- print("copy: ")
- pprint(eval(repr(c)))
- print("orig: ")
- pprint(eval(repr(o)))
+ prot = TBinaryProtocol.TBinaryProtocolAccelerated(TTransport.TMemoryBuffer())
+ o.write(prot)
+ prot = TBinaryProtocol.TBinaryProtocol(
+ TTransport.TMemoryBuffer(prot.trans.getvalue()))
+ c = o.__class__()
+ c.read(prot)
+ if c != o:
+ print("copy: ")
+ pprint(eval(repr(c)))
+ print("orig: ")
+ pprint(eval(repr(o)))
def do_benchmark(iters=5000):
- setup = """
+ setup = """
from __main__ import hm, rs, TDevNullTransport
from thrift.protocol import TBinaryProtocol
trans = TDevNullTransport()
prot = TBinaryProtocol.TBinaryProtocol%s(trans)
"""
- setup_fast = setup % "Accelerated"
- setup_slow = setup % ""
+ setup_fast = setup % "Accelerated"
+ setup_slow = setup % ""
- print("Starting Benchmarks")
+ print("Starting Benchmarks")
- print("HolyMoley Standard = %f" %
- timeit.Timer('hm.write(prot)', setup_slow).timeit(number=iters))
- print("HolyMoley Acceler. = %f" %
- timeit.Timer('hm.write(prot)', setup_fast).timeit(number=iters))
+ print("HolyMoley Standard = %f" %
+ timeit.Timer('hm.write(prot)', setup_slow).timeit(number=iters))
+ print("HolyMoley Acceler. = %f" %
+ timeit.Timer('hm.write(prot)', setup_fast).timeit(number=iters))
- print("FastStruct Standard = %f" %
- timeit.Timer('rs.write(prot)', setup_slow).timeit(number=iters))
- print("FastStruct Acceler. = %f" %
- timeit.Timer('rs.write(prot)', setup_fast).timeit(number=iters))
+ print("FastStruct Standard = %f" %
+ timeit.Timer('rs.write(prot)', setup_slow).timeit(number=iters))
+ print("FastStruct Acceler. = %f" %
+ timeit.Timer('rs.write(prot)', setup_fast).timeit(number=iters))
if __name__ == '__main__':
- do_test()
- do_benchmark()
+ do_test()
+ do_benchmark()