3 SÉLjï¦ã @s$dZdZddlZy ddlZWnek r8ddlZYnXddlmZddlmZddlm Z ddlm Z ddl m Z dd l m Z dd lmZdd lmZdd lmZdd lmZdZGdd„dejƒZGdd„deƒZGdd„dejƒZGdd„dejƒZGdd„dejƒZedk�r ejƒdS)z1Unittest for google.protobuf.internal.descriptor.z#robinson@google.com (Will Robinson)éN)Úunittest_custom_options_pb2)Úunittest_import_pb2)Ú unittest_pb2)Údescriptor_pb2)Úapi_implementation)Ú test_util)Ú descriptor)Údescriptor_pool)Úsymbol_database)Ú text_formatz name: 'TestEmptyMessage' c@s¤eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zejejƒdkp’ejƒdkdƒd d!„ƒZd"S)#ÚDescriptorTestcCstjddd�}|jjdd�}|jjddtjjtjjd�|jjd d�}|j jd d d �|j jd dd �|j jddd �|jjdd�|j jdd�}|j jdddd�}|j ƒ|_ |j j|ƒ|j j|jƒ|_|jj|j|_|jj|j|_|jj|j|_|jj|j|_dS)Nzsome/filename/some.protoÚprotobuf_unittest)ÚnameÚpackageÚ NestedMessage)rZbbé)rÚnumberÚtypeÚlabelÚ ForeignEnumÚ FOREIGN_FOOé)rrZ FOREIGN_BARéZ FOREIGN_BAZéZResponseMessageZServiceZ CallMethodz .protobuf_unittest.NestedMessagez".protobuf_unittest.ResponseMessage)rZ input_typeZ output_type)rÚFileDescriptorProtoÚ message_typeÚaddÚfieldZFieldDescriptorProtoZ TYPE_INT32ZLABEL_OPTIONALÚ enum_typeÚvalueZserviceÚmethodÚGetDescriptorPoolÚpoolZAddZFindFileByNamerÚmy_fileÚmessage_types_by_nameÚ my_messageÚenum_types_by_nameÚmy_enumÚservices_by_nameÚ my_serviceÚmethods_by_nameÚ my_method)ÚselfÚ file_protoZ message_protoZ enum_protoZ service_protoZ method_proto©r.ú%/usr/lib/python3.6/descriptor_test.pyÚsetUp>s:   zDescriptorTest.setUpcCs tjƒjS)N)r ÚDefaultr")r,r.r.r/r!bsz DescriptorTest.GetDescriptorPoolcCs¨|j|jjddƒdƒ|j|jjdjdj|jjddƒƒ|jtƒ�|jjddƒWdQRX|jtƒ�|jjddƒWdQRX|jtƒ�|jjƒWdQRXdS)NrrriçZNoneEnum) Ú assertEqualr%Z EnumValueNamer&Zvalues_by_numberrÚ assertRaisesÚKeyErrorÚ TypeError)r,r.r.r/ÚtestEnumValueNamees    z DescriptorTest.testEnumValueNamecCs|j|j|jjdjƒdS)Nr)r2r'Úvaluesr)r,r.r.r/ÚtestEnumFixupstszDescriptorTest.testEnumFixupscCs.|j|j|jjdjƒ|j|j|jjƒdS)Nr)r2r%ÚfieldsÚcontaining_typer')r,r.r.r/ÚtestContainingTypeFixupswsz'DescriptorTest.testContainingTypeFixupscCs|j|j|jjƒdS)N)r2r)r+Zcontaining_service)r,r.r.r/ÚtestContainingServiceFixups{sz*DescriptorTest.testContainingServiceFixupscCs”|j|jjƒtjƒƒ|j|jjdjƒtjƒƒ|j|jjƒtjƒƒ|j|jj djƒtj ƒƒ|j|j jƒtj ƒƒ|j|j jƒtjƒƒdS)Nr)r2r'Ú GetOptionsrZ EnumOptionsr7ZEnumValueOptionsr%ZMessageOptionsr9Z FieldOptionsr+Z MethodOptionsr)ZServiceOptions)r,r.r.r/ÚtestGetOptions~s         zDescriptorTest.testGetOptionscCsÌtj}tjj}|jd}|jd}|jd}|jd}|jd}tjj}|jdƒ} |j ƒ} tj } |j d| j | ƒ|j ƒ} tj } |j d| j | ƒ|j ƒ}tj}|j d |j |ƒtj}|j d |j |ƒ|j ƒ}tj}|j d|j |ƒ|j ƒ}tj}|j d|j |ƒ|j ƒ}tj}|j d |j |ƒ|j ƒ}tj}|j d|j |ƒ| j ƒ}tj}|j tj|j |ƒtjj}|j|jƒ|j|jƒ|j|jƒ|j|jƒ|j|jƒ|j|jƒ|j|jƒdS)NZfield1ZAnOneofZAnEnumZ ANENUM_VAL2Z ANENUM_VAL1ÚFoolê` é8l-aëé*écié{iÈÿÿÿi�ÿÿÿiëüÿÿlýÿÿÿê` )rÚ DESCRIPTORZTestMessageWithCustomOptionsÚfields_by_nameÚoneofs_by_namer&Úenum_values_by_nameZTestServiceWithCustomOptionsÚFindMethodByNamer=Ú file_opt1r2Ú ExtensionsÚ message_opt1Ú field_opt1Ú field_opt2Ú oneof_opt1Ú enum_opt1Úenum_value_opt1Ú service_opt1Ú method_opt1ZMETHODOPT1_VAL2ÚDummyMessageContainingEnumZ assertTrueÚ has_optionsÚ assertFalse)r,Úfile_descriptorÚmessage_descriptorÚfield_descriptorÚoneof_descriptorÚenum_descriptorÚenum_value_descriptorZother_enum_value_descriptorÚservice_descriptorÚmethod_descriptorÚ file_optionsrIÚmessage_optionsrKZ field_optionsrLrMZ oneof_optionsrNZ enum_optionsrOZenum_value_optionsrPZservice_optionsrQZmethod_optionsrRr.r.r/ÚtestSimpleCustomOptionsŒs\           z&DescriptorTest.testSimpleCustomOptionsc Csúd}d}d}d}d}d}tjj}|jƒ}|jd|jtjƒ|j||jtjƒ|j||jtjƒ|jd|jtj ƒ|jd|jtj ƒ|j||jtj ƒ|j||jtj ƒ|jd|jtj ƒ|jd|jtjƒ|j||jtjƒ|j||jtjƒtjj}|jƒ}|jd |jtjƒ|j||jtjƒ|j||jtjƒ|j||jtj ƒ|j||jtj ƒ|j||jtj ƒ|j||jtj ƒ|j||jtj ƒ|j||jtjƒ|j||jtjƒ|j||jtjƒtjj}|jƒ}|jd|jtjƒ|jd |jtjd ƒ|jd |jtjƒ|jd|jtjƒ|jd|jtjƒtj} |j| j|jtjƒtjj}|jƒ}|jd|jtjd ƒ|jd|jtjƒtjj}|jƒ}|jd|jtjd ƒ|jd |jtjƒdS)!Nééé?ré é@FrTédg¢Õ$Óü°(@rgûYŒBÊÀó?zHello, "World"s HelloWorldé éšli€llûÿÿÿliÿÿÿllÿÿÿÿllÿÿllÿÿÿÿiœÿÿÿiôÿÿÿifÿÿÿ)rZCustomOptionMinIntegerValuesrDr=r2rJZbool_optZ int32_optZ int64_optZ uint32_optZ uint64_optZ sint32_optZ sint64_optZ fixed32_optZ fixed64_optZ sfixed32_optZ sfixed64_optZCustomOptionMaxIntegerValuesZCustomOptionOtherValuesZassertAlmostEqualZ float_optZ double_optZ string_optZ bytes_optrSZTEST_OPTION_ENUM_TYPE2Zenum_optZSettingRealsFromPositiveIntsZSettingRealsFromNegativeInts) r,Z kint32minZ kint64minZ kint32maxZ kint64maxZ kuint32maxZ kuint64maxrWr_Z dummy_enumr.r.r/ÚtestDifferentCustomOptionTypesÂs¤                                                             z-DescriptorTest.testDifferentCustomOptionTypescCsÊtjj}|jƒ}|jd|jtjjƒ|jd|jtjjtjƒ|jd|jtjjtj j ƒ|jd|jtj j ƒ|jd|jtj jtj ƒ|jd|jtj jjƒ|jd|jtj jjtjƒ|jd|jtj jjtj j ƒ|jd |jtj jtjjƒ|jd |jtj jtjjtjƒ|jd |jtj jtjjtj j ƒ|jd |jtjjjjƒ|jd |jtj jjƒ|jd|jtjj ƒ|jd|jtjjjƒ|jd|jtjjƒdS)NrAiDiliÛiŽiçiÏiØiåiÎiIi³iAé éé)rZVariousComplexOptionsrDr=r2rJZ complex_opt1ZfooZquuxZcorgeZquxZ complex_opt2ZbazZgraultZbarZgarplyZComplexOptionType2ZComplexOptionType4Z complex_opt4ZwaldoZfredZ complex_opt3Zcomplexoptiontype5ZplughZ complexopt6Zxyzzy)r,rÚoptionsr.r.r/ÚtestComplexExtensionOptions sX                             z*DescriptorTest.testComplexExtensionOptionsc CsJtj}tjj}|jd}tjj}|jd}tjj}|jdƒ}|jƒj tj }|j d|j ƒ|j d|j ƒ|j d|jj ƒ|j d|jj tj j ƒ|j d|jj tjjj ƒ|j d |jƒj tjj ƒ|j d |jƒj tjj ƒ|j d |jƒj tjj ƒ|j d |jƒj tjj ƒ|j d |jƒj tjj ƒ|j d|jƒj tjj ƒdS)NZ fieldnameZVALUEZMethodrfZFileAnnotationZNestedFileAnnotationZFileExtensionAnnotationZEmbeddedMessageSetElementZMessageAnnotationZFieldAnnotationZEnumAnnotationZEnumValueAnnotationZServiceAnnotationZMethodAnnotation)rrDÚAggregateMessagerEZ AggregateEnumÚvalues_by_nameZAggregateServicerHr=rJZfileoptr2ÚiÚsÚsubÚfileZmsetZAggregateMessageSetElementZmessage_set_extensionÚmsgoptZfieldoptZenumoptZ enumvaloptZ serviceoptZ methodopt) r,rVrWrXrZr[r\r]r^r.r.r/ÚtestAggregateOptionsRsP           z#DescriptorTest.testAggregateOptionscCs¶tjjj}|jd|jƒjtjƒ|jd}|jd|jƒjtj ƒtjj}|j d}|jd|jƒjtj ƒ|j d}|jd|jƒjtj ƒ|jd}|jd |jƒjtjƒdS) NiéÚ nested_fieldiêÚ NestedEnumiëZNESTED_ENUM_VALUEiìÚnested_extensionií)rZNestedOptionTyperrDr2r=rJrKrErLr&rOrGrPÚextensions_by_namerM)r,Znested_messagerwZ outer_messageZ nested_enumZnested_enum_valueryr.r.r/ÚtestNestedOptionsƒs          z DescriptorTest.testNestedOptionscCs(|j|jj|jƒ|j|jj|jƒdS)N)r2r'rtr#r%)r,r.r.r/ÚtestFileDescriptorReferences—sz+DescriptorTest.testFileDescriptorReferencescCs�|j|jjdƒ|j|jjdƒ|j|jj|jƒ|j|jjƒ|jd|jjƒtj ƒ}|jj |ƒ|j|jj |j ƒƒ|jt jjtjƒƒdS)Nzsome/filename/some.protor Zproto2)r2r#rrr"rUrTZsyntaxrrÚ CopyToProtoZ serialized_pbZSerializeToStringrrDr r1)r,r-r.r.r/ÚtestFileDescriptor›s   z!DescriptorTest.testFileDescriptorÚcpprazAImmutability of descriptors is only enforced in v2 implementationcCCsHtj}tjj}|jd}|jd}|jd}|jtƒ� d|_WdQRX|jtƒ�d|jd<WdQRX|jtƒ�|j j dƒWdQRX|jtƒ� ||_ WdQRX|jtƒ� d|_ WdQRX|jtƒ� d|_ WdQRX|jtƒ� d|_ WdQRX|jtƒ� d|_ WdQRX|jtƒ� }d|_ WdQRX|j dt|jƒƒdS)NÚoptional_int32rxÚ oneof_fieldZAnotherFTz&attribute is not writable: has_options)rrDÚ TestAllTypesrEr&rFr3ÚAttributeErrorr5r9Úappendr:rTr2ÚstrZ exception)r,rVrWrXrZrYÚer.r.r/ÚtestImmutableCppDescriptor¨s2            z)DescriptorTest.testImmutableCppDescriptorN)Ú__name__Ú __module__Ú __qualname__r0r!r6r8r;r<r>r`rirnrvr{r|r~ÚunittestÚskipIfrÚTypeZVersionr‡r.r.r.r/r <s"$6^21 r c@seZdZdZdd„ZdS)ÚNewDescriptorTestzARedo the same tests as above, but with a separate DescriptorPool.cCstjƒS)N)r ZDescriptorPool)r,r.r.r/r!Êsz#NewDescriptorTest.GetDescriptorPoolN)rˆr‰rŠÚ__doc__r!r.r.r.r/rŽÇsrŽc@sXeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dS)ÚGeneratedDescriptorTestz:Tests for the properties of descriptors in generated code.cCsÒ|j|jdƒ|j|jdƒ|j||ƒ|j|jdj|ƒ|j||gƒ|j||diƒ|j|jƒ|j|jƒ|j|j ƒ|j|j ƒ|j|j ƒ|j|j ƒ|j|j ƒ|j|jdjƒ|j|jgƒdS)Nr‚zprotobuf_unittest.TestAllTypesr)r2rÚ full_namer9r:ÚassertInÚCheckDescriptorSequenceÚCheckDescriptorMappingrEZfields_by_numberÚfields_by_camelcase_namer&rGrFÚ enum_typesrpÚextension_ranges)r,rWr.r.r/ÚCheckMessageDescriptorÑs"        z.GeneratedDescriptorTest.CheckMessageDescriptorcCsØ|j|jdƒ|j|jdƒ|j|jdƒ|j|jjdƒ|j|jtjƒ|j||ƒ|j|jjd|ƒ|j|jj d|ƒ|j ||gƒ|j ||diƒ|jd|j ƒ|jd|j ƒt jƒdkrÔ|j|j|jƒdS)Nr€Ú optionalInt32z-protobuf_unittest.TestAllTypes.optional_int32r‚r)r2rÚcamelcase_namer‘r:rtrrDrEr•r’Zextension_scoperrr�Úid)r,rXr.r.r/ÚCheckFieldDescriptorès(   z,GeneratedDescriptorTest.CheckFieldDescriptorcCs´|j|tjjjƒ|j|gƒ|j|dƒ|j|dkƒ|j||ƒt|ƒ}|j||ƒ|jt |ƒdƒ|jt |ƒt |ƒƒ|j|t |ƒd|dƒ|d}|j||dƒ|j ||ƒ|j|j |ƒdƒ|j|j |ƒdƒtj jjd}|j||ƒ|j|j |ƒdƒ|jt|j |ƒ|jt|j gƒt|ƒ}|jt|ƒt|ƒddd…ƒ|jtt|ƒd|d<|j||ƒtjƒdk�rœ|jtt|ƒƒt|ƒƒn|jt|ƒddƒdS)Nrrz change valueÚpythonú<éÿÿÿÿrŸ)ÚassertNotEqualrÚTestAllExtensionsrDr9rUr2ÚlistÚ assertGreaterÚlenr’ÚindexÚcountZNestedTestAllTypesZ assertNotInr3Ú ValueErrorÚreversedÚ StopIterationÚnextrr�r…)r,ZsequenceZ expected_listÚitemZ other_itemZreversed_iteratorr.r.r/r“s:        z/GeneratedDescriptorTest.CheckDescriptorSequencec sFˆj|tjjjƒˆj|iƒˆj|dƒˆj|dkƒt|jƒƒ}ˆj||ƒˆj||ƒˆj t |ƒdƒˆjt |ƒt |ƒƒt j d kr t t|jƒƒƒ\}}n|jƒd\}}ˆj||ƒˆj|j|ƒ|ƒˆjtƒ�|jƒWdQRXtjƒdk�r ˆjt|jgƒnˆjd|jgƒƒt t|jƒƒƒt t|jƒƒƒf}ˆj|t t|jƒƒƒƒt j d k�r¤‡fdd„}||jƒ|jƒƒ||jƒ|jƒƒ||jƒ|jƒƒd||<ˆj||ƒ||=d|d <ˆj||ƒˆjt|jd ƒˆjt|jt |ƒdƒtjƒdk�r.ˆjt tt|jƒƒƒƒt t|ƒƒƒnˆjt|ƒdd ƒdS)Nrrér�cs0ˆjt|ƒ|dƒˆjt|ƒ|dd…ƒdS)Nrr)r2rªr¢)ÚseqÚiterator)r,r.r/Ú CheckItemsBszBGeneratedDescriptorTest.CheckDescriptorMapping..CheckItemsz change valueÚnewZnew_keyZ key_errorrž)r¬)r¬)r rr¡rDrErUÚdictÚitemsr2r£r¤ÚsysÚ version_inforªÚiterr’Úgetr3r5rr�Úkeysr7ZiterkeysZ itervaluesZ iteritemsr4Ú __getitem__r…)r,ÚmappingZ excepted_dictÚkeyr«r¯r.)r,r/r”$sJ             &z.GeneratedDescriptorTest.CheckDescriptorMappingcCs„tjj}|j|ƒ|jd}|j|ƒ|jd}|j|ƒtjjd}|jd|j ƒ|jtj jj d gƒ|jtj jj d d dgƒdS)Nr€r™rré rAé+é/é”é)rr»)rAr¼)r½r¾)r¿r») rr‚rDr˜rErœr•r&r2r:r¡r—ÚTestMultipleExtensionRanges)r,rWrXrZr.r.r/ÚtestDescriptorUs     z&GeneratedDescriptorTest.testDescriptorcCsVtj}|j|jƒ|j|jƒ|j|jƒ|j|jƒ|j|jƒ|jtj jjƒdS)N) rrDr“Z dependenciesr”r$r&r(rzZTestNestedExtension)r,Zcontaining_filer.r.r/ÚtestCppDescriptorContainerhs     z2GeneratedDescriptorTest.testCppDescriptorContainercCs0tjjjd}t|jƒ}~|jdt|ƒjƒdS)NrxÚFOO) rr‚rDr&rµr7r2rªr)r,ÚenumZ values_iterr.r.r/Ú#testCppDescriptorContainer_Iteratorrs z;GeneratedDescriptorTest.testCppDescriptorContainer_IteratorcCs\tjjd}|j|jdƒ|j|jdjdƒ|j|jtjƒ|j|jdƒ|j |j ƒdS)NÚ TestServicerr?) rrDr(r2rÚmethodsZassertIsrtr¥r”r*)r,r\r.r.r/ÚtestServiceDescriptorys  z-GeneratedDescriptorTest.testServiceDescriptorcCsZtjj}|jd}|j|jƒ|j||jƒ|jd|jƒ|jd|j ƒ|jd|j ƒdS)Nr�z*protobuf_unittest.TestAllTypes.oneof_fieldr) rr‚rDrFrUrTr2r:rr‘r¥)r,rWrYr.r.r/ÚtestOneofDescriptor�s  z+GeneratedDescriptorTest.testOneofDescriptorN) rˆr‰rŠr�r˜rœr“r”rÁrÂrÅrÈrÉr.r.r.r/r�Îs#1 r�c@s eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zejejƒdkdƒdd„ƒZejejƒdkdƒdd„ƒZdS) ÚDescriptorCopyToProtoTestz)Tests for CopyTo functions of Descriptor.cCs4|ƒ}tj||ƒ|j||dt|ƒt|ƒfƒdS)Nz#Not equal, Actual: %s Expected: %s )r ZMerger2r…)r,Z actual_protoZexpected_classÚexpected_asciiZexpected_protor.r.r/Ú_AssertProtoEqual�s  z+DescriptorCopyToProtoTest._AssertProtoEqualcCs"|ƒ}|j|ƒ|j|||ƒdS)N)r}rÌ)r,ZdescZexpected_proto_classZexpected_proto_asciiÚactualr.r.r/Ú_InternalTestCopyToProto˜s z2DescriptorCopyToProtoTest._InternalTestCopyToProtocCs|jtjjtjtƒdS)N)rÎrÚTestEmptyMessagerDrÚDescriptorProtoÚ#TEST_EMPTY_MESSAGE_DESCRIPTOR_ASCII)r,r.r.r/ÚtestCopyToProto_EmptyMessageŸsz6DescriptorCopyToProtoTest.testCopyToProto_EmptyMessagecCsd}|jtjjjtj|ƒdS)Nzš name: 'NestedMessage' field: < name: 'bb' number: 1 label: 1 # Optional type: 5 # TYPE_INT32 > )rÎrr‚rrDrrÐ)r,ZTEST_NESTED_MESSAGE_ASCIIr.r.r/ÚtestCopyToProto_NestedMessage¥s z7DescriptorCopyToProtoTest.testCopyToProto_NestedMessagecCsd}|jtjjtj|ƒdS)Nzð name: 'TestForeignNested' field: < name: 'foreign_nested' number: 1 label: 1 # Optional type: 11 # TYPE_MESSAGE type_name: '.protobuf_unittest.TestAllTypes.NestedMessage' > )rÎrZTestForeignNestedrDrrÐ)r,ZTEST_FOREIGN_NESTED_ASCIIr.r.r/Ú$testCopyToProto_ForeignNestedMessageµs z>DescriptorCopyToProtoTest.testCopyToProto_ForeignNestedMessagecCsd}|jtjjtj|ƒdS)Nzð name: 'ForeignEnum' value: < name: 'FOREIGN_FOO' number: 4 > value: < name: 'FOREIGN_BAR' number: 5 > value: < name: 'FOREIGN_BAZ' number: 6 > )rÎrrrDrZEnumDescriptorProto)r,ZTEST_FOREIGN_ENUM_ASCIIr.r.r/ÚtestCopyToProto_ForeignEnumÆs z5DescriptorCopyToProtoTest.testCopyToProto_ForeignEnumcCsd}|jtjjtj|ƒdS)Nzç name: 'TestDeprecatedFields' field: < name: 'deprecated_int32' number: 1 label: 1 # Optional type: 5 # TYPE_INT32 options: < deprecated: true > > )rÎrZTestDeprecatedFieldsrDrrÐ)r,ZTEST_DEPRECATED_FIELDS_ASCIIr.r.r/ÚtestCopyToProto_OptionsÜs z1DescriptorCopyToProtoTest.testCopyToProto_OptionscCsd}|jtjjtj|ƒdS)Nz} name: 'TestEmptyMessageWithExtensions' extension_range: < start: 1 end: 536870912 > )rÎrZTestEmptyMessageWithExtensionsrDrrÐ)r,Z(TEST_EMPTY_MESSAGE_WITH_EXTENSIONS_ASCIIr.r.r/ÚtestCopyToProto_AllExtensionsïs z7DescriptorCopyToProtoTest.testCopyToProto_AllExtensionscCsd}|jtjjtj|ƒdS)Na name: 'TestMultipleExtensionRanges' extension_range: < start: 42 end: 43 > extension_range: < start: 4143 end: 4244 > extension_range: < start: 65536 end: 536870912 > )rÎrrÀrDrrÐ)r,Z*TEST_MESSAGE_WITH_SEVERAL_EXTENSIONS_ASCIIr.r.r/Ú!testCopyToProto_SeveralExtensionsýs z;DescriptorCopyToProtoTest.testCopyToProto_SeveralExtensionscCsd}|jtjtj|ƒdS)Nad name: 'google/protobuf/unittest_import.proto' package: 'protobuf_unittest_import' dependency: 'google/protobuf/unittest_import_public.proto' message_type: < name: 'ImportMessage' field: < name: 'd' number: 1 label: 1 # Optional type: 5 # TYPE_INT32 > > aŒenum_type: < name: 'ImportEnum' value: < name: 'IMPORT_FOO' number: 7 > value: < name: 'IMPORT_BAR' number: 8 > value: < name: 'IMPORT_BAZ' number: 9 > > enum_type: < name: 'ImportEnumForMap' value: < name: 'UNKNOWN' number: 0 > value: < name: 'FOO' number: 1 > value: < name: 'BAR' number: 2 > > options: < java_package: 'com.google.protobuf.test' optimize_for: 1 # SPEED zG cc_enable_arenas: true > public_dependency: 0 að name: 'google/protobuf/unittest_import.proto' package: 'protobuf_unittest_import' dependency: 'google/protobuf/unittest_import_public.proto' message_type: < name: 'ImportMessage' field: < name: 'd' number: 1 label: 1 # Optional type: 5 # TYPE_INT32 > > enum_type: < name: 'ImportEnum' value: < name: 'IMPORT_FOO' number: 7 > value: < name: 'IMPORT_BAR' number: 8 > value: < name: 'IMPORT_BAZ' number: 9 > > enum_type: < name: 'ImportEnumForMap' value: < name: 'UNKNOWN' number: 0 > value: < name: 'FOO' number: 1 > value: < name: 'BAR' number: 2 > > options: < java_package: 'com.google.protobuf.test' optimize_for: 1 # SPEED a7 name: 'google/protobuf/unittest_import.proto' package: 'protobuf_unittest_import' dependency: 'google/protobuf/unittest_import_public.proto' message_type: < name: 'ImportMessage' field: < name: 'd' number: 1 label: 1 # Optional type: 5 # TYPE_INT32 > > enum_type: < name: 'ImportEnum' value: < name: 'IMPORT_FOO' number: 7 > value: < name: 'IMPORT_BAR' number: 8 > value: < name: 'IMPORT_BAZ' number: 9 > > enum_type: < name: 'ImportEnumForMap' value: < name: 'UNKNOWN' number: 0 > value: < name: 'FOO' number: 1 > value: < name: 'BAR' number: 2 > > options: < java_package: 'com.google.protobuf.test' optimize_for: 1 # SPEED cc_enable_arenas: true > public_dependency: 0 )rÎrrDrr)r,Z%UNITTEST_IMPORT_FILE_DESCRIPTOR_ASCIIr.r.r/ÚtestCopyToProto_FileDescriptors 0z8DescriptorCopyToProtoTest.testCopyToProto_FileDescriptorcCsd}|jtjjtj|ƒdS)NaM name: 'TestService' method: < name: 'Foo' input_type: '.protobuf_unittest.FooRequest' output_type: '.protobuf_unittest.FooResponse' > method: < name: 'Bar' input_type: '.protobuf_unittest.BarRequest' output_type: '.protobuf_unittest.BarResponse' > )rÎrrÆrDrZServiceDescriptorProto)r,ZTEST_SERVICE_ASCIIr.r.r/Ú!testCopyToProto_ServiceDescriptorNs z;DescriptorCopyToProtoTest.testCopyToProto_ServiceDescriptorr�z It is not implemented in python.cCs&d}tjjjdƒ}|j|tj|ƒdS)Nz} name: 'Foo' input_type: '.protobuf_unittest.FooRequest' output_type: '.protobuf_unittest.FooResponse' r?)rrÆrDrHrÎrZMethodDescriptorProto)r,rËr]r.r.r/Ú testCopyToProto_MethodDescriptoras z:DescriptorCopyToProtoTest.testCopyToProto_MethodDescriptorz!Pure python does not raise error.cCsbtjƒ}|jttjjj|ƒ|jttjjj|ƒ|jttj jj|ƒtj ƒ}|jtt jj|ƒdS)N) rrr3r5rrÏrDr}rrÆrÐr)r,r-Úprotor.r.r/ÚtestCopyToProto_TypeErrorrsz3DescriptorCopyToProtoTest.testCopyToProto_TypeErrorN)rˆr‰rŠr�rÌrÎrÒrÓrÔrÕrÖr×rØrÙrÚr‹rŒrr�rÛrÝr.r.r.r/rÊŒs$ ;  rÊc@s4eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd S) ÚMakeDescriptorTestc CsÂtjƒ}d|_|jjƒ}|j|_|jjƒ}d|_|jjƒ}d|_|jjƒ}d|_d|_|j jƒ}d|_d|_t j j |_ t j j|_|j jƒ}d|_d |_t j j |_ t j j|_d|_|j jƒ}d|_d |_t j j |_ t j j|_d |_t j|ƒ}|j|jd jt j jƒ|j|jdjt j jƒ|j|jdjj|ƒ|j|jd jd jd ƒ|j|jd jd j|jd jd ƒ|j|jƒ|j|jd jƒtj ƒdk�r¾|j!t"ƒ�d|jd _WdQRXdS)NZFoo2ZSubrÃÚBARr¬rÚ uint64_fieldraZnested_message_fieldÚ bar_fieldz Foo2.Sub.FOOrzFoo2.Sub.bar_fieldrF)#rrrrrÚ nested_typerrrrrÚFieldDescriptorÚLABEL_REQUIREDrÚ TYPE_UINT64rZ TYPE_MESSAGEÚ type_nameÚ TYPE_ENUMÚMakeDescriptorr2r9Úcpp_typeÚCPPTYPE_UINT64ZCPPTYPE_MESSAGEr:Z nested_typesr‘r–rUrTrr�r3rƒ) r,Úfile_descriptor_protorrârÚ enum_type_valrÚ enum_fieldÚresultr.r.r/Ú"testMakeDescriptorWithNestedFields‰sX                  z5MakeDescriptorTest.testMakeDescriptorWithNestedFieldscCsÆtjƒ}d|_|jjƒ}|j|_|jjƒ}d|_|jjƒ}d|_d|_|jjƒ}d|_d|_t j j |_ t j j |_|jjƒ}d|_d|_t j j |_ t j j|_d |_t j|ƒ}|j|jd jt j jƒdS) Nr?rÃrßr¬rràrarázFoo.FOOr)rrrrrrrrrrrãrärrårrçrærèr2r9rérê)r,rërrrìrrírîr.r.r/Ú&testMakeDescriptorWithUnsignedIntField¸s.          z9MakeDescriptorTest.testMakeDescriptorWithUnsignedIntFieldcCsFtjƒ}tj}|jj|ƒtj|ƒ}|jƒ}|j d|j tj j ƒdS)Née) rrÐrrorDr}rrèr=r2rJrurq)r,Údescriptor_protoZaggregate_messageZreformed_descriptorrmr.r.r/ÚtestMakeDescriptorWithOptionsÓs  z0MakeDescriptorTest.testMakeDescriptorWithOptionscCsštjƒ}d|_dddddg}dddddg}x2tt|ƒƒD]"}|jjƒ}|d|_|||_q8Wtj |ƒ}x,tt|ƒƒD]}|j |j |j ||ƒqvWdS) NZBarZfoo_fooZFooBarZfooBazZfooFooZfoobarZfooBarr) rrÐrÚranger¤rrrrrèr2r9rš)r,ròÚnamesZcamelcase_namesr¥rrîr.r.r/ÚtestCamelcaseNameÝs   z$MakeDescriptorTest.testCamelcaseNamecCs¤tjƒ}d|_ddddddg}dddddd g}x2tt|ƒƒD]"}|jjƒ}|d |_|||_q s:           ?|v