Guest User

THRIFT-1525 test fix (1)

a guest
Feb 28th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. #!/usr/bin/env python
  2. from __future__ import absolute_import
  3. import sys, glob
  4. sys.path.insert(0, glob.glob('lib/py/build/lib.*')[0])  # run make and stay in trunk/ dir
  5. import thrift.protocol.TCompactProtocol as TCP
  6. import thrift.transport.TTransport as TTrans
  7.  
  8. def test(x, dtype):
  9.   transport = TTrans.TMemoryBuffer()
  10.   tcp = TCP.TCompactProtocol(transport)
  11.   tcp.state = TCP.VALUE_WRITE
  12.   writer = getattr(tcp, 'write' + dtype)
  13.   writer(x)
  14.   tcp2 = TCP.TCompactProtocol(TTrans.TMemoryBuffer(transport.getvalue()))
  15.   tcp2.state = TCP.VALUE_READ
  16.   reader = getattr(tcp2, 'read' + dtype)
  17.   y = reader()
  18.   return y
  19.  
  20. vals = {
  21.   'I64': [(1 << 63) - 1, (1 << 63)],
  22.   'I32': [2147483647, 2147483648, 3000000000],
  23.   'I16': [32767, 32768]
  24. }
  25. for dtype, vals in vals.iteritems():
  26.   for x in vals:
  27.     try:
  28.       y = test(x, dtype)
  29.     except Exception as exc:
  30.       print 'FAILED %r %r (Due to: %r)' % (x, dtype, exc)
  31.       continue
  32.     if not x == y:
  33.       print 'Decoded value  %13r  is different from input value %r' % (y, x)
  34.     else:
  35.       print 'Decoded value  %13r  OK' % y
Advertisement
Add Comment
Please, Sign In to add comment