def test_struct_type(): struct_thrift = load_thrift_from_testdir("structThrift.thrift") my_int_struct = ThriftSpec(name="myIntStruct", type_info=TI64(), required=True) my_other_struct = ThriftSpec( name="myOtherStruct", type_info=TStruct( name="MyOtherStruct", fields=[ ThriftSpec(name="id", type_info=TString(), required=True), ThriftSpec(name="ints", type_info=TList(value_type=TI64()), required=True), ], ), required=False, ) expected = ServiceEndpoint( name="getMyStruct", args=[], results=[ ThriftSpec( name="success", type_info=TStruct(name="MyStruct", fields=[my_int_struct, my_other_struct]), required=False, ) ], ) result = thrift_parser._parse_thrift_endpoint( struct_thrift.__thrift_meta__["services"][0], "getMyStruct") assert expected == result
def test_super_nesting(): turducken_thrift = load_thrift_from_testdir("turducken.thrift") dog_names_to_values = {"GOLDEN": 0, "CORGI": 1, "BASSET": 2} dog_enum = TEnum( name="DOG", names_to_values=dog_names_to_values, values_to_names={ value: key for key, value in dog_names_to_values.items() }, ) outer_value = TI64() inner_value = TList(value_type=TString()) inner_key = TSet(value_type=TList(value_type=dog_enum)) outer_key = TMap(key_type=inner_key, value_type=inner_value) map_field = TMap(key_type=outer_key, value_type=outer_value) expected = ServiceEndpoint( name="getTheStruct", args=[], results=[ ThriftSpec( field_id=0, name="success", type_info=TStruct( name="TheStruct", fields=[ ThriftSpec( field_id=1, name="myInsaneStruct", type_info=map_field, required=True, ) ], ), required=False, ) ], ) assert expected == thrift_parser._parse_thrift_endpoint( turducken_thrift.__thrift_meta__["services"][0], "getTheStruct")
def test_map_type(): collections_thrift = load_thrift_from_testdir("collections.thrift") expected = ServiceEndpoint( name="maps", args=[ ThriftSpec( name="mapofI16toI64", type_info=TMap(key_type=TI16(), value_type=TI64()), required=False, ) ], results=[ ThriftSpec( name="success", type_info=TMap(key_type=TBool(), value_type=TByte()), required=False, ) ], ) result = thrift_parser._parse_thrift_endpoint( collections_thrift.__thrift_meta__["services"][0], "maps") assert expected == result
def test_invalid_ti64(): assert (TI64().validate_arg(9223372036854775808) == "Value is too large to be a 64 bit integer") assert (TI64().validate_arg(-9223372036854775809) == "Value is too small to be a 64 bit integer")
def test_valid_ti64(): assert TI64().validate_arg(9223372036854775807) is None assert TI64().validate_arg(-9223372036854775808) is None
def test_base_type_translate_int(): assert 4 == TI64().format_arg_for_thrift(4, None)