Ejemplo n.º 1
0
    def test_required(self):
        # "required" fields aren't enforced anymore and should not throw any exceptions

        aStruct = AStruct(anInteger=1)
        self.encode_and_decode(aStruct)

        aStruct = AStruct(aString="")
        required = Required(aStruct=aStruct)
        self.encode_and_decode(required)
Ejemplo n.º 2
0
    def test_required(self):
        with self.assertRaises(TProtocol.TProtocolException):
            aStruct = AStruct(anInteger=1)
            self.encode_and_decode(aStruct)

        with self.assertRaises(TProtocol.TProtocolException):
            aStruct = AStruct(aString="")
            required = Required(aStruct=aStruct)
            self.encode_and_decode(required)
Ejemplo n.º 3
0
 def test_decode_union(self):
     u = TestUnion(i32_field=123)
     self.decode_helper(u)
     u.set_string_field(b"world")
     self.decode_helper(u)
     u.set_struct_field(AStruct(aString=b"world"))
     self.decode_helper(u)
     swu = StructWithUnion(aUnion=u, aString=b"world")
     self.decode_helper(swu)
Ejemplo n.º 4
0
 def test_encode_union(self):
     u = TestUnion(i32_field=12)
     self.encode_helper(u)
     u.set_string_field("hello")
     self.encode_helper(u)
     u.set_struct_field(AStruct(aString="hello"))
     self.encode_helper(u)
     swu = StructWithUnion(aUnion=u, aString="world")
     self.encode_helper(swu)
Ejemplo n.º 5
0
 def buildOneOfEachB(self):
     return OneOfEach(
             aBool=True,
             aByte=1,
             anInteger16=234,
             anInteger32=12345,
             anInteger64=12345678910,
             aString=b'\x00hello',
             aBinary=b'\x00\x01\x00',
             aDouble=1234567.901,
             aFloat=12345.0,
             aList=[12, 34, 567, 89],
             aSet=set([b"hello", b"world", b"good", b"bye"]),
             aMap={b"hello": 1, b"world": 20},
             aStruct=AStruct(aString=b"str", anInteger=109))
Ejemplo n.º 6
0
 def buildOneOfEach(self):
     return OneOfEach(
         aBool=True,
         aByte=1,
         anInteger16=234,
         anInteger32=12345,
         anInteger64=12345678910,
         aString="\x00hello",
         aBinary=b"\x00\x01\x00",
         aDouble=1234567.901,
         aFloat=12345.0,
         aList=[12, 34, 567, 89],
         aSet={"hello", "world", "good", "bye"},
         aMap={"hello": 1, "world": 20},
         aStruct=AStruct(aString="str", anInteger=109),
     )
Ejemplo n.º 7
0
 def test_decode_failure_lists_fieldname(self):
     obj = OneOfEach(aStruct=AStruct(aString="Привет".encode("cp866")))
     # Can't use self.assertRaises since AbstractTest cannot inherit
     # from unittest.TestCase
     raised_exception = None
     try:
         self.decode_helper(obj, split=1.0, utf8strings=1)
     except UnicodeDecodeError as ex:
         raised_exception = ex
     self.assertIsNotNone(raised_exception)
     self.assertIn("when decoding field 'aStruct->aString'", str(raised_exception))
     self.assertIn(
         "('utf-8', b'\\x8f\\xe0\\xa8\\xa2\\xa5\\xe2', 0, 1, 'invalid start byte')",
         repr(raised_exception),
     )
     self.assertTrue(isinstance(raised_exception, ThriftUnicodeDecodeError))
Ejemplo n.º 8
0
from FastProto.ttypes import AStruct, OneOfEach

ooe = OneOfEach()
ooe.aBool = True
ooe.aByte = 1
ooe.anInteger16 = 234
ooe.anInteger32 = 2345678
ooe.anInteger64 = 23456789012345
ooe.aString = "This is my rifle" * 100
ooe.aDouble = 2.3456789012
ooe.aFloat = 12345.678
ooe.aList = [12, 34, 56, 78, 90, 100, 123, 456, 789]
ooe.aSet = set(["This", "is", "my", "rifle"])
ooe.aMap = {"What": 4, "a": 1, "wonderful": 9, "day": 3, "!": 1}
ooe.aStruct = AStruct(aString="isn't it?", anInteger=999)

trans = TTransport.TMemoryBuffer()
proto = TBinaryProtocol.TBinaryProtocol(trans)
ooe.write(proto)
binary_buf = trans.getvalue()

trans = TTransport.TMemoryBuffer()
proto = TCompactProtocol.TCompactProtocol(trans)
ooe.write(proto)
compact_buf = trans.getvalue()


class TDevNullTransport(TTransport.TTransportBase):
    def __init__(self):
        pass