3 SLj{@sdZdZddlZddlZy ddlZWnek r@ddlZYnXddlmZddlm Z ddlm Z ddlm Z ddl m Z dd l mZdd l mZdd l mZdd l mZdd l mZddl mZddlmZddlmZddlmZddlmZddlmZGdddeZGdddeejZGdddeejZGdddeejZGdddeZGdddeZ Gd d!d!eZ!Gd"d#d#eZ"Gd$d%d%eZ#Gd&d'd'eZ$Gd(d)d)eZ%Gd*d+d+ejZ&ed,d-e!e dmdnge!e dodpge!d6e dqdrgid;e"d/d6d7fdd;e"d/d6d4fdd;e"d/d6dKfdd;e"d/d6d^fdgoogle.protobuf.python.internal.Factory2Message.one_more_fieldzprotobuf_unittest.TestServicezgoogle/protobuf/unittest.proto) rFindFileContainingSymbolrr rrrrrr)rrr Z file_desc3Z file_desc4Z file_desc5r!r!r"testFindFileContainingSymbolTs:z3DescriptorPoolTestBase.testFindFileContainingSymbolc Cs&|jt|jjdWdQRXdS)NzDoes not exist)r$r%rr')rr!r!r"#testFindFileContainingSymbolFailureys z:DescriptorPoolTestBase.testFindFileContainingSymbolFailurec Cs|jjd}|j|tj|jd|j|jd|j|jd|j|j |j |j d}|jd|j|j||j|j d}|jd|j|j||j|j||j dj|j||j dj|jjd}|j|tj|jd |j|jd|j|j|j|j d}|jd |j|j||j|j d}|jd |j|j||j|j||j d j|j||j d j|j|j dj|jd|j dj|j|j dj|jd|j dj|j|j dj|jd|j dj|j|j dj|j |j dj|j|j dj|jd|j dj|jjd}|j|||j|j dj|jd|j dj|jdt|j|jdt|j|jdt|jdjxBdD]:}|j|jd|j |j|j|j ||jdjqWdS)Nz/google.protobuf.python.internal.Factory1MessagerrZNestedFactory1MessageZNestedFactory1EnumZnested_factory_1_messageZnested_factory_1_enumz/google.protobuf.python.internal.Factory2MessagerZNestedFactory2MessageZNestedFactory2EnumZnested_factory_2_messageZnested_factory_2_enumZint_with_defaultiZdouble_with_defaultg{G#@Zstring_with_defaultz hello worldZbool_with_defaultZenum_with_defaultzEgoogle.protobuf.python.internal.Factory2Message.NestedFactory2MessageZbytes_with_defaultsac oneof_int oneof_string)r,r-)rFindMessageTypeByNamerr Z Descriptorrr full_namecontaining_type assertFalse has_optionsZ nested_typesZ enum_typesfields_by_name message_type enum_typeZ assertIsNone assertTruehas_default_value default_valuelenZoneofsoneofs_by_nameZfieldsZcontaining_oneofr) rZmsg1Z nested_msg1 nested_enum1Zmsg2Z nested_msg2 nested_enum2Zmsg3rr!r!r"testFindMessageTypeByName}s                 z0DescriptorPoolTestBase.testFindMessageTypeByNamecCs|jt|jjdtjdkrH|jt|jjd|jt|jjdt}nt}|j||jj d|j||jj d|j||jj d|j||jj d|j||jj d|j||jjd|j||jjdtjdkrt}|j||jjddS)Ncpprpython)r$ TypeErrorrFindExtensionByNumberrTypeZFindMethodByNamer%AttributeErrorr.FindFieldByNameFindExtensionByNameFindEnumTypeByNameFindOneofByNameFindServiceByNamer'r)rZ error_typer!r!r"testFindTypeErrorss   z)DescriptorPoolTestBase.testFindTypeErrorsc Cs&|jt|jjdWdQRXdS)NzDoes not exist)r$r%rr.)rr!r!r" testFindMessageTypeByNameFailures z7DescriptorPoolTestBase.testFindMessageTypeByNameFailurecCs|jjd}|j|tj|jd|jdj|jd|jdj|j|j |jjd}|j|tj|jd|jdj|jd|jdj|jjd }|j|tj|jd|jd j|jd|jd j|jjd }|j|tj|jd|jd j|jd|jdjdS)Nz,google.protobuf.python.internal.Factory1EnumrZFACTORY_1_VALUE_0r*ZFACTORY_1_VALUE_1zBgoogle.protobuf.python.internal.Factory1Message.NestedFactory1EnumZNESTED_FACTORY_1_VALUE_0ZNESTED_FACTORY_1_VALUE_1z,google.protobuf.python.internal.Factory2EnumZFACTORY_2_VALUE_0ZFACTORY_2_VALUE_1zBgoogle.protobuf.python.internal.Factory2Message.NestedFactory2EnumZNESTED_FACTORY_2_VALUE_0ZNESTED_FACTORY_2_VALUE_1) rrGrr ZEnumDescriptorrvalues_by_namenumberr1r2)rZenum1r;Zenum2r<r!r!r"testFindEnumTypeByNames2 z-DescriptorPoolTestBase.testFindEnumTypeByNamec Cs&|jt|jjdWdQRXdS)NzDoes not exist)r$r%rrG)rr!r!r"testFindEnumTypeByNameFailures z4DescriptorPoolTestBase.testFindEnumTypeByNameFailurec Csvt|trtjdkrdS|jjd}|j|jd|j|j|j |j |j |j t |jjdWdQRXdS)Nr?z:google.protobuf.python.internal.Factory1Message.list_valueZ list_valuezDoes not exist) isinstance#SecondaryDescriptorFromDescriptorDBrrCrrErrlabelZLABEL_REPEATEDr1r2r$r%)rfieldr!r!r"testFindFieldByName s    z*DescriptorPoolTestBase.testFindFieldByNamec CsZt|trtjdkrdS|jjd}|j|jd|jt |jjdWdQRXdS)Nr?z;google.protobuf.python.internal.Factory2Message.oneof_field oneof_fieldzDoes not exist) rPrQrrCrrHrrr$r%)rZoneofr!r!r"testFindOneofByNames   z*DescriptorPoolTestBase.testFindOneofByNamec Cst|trtjdkrdS|jjd}|j|jd|jjd}|j|jd|j|jd|j t |jj dWdQRXdS)Nr?z>google.protobuf.python.internal.Factory2Message.one_more_fieldone_more_fieldz-google.protobuf.python.internal.another_field another_fieldizDoes not exist) rPrQrrCrrFrrrMr$r%rE)r extensionr!r!r"testFindExtensionByName%s   z.DescriptorPoolTestBase.testFindExtensionByNamecCs|jjd}|jjd}|jd}|jj||jjd}|jd}|jj||jj|}t||g}|j|t||jd|jj|}|j|t|dS)Nz/google.protobuf.python.internal.Factory1Messagez/google.protobuf.python.internal.Factory2MessagerWz,google/protobuf/internal/factory_test2.protorXZunexpected_element) rr.extensions_by_nameAddExtensionDescriptorrZFindAllExtensionssetrappend)rfactory1_messagefactory2_messagerW factory_test2rX extensionsZexpected_extension_numbersr!r!r"testFindAllExtensions7s         z,DescriptorPoolTestBase.testFindAllExtensionsc Cs|jjd}|jjd}|jd}|jj||jjd}|jd}|jj||jj|d}|j|jd|jj|d}|j|jd|jt |jj|d}WdQRXdS) Nz/google.protobuf.python.internal.Factory1Messagez/google.protobuf.python.internal.Factory2MessagerWz,google/protobuf/internal/factory_test2.protorXiii) rr.r[r\rrBrrr$r%)rr_r`rWrarXrYr!r!r"testFindExtensionByNumberOs      z0DescriptorPoolTestBase.testFindExtensionByNumbercCsj|jt|jjdWdQRX|jt|jjdWdQRX|jt|jjdWdQRXdS)Nz-google.protobuf.python.internal.another_fieldz>google.protobuf.python.internal.Factory2Message.one_more_fieldz:google.protobuf.python.internal.Factory1Message.list_value)r$r%rrErF)rr!r!r"testExtensionsAreNotFieldsfs   z1DescriptorPoolTestBase.testExtensionsAreNotFieldsc Cs@|jjd}|j|jd|jt|jjdWdQRXdS)Nzprotobuf_unittest.TestServicezDoes not exist)rrIrr/r$r%)rservicer!r!r"testFindServiceps  z&DescriptorPoolTestBase.testFindServicecCs8tj}tj||_|j|j|j|j|jdS)N) rDescriptorDatabaserDescriptorPoolrAddfactory_test1_fdfactory_test2_fdr=)rdbr!r!r"testUserDefinedDBvs    z(DescriptorPoolTestBase.testUserDefinedDBcCsTt|trtjdkrdStj|_|jj|jj |jj|j j |j dS)Nr?) rPrQrrCrrirAddSerializedFilerkSerializeToStringrlr=)rr!r!r"testAddSerializedFile}s   z,DescriptorPoolTestBase.testAddSerializedFilecsfdd}|tjtjjjd}j|tj||ttrVt j dkrVdSt j j tjj}jj|jjd}||dS)z:Test the default value of enums which don't start at zero.cs&|jdjdj}j|tjjdS)NDescriptorPoolTest1 nested_enum)rr3r8rrrrBETA)file_descriptorr8)rr!r"_CheckDefaultValues zGDescriptorPoolTestBase.testEnumDefaultValue.._CheckDefaultValuez4google/protobuf/internal/descriptor_pool_test1.protor?N)r DESCRIPTORrDefaultrrassertIsrPrQrrCrFileDescriptorProto FromString serialized_pbrj)rrvruZdescriptor_protor!)rr"testEnumDefaultValues       z+DescriptorPoolTestBase.testEnumDefaultValuecsfddfdd}|tjtj}|jtjjtj j |jtjjt j j |jtjjtj j t j |j|jtjj j}||dS)z0Check the value returned by non-existent fields.csj||j||dS)N)rr)valueZexpected_valueZ expected_type)rr!r"_CheckValueAndTypes zTDescriptorPoolTestBase.testDefaultValueForCustomMessages.._CheckValueAndTypecsyt}Wntk r t}YnXyt}Wntk rBt}YnX|jdt|jd|tf|jdttf|j dttf|j dt |j d||j dt|j|jtdS)NrFr>)Zlong NameErrorintZunicodestroptional_int32Zoptional_uint64Zoptional_floatfloatZoptional_doubleZ optional_boolboolZoptional_stringZoptional_bytesbytesZoptional_nested_enumZFOO)msgZint64Z unicode_type)rr!r"_CheckDefaultValuess   zUDescriptorPoolTestBase.testDefaultValueForCustomMessages.._CheckDefaultValuesN)r TestAllTypesrrirjrrzr{rrwr|rrZMessageFactoryZ GetPrototyper.r/)rrrZ message_classr!)rrr"!testDefaultValueForCustomMessagess          z8DescriptorPoolTestBase.testDefaultValueForCustomMessagescCsFt|trtjdkrdStjdd}|jj||jj|j dS)Nr?zsome/file.proto)r) rPrQrrCrrzrrjrorp)r file_descr!r!r"testAddFileDescriptors     z,DescriptorPoolTestBase.testAddFileDescriptorcCst|trtjdkrdStjjtjj }tjjt jj }tjjt jj }|j j ||j j ||j j |tj||j tj||j dS)Nr?)rPrQrrCrrzr{r rwr|rrrrj TEST1_FILE CheckFile TEST2_FILE)rZmore_messages_descZ test1_descZ test2_descr!r!r"testComplexNestings        z)DescriptorPoolTestBase.testComplexNestingN)__name__ __module__ __qualname__r#r&r(r)r=rJrKrNrOrTrVrZrcrdrergrnrqr}rrrr!r!r!r"r?s,%R    & rc@seZdZddZddZdS)DefaultDescriptorPoolTestcCs2tj|_tjjtjj|_ tjjt jj|_ dS)N) rrxrrrzr{r rwr|rkr rl)rr!r!r"setUps   zDefaultDescriptorPoolTest.setUpcCs|j|jjdtj|j|jjdtjj|j|jjdtjjjd|j|jj dtj j|j|jj dtjj d|j|jj dtjjjd |j|jjd tjjd dS) Nzgoogle/protobuf/unittest.protozprotobuf_unittest.TestAllTypesz-protobuf_unittest.TestAllTypes.optional_int32rzprotobuf_unittest.ForeignEnumz*protobuf_unittest.optional_int32_extensionZoptional_int32_extensionz*protobuf_unittest.TestAllTypes.oneof_fieldrUzprotobuf_unittest.TestServiceZ TestService)ryrrrrwr.rrEr3rG ForeignEnumrFr[rHr:rIZservices_by_name)rr!r!r"testFindMethodss.       z)DefaultDescriptorPoolTest.testFindMethodsN)rrrrrr!r!r!r"rsrc@seZdZddZdS)CreateDescriptorPoolTestcCstj|_tjjtjj|_ tjjt jj|_ |jj |j |jj |j |jj tjjt jj|jj tjjtjj|jj tjjtjjdS)N)rrirrrzr{r rwr|rkr rlrjrrr)rr!r!r"rs        zCreateDescriptorPoolTest.setUpN)rrrrr!r!r!r"rsrc@seZdZddZdS)rQcCstjjtjj|_tjjtjj|_t j }|j |j|j |j|j tjjt jj|j tjjt jj|j tjjtjjtj|d|_dS)N)Z descriptor_db)rrzr{r rwr|rkr rlrrhrjrrrrrir)rrmr!r!r"r(s          z)SecondaryDescriptorFromDescriptorDB.setUpN)rrrrr!r!r!r"rQ%srQc@seZdZdddZddZdS) ProtoFileNcCs*||_||_||_|pg|_|p"g|_dS)N)rrmessages dependenciespublic_dependencies)rrrrrrr!r!r"__init__;s  zProtoFile.__init__cCs|j|j}|j|j|j|j|j|jdd|jD}|j|j|dd|jD}|j|j|x&|jjD]\}}|j|d||qtWdS)NcSsg|] }|jqSr!)r).0fr!r!r" Gsz'ProtoFile.CheckFile..cSsg|] }|jqSr!)r)rrr!r!r"rIs) rrrrrrritems CheckType)rtestrrZdependencies_namesZpublic_dependencies_namesrZmsg_typer!r!r"rCs zProtoFile.CheckFile)NN)rrrrrr!r!r!r"r9s rc@seZdZddZddZdS)EnumTypecCs ||_dS)N)values)rrr!r!r"rQszEnumType.__init__c Cs|j|}|j||jdj|j|g}|j||j|j||j|j||jxjt|jD]\\}\}} |j |} |j|| j|j|| j |j| | j |j|| j |j ||jq^WdS)N.)enum_types_by_namerrjoinr/r0file enumeraterrLindexrMtyperZenum_values_by_name) rrmsg_descrr enum_descZexpected_enum_full_namerr~rMZ value_descr!r!r"rTs  zEnumType.CheckTypeN)rrrrrr!r!r!r"rOsrc@seZdZdddZddZdS) MessageTypeFNcCs ||_||_||_|pg|_dS)N) type_dict field_list is_extendablerb)rrrrrbr!r!r"rfszMessageType.__init__c Cs|dkr$|j|}dj|j|g}n|j|}dj|j|g}|j||j|j||j|j||j|j|j||j|j |j x&|j j D]\}}|j ||||qWx,t |jD]\}\}} | j|||||qWx,t |jD]\}\}} | j|||||qWdS)Nr)rrrnested_types_by_namer/rrr0rrrrrrr CheckFieldrb) rrZcontaining_type_descrrZdescZexpected_full_namesubtyperrSr!r!r"rms   zMessageType.CheckType)FN)rrrrrr!r!r!r"rds rc@seZdZddZddZdS) EnumFieldcCs||_||_||_dS)N)rM type_namer8)rrMrr8r!r!r"rszEnumField.__init__c Cs|j|}|j|j}|j||jdj|j|g}|j||j|j||j|j|j|j|jt j j |j |jt j j |j|j|j|j|j|jj|j|j|j|jj|j||j|j||j|j||jdS)Nr)r3rrrrrr/rrMr FieldDescriptorZ TYPE_ENUMrZ CPPTYPE_ENUMcpp_typer6r7rLr8r1r2r0r5r) rrrrrr field_descrexpected_field_full_namer!r!r"rs"    zEnumField.CheckFieldN)rrrrrr!r!r!r"rsrc@seZdZddZddZdS) MessageFieldcCs||_||_dS)N)rMr)rrMrr!r!r"rszMessageField.__init__c Cs|j|}|j|j}|j||jdj|j|g}|j||j|j||j|j|j|j|jt j j |j |jt j j |j|j|j|j||j|j||j|j||jtjdkr|jtt|ddS)Nrr?r8)r3rrrrrr/rrMr r TYPE_MESSAGErCPPTYPE_MESSAGErr1r7r0r4rrrCr$NotImplementedErrorgetattr) rrrrrrrZfield_type_descrr!r!r"rs"     zMessageField.CheckFieldN)rrrrrr!r!r!r"rsrc@seZdZddZddZdS) StringFieldcCs||_||_dS)N)rMr8)rrMr8r!r!r"rszStringField.__init__cCs|j|}|j||jdj|j|g}|j||j|j||j|j|j|j|jtjj |j |jtjj |j |j |j|j|j|j|j||jdS)Nr)r3rrrr/rrMr rZ TYPE_STRINGrZCPPTYPE_STRINGrr6r7r8r)rrrrrrrrr!r!r"rs   zStringField.CheckFieldN)rrrrrr!r!r!r"rsrc@seZdZddZddZdS)ExtensionFieldcCs||_||_dS)N)rM extended_type)rrMrr!r!r"rszExtensionField.__init__cCs|j|}|j||jdj|j|g}|j||j|j|j|j|j||j|jtjj |j |jtjj |j |j |j|j|j|j||j|j||j|j|j|jj|j||jdS)Nr)r[rrrr/rMrr rrrrrr1r7r6Z is_extensionZextension_scoper4rr0r)rrrrrrrrr!r!r"rs    zExtensionField.CheckFieldN)rrrrrr!r!r!r"rsrc@seZdZddZejejdkdddZddZ ejejdkdd d Z ejejdkdd d Z ejejdkdd dZ ddZ ddZddZddZdS)AddDescriptorTestc Cstj}|jtjj|jd|j|dj|j t |j|dWdQRX|jtjj j|jd|j|dj|jd|j dj |jd|j|dj dS)Nzprotobuf_unittest.TestAllTypesz,protobuf_unittest.TestAllTypes.NestedMessagezgoogle/protobuf/unittest.proto)rri AddDescriptorrrrwrr.r/r$r% NestedMessagerrr')rprefixrr!r!r" _TestMessages,  zAddDescriptorTest._TestMessager?z7With the cpp implementation, Add() must be called firstcCs|jd|jddS)Nr>r)r)rr!r!r" testMessages zAddDescriptorTest.testMessagec Cstj}|jtjj|jd|j|dj|j t |j|dWdQRX|jtj j j|jd|j|dj|jd|j dj|jd|j|djdS)Nzprotobuf_unittest.ForeignEnumz(protobuf_unittest.ForeignEnum.NestedEnumz)protobuf_unittest.TestAllTypes.NestedEnumzgoogle/protobuf/unittest.proto)rriAddEnumDescriptorrrrwrrGr/r$r%r NestedEnumrrr')rrrr!r!r" _TestEnums,  zAddDescriptorTest._TestEnumcCs|jd|jddS)Nr>r)r)rr!r!r"testEnum,s zAddDescriptorTest.testEnumc CsLtj}|jt|jdWdQRX|jtj|jd|jdj dS)Nzprotobuf_unittest.TestService) rrir$r%rIAddServiceDescriptorrZ _TESTSERVICErr/)rrr!r!r" testService2s  zAddDescriptorTest.testServicec CsLtj}|jtj|jd|jdj|jt |j dWdQRXdS)Nzgoogle/protobuf/unittest.protozprotobuf_unittest.TestAllTypes) rriAddFileDescriptorrrwrrrr$r%r')rrr!r!r"testFile=s   zAddDescriptorTest.testFilecCsRtj}tjj}|jt|j|tj}tjj ||j ||j |j|dS)N) rrirrwrr$r%rrzZ CopyToProtorjr6)rrZproto_file_namerur!r!r"testEmptyDescriptorPoolMs  z)AddDescriptorTest.testEmptyDescriptorPoolcCs tj}tjddd}|jjdd|j||j|jdj d|j|j dj dtjdd}|jjdd}|j jd d tj j tj jd |jjd d}|jjd dd|jjddtj}|j||jd|j dj |jd |jd j |jd|jdj dS)Nzsome/file.protor)rrZMessage)rzpackage.Messagezsome/filename/container.protoZ TopMessageZbbr*)rrMrrRZTopEnumZ FOREIGN_FOO)rrMZ TopService)rrirrzr4addrjrrrr.rSZFieldDescriptorProtoZ TYPE_INT32ZLABEL_OPTIONALr5r~rfrGrI)rrrZ file_protoZ message_protoZ enum_protor!r!r"testCustomDescriptorPoolYs6    z*AddDescriptorTest.testCustomDescriptorPoolcCsptj}d}tj|d}tj}d|jj|_|j ||j |}|j }|j d|j|j|j ||j dS)Nz9file_descriptor_options_with_custom_descriptor_pool.proto)rZfoo)rrirrzr Z foo_optionsoptionsZ ExtensionsZfoo_namerjrZ GetOptionsrry)rr file_nameZfile_descriptor_protoZ extension_idrurr!r!r"1testFileDescriptorOptionsWithCustomDescriptorPoolxs   zCAddDescriptorTest.testFileDescriptorOptionsWithCustomDescriptorPoolc%Cstj}|jt|jdWdQRX|jt|jdWdQRX|jt|jdWdQRX|jt|jdWdQRX|jt|jdWdQRXdS)Nr) rrir$rArrrr\r)rrr!r!r"testAddTypeErrors     z"AddDescriptorTest.testAddTypeErrorN)rrrrunittestZskipIfrrCrrrrrrrrrr!r!r!r"rs  rz4google/protobuf/internal/descriptor_pool_test1.protozgoogle.protobuf.python.internalALPHAr*rtr+EPSILONZETArETATHETArsZ nested_fieldZtheta)rDeepNestedMessageZbetaZdeep_nested_messager)rrZnested_messagerT)rGAMMADELTArIOTA KAPPA LAMBDA MU lambdaZdelta)rrZDescriptorPoolTest2z4google/protobuf/internal/descriptor_pool_test2.protoZDescriptorPoolTest3NU XIOMICRONPIRHOSIGMAZsigmaZnuZdescriptor_pool_testirr)rbz,google/protobuf/internal/more_messages.proto)rr__main__)rr*)rtr+)rr)rr)rr)rr)rr)rr)rr)rr)rr)rr)rr)rr)rr)rr)rr)rr)+__doc__ __author__ossysZ unittest2r ImportErrorZgoogle.protobufrrrrZgoogle.protobuf.internalrrrr r r r r rrrrobjectrZTestCaserrrQrrrrrrrrrrrmainr!r!r!r" s                 3#  0