SLjc @ s d Z d Z d d l Z y d d l Z Wn e k
rG d d l Z n Xd d l m Z d d l m Z d d l m Z d d l m
Z
d d l m Z d d l m
Z
d d
l m Z d d l m Z d d l m Z d d
l m Z d Z d e j f d YZ d e f d YZ d e j f d YZ d e j f d YZ d e j f d YZ e d k re j n d S( s1 Unittest for google.protobuf.internal.descriptor.s# robinson@google.com (Will Robinson)iN( t unittest_custom_options_pb2( t unittest_import_pb2( t unittest_pb2( t descriptor_pb2( t api_implementation( t test_util( t
descriptor( t descriptor_pool( t symbol_database( t text_formats
name: 'TestEmptyMessage'
t DescriptorTestc B s e Z d Z d Z d Z d Z d Z d Z d Z d Z d Z
d Z d
Z d Z
d Z d
Z e j e j d k p e j d k d d Z RS( c C s t j d d d d } | j j d d } | j j d d d d d t j j d
t j j | j j d d } | j j d d d d
| j j d d d d | j j d d d d | j j d d | j
j d d } | j j d d d d d d } | j | _
| j
j | | j
j | j | _ | j j | j | _ | j j | j | _ | j j | j | _ | j j | j | _ d S( Nt names some/filename/some.protot packaget protobuf_unittestt
NestedMessaget bbt numberi t typet labelt ForeignEnumt FOREIGN_FOOi t FOREIGN_BARi t FOREIGN_BAZi t ResponseMessaget Servicet
CallMethodt
input_types .protobuf_unittest.NestedMessaget output_types" .protobuf_unittest.ResponseMessage( R t FileDescriptorProtot message_typet addt fieldt FieldDescriptorProtot
TYPE_INT32t LABEL_OPTIONALt enum_typet valuet servicet methodt GetDescriptorPoolt poolt Addt FindFileByNameR t my_filet message_types_by_namet
my_messaget enum_types_by_namet my_enumt services_by_namet
my_servicet methods_by_namet my_method( t selft
file_protot
message_protot
enum_protot
service_protot method_proto( ( sL /usr/lib/python2.7/site-packages/google/protobuf/internal/descriptor_test.pyt setUp> s:
c C s
t j j S( N( R t DefaultR( ( R4 ( ( sL /usr/lib/python2.7/site-packages/google/protobuf/internal/descriptor_test.pyR' b s c C s | j | j j d d d | j | j j d j d j | j j d d | j t | j j d d Wd QX| j t | j j d d Wd QX| j t | j j Wd QXd S( NR i R i t NoneEnum( t assertEqualR- t
EnumValueNameR. t values_by_numberR t assertRaisest KeyErrort TypeError( R4 ( ( sL /usr/lib/python2.7/site-packages/google/protobuf/internal/descriptor_test.pyt testEnumValueNamee s c C s$ | j | j | j j d j d S( Ni ( R= R/ t valuesR ( R4 ( ( sL /usr/lib/python2.7/site-packages/google/protobuf/internal/descriptor_test.pyt testEnumFixupst s c C s= | j | j | j j d j | j | j | j j d S( Ni ( R= R- t fieldst containing_typeR/ ( R4 ( ( sL /usr/lib/python2.7/site-packages/google/protobuf/internal/descriptor_test.pyt testContainingTypeFixupsw s c C s | j | j | j j d S( N( R= R1 R3 t containing_service( R4 ( ( sL /usr/lib/python2.7/site-packages/google/protobuf/internal/descriptor_test.pyt testContainingServiceFixups{ s c C s | j | j j t j | j | j j d j t j | j | j j t j | j | j j d j t j
| j | j j t j | j | j
j t j d S( Ni ( R= R/ t
GetOptionsR t EnumOptionsRD t EnumValueOptionsR- t MessageOptionsRF t FieldOptionsR3 t
MethodOptionsR1 t ServiceOptions( R4 ( ( sL /usr/lib/python2.7/site-packages/google/protobuf/internal/descriptor_test.pyt testGetOptions~ s
c C st t j } t j j } | j d } | j d } | j d } | j d } | j d } t j j } | j d } | j }
t j
} | j d |
j | | j } t j
}
| j d | j |
| j } t j } | j d | j | t j } | j d
| j | | j } t j } | j d | j | | j } t j } | j d | j | | j } t j } | j d
| j | | j } t j } | j d | j | | j } t j } | j t j | j | t j j } | j | j | j | j | j | j | j | j | j | j | j | j | j | j d S( Nt field1t AnOneoft AnEnumt ANENUM_VAL2t ANENUM_VAL1t Fool ` il -a i* iii{ l` ( R t
DESCRIPTORt TestMessageWithCustomOptionst fields_by_namet oneofs_by_nameR. t enum_values_by_namet TestServiceWithCustomOptionst FindMethodByNameRK t file_opt1R= t
Extensionst message_opt1t
field_opt1t
field_opt2t
oneof_opt1t enum_opt1t enum_value_opt1t service_opt1t method_opt1t METHODOPT1_VAL2t DummyMessageContainingEnumt
assertTruet has_optionst assertFalse( R4 t file_descriptort message_descriptort field_descriptort oneof_descriptort enum_descriptort enum_value_descriptort other_enum_value_descriptort service_descriptort method_descriptort file_optionsR` t message_optionsRb t
field_optionsRc Rd t
oneof_optionsRe t enum_optionsRf t enum_value_optionsRg t service_optionsRh t method_optionsRi ( ( sL /usr/lib/python2.7/site-packages/google/protobuf/internal/descriptor_test.pyt testSimpleCustomOptions s\
c
C s d } d } d } d } d } d } t j j } | j } | j t | j t j | j | | j t j | j | | j t j | j d | j t j
| j d | j t j | j | | j t j | j | | j t j
| j d | j t j | j d | j t j | j | | j t j | j | | j t j t j j } | j } | j t | j t j | j | | j t j | j | | j t j | j | | j t j
| j | | j t j | j | | j t j | j | | j t j
| j | | j t j | j | | j t j | j | | j t j | j | | j t j t j j } | j } | j d | j t j | j d | j t j d
| j d | j t j | j d | j t j | j d
| j t j t j } | j | j | j t j t j j } | j } | j d | j t j d
| j d | j t j t j j } | j } | j d | j t j d
| j d | j t j d S( Ni i i? i i i@ i ig$(@i gYB?s Hello, "World"s Hello Worldi i iifl l l l l l l l l l l l ( R t CustomOptionMinIntegerValuesRY RK R= t FalseRa t bool_optt int32_optt int64_optt
uint32_optt
uint64_optt
sint32_optt
sint64_optt fixed32_optt fixed64_optt sfixed32_optt sfixed64_optt CustomOptionMaxIntegerValuest Truet CustomOptionOtherValuest assertAlmostEqualt float_optt
double_optt
string_optt bytes_optRk t TEST_OPTION_ENUM_TYPE2t enum_optt SettingRealsFromPositiveIntst SettingRealsFromNegativeInts(
R4 t kint32mint kint64mint kint32maxt kint64maxt
kuint32maxt
kuint64maxRp Ry t
dummy_enum( ( sL /usr/lib/python2.7/site-packages/google/protobuf/internal/descriptor_test.pyt testDifferentCustomOptionTypes s c C sY t j j } | j } | j d | j t j j | j d | j t j j t j | j d | j t j j t j j
| j d | j t j j | j d | j t j j t j
| j d | j t j j j | j d | j t j j j t j | j d | j t j j j t j j
| j d | j t j j t j j | j d
| j t j j t j j t j | j d | j t j j t j j t j j
| j d | j t j j j j | j d
| j t j j j | j d | j t j j
| j d | j t j j j | j d | j t j j d S( Ni* iD il i i i i i i i iI i iA i i i ( R t VariousComplexOptionsRY RK R= Ra t complex_opt1t foot quuxt corget quxt complex_opt2t bazt graultt bart garplyt ComplexOptionType2t ComplexOptionType4t complex_opt4t waldot fredt complex_opt3t complexoptiontype5t plught complexopt6t xyzzy( R4 R t options( ( sL /usr/lib/python2.7/site-packages/google/protobuf/internal/descriptor_test.pyt testComplexExtensionOptions sX
c C s t j } t j j } | j d } t j j } | j d } t j j } | j d } | j j t j
} | j d | j | j d | j
| j d | j j
| j d | j j t j
j
| j d | j j t j j j
| j d | j j t j j
| j d
| j j t j j
| j d | j j t j j
| j d | j j t j j
| j d
| j j t j j
| j d | j j t j j
d S( Nt fieldnamet VALUEt Methodid t FileAnnotationt NestedFileAnnotationt FileExtensionAnnotationt EmbeddedMessageSetElementt MessageAnnotationt FieldAnnotationt EnumAnnotationt EnumValueAnnotationt ServiceAnnotationt MethodAnnotation( R RY t AggregateMessageR[ t
AggregateEnumt values_by_namet AggregateServiceR_ RK Ra t fileoptR= t it st subt filet msett AggregateMessageSetElementt message_set_extensiont msgoptt fieldoptt enumoptt
enumvaloptt
serviceoptt methodopt( R4 Ro Rp Rq Rs Rt Rv Rw Rx ( ( sL /usr/lib/python2.7/site-packages/google/protobuf/internal/descriptor_test.pyt testAggregateOptionsR sP
c C s t j j j } | j d | j j t j | j d } | j d | j j t j t j j } | j
d } | j d | j j t j | j d } | j d | j j t j
| j d } | j d | j j t j d S(
Ni t nested_fieldi t
NestedEnumi t NESTED_ENUM_VALUEi t nested_extensioni ( R t NestedOptionTypeR RY R= RK Ra Rb R[ Rc R. Rf R] Rg t extensions_by_nameRd ( R4 t nested_messageR t
outer_messaget nested_enumt nested_enum_valueR ( ( sL /usr/lib/python2.7/site-packages/google/protobuf/internal/descriptor_test.pyt testNestedOptions s
c C s6 | j | j j | j | j | j j | j d S( N( R= R/ R R+ R- ( R4 ( ( sL /usr/lib/python2.7/site-packages/google/protobuf/internal/descriptor_test.pyt testFileDescriptorReferences s c C s | j | j j d | j | j j d | j | j j | j | j | j j | j d | j j t j } | j j
| | j | j j | j | j t
j j t j d S( Ns some/filename/some.protoR
t proto2( R= R+ R R R( Rn Rm t syntaxR R t CopyToProtot
serialized_pbt SerializeToStringR RY R R; ( R4 R5 ( ( sL /usr/lib/python2.7/site-packages/google/protobuf/internal/descriptor_test.pyt testFileDescriptor s
t cppi sA Immutability of descriptors is only enforced in v2 implementationc C s} t j } t j j } | j d } | j d } | j d } | j t d | _ Wd QX| j t d | j d