o
    ˷e>                     @   s  d Z dZddlZddl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dlmZ dZdZede G dd dejZG dd deZG dd dejZG dd dejZG dd dejZedkre  dS dS )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'
aO  syntax = "proto2";

package protobuf_unittest;

message NestedMessage {
  enum ForeignEnum {
    FOREIGN_FOO = 4;
    FOREIGN_BAR = 5;
    FOREIGN_BAZ = 6;
  }
  optional int32 bb = 1;
}

message ResponseMessage {
}

service Service {
  rpc CallMethod(.protobuf_unittest.NestedMessage) returns (.protobuf_unittest.ResponseMessage);
}

errorc                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Ze	
e dkddd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Ze	
e dkd#d$d% Zd&d' Zd(S ))DescriptorTestc                 C   s  t jddd}|jjdd}|jjddt jjt jjd |jjd	d}|j	jd
dd |j	jddd |j	jddd |jjdd |j
jdd}|jjdddd}|  | _| j| | j|j| _| jj|j | _| jj|j | _| jj|j | _| jj|j | _d S )Nsome/filename/some.protoprotobuf_unittest)namepackageNestedMessage)r   bb   )r   numbertypelabelForeignEnumFOREIGN_FOO   )r   r   FOREIGN_BAR   FOREIGN_BAZ   ResponseMessageService
CallMethodz .protobuf_unittest.NestedMessagez".protobuf_unittest.ResponseMessage)r   
input_typeoutput_type)r   FileDescriptorProtomessage_typeaddfieldFieldDescriptorProto
TYPE_INT32LABEL_OPTIONAL	enum_typevalueservicemethodGetDescriptorPoolpoolAddFindFileByNamer   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_protomessage_proto
enum_protoservice_protomethod_proto rB   _/var/www/ideatree/venv/lib/python3.10/site-packages/google/protobuf/internal/descriptor_test.pysetUpR   sF   
zDescriptorTest.setUpc                 C   s
   t  jS N)r
   Defaultr0   r<   rB   rB   rC   r/   v   s   
z DescriptorTest.GetDescriptorPoolc                 C   s   |  | jddd |  | jjd jd j| jdd | t | jdd W d    n1 s5w   Y  | t | jdd W d    n1 sQw   Y  | t | j  W d    d S 1 slw   Y  d S )Nr   r   r   i  NoneEnum)	assertEqualr5   EnumValueNamer6   values_by_numberr   assertRaisesKeyError	TypeErrorrG   rB   rB   rC   testEnumValueNamey   s*   "z DescriptorTest.testEnumValueNamec                 C   s   |  | j| jjd j d S Nr   )rI   r7   valuesr   rG   rB   rB   rC   testEnumFixups   s   zDescriptorTest.testEnumFixupsc                 C   s.   |  | j| jjd j |  | j| jj d S rP   )rI   r5   fieldscontaining_typer7   rG   rB   rB   rC   testContainingTypeFixups   s   z'DescriptorTest.testContainingTypeFixupsc                 C   s   |  | j| jj d S rE   )rI   r9   r;   containing_servicerG   rB   rB   rC   testContainingServiceFixups   s   z*DescriptorTest.testContainingServiceFixupspythonz<GetDebugString is only available with the cpp implementationc                 C   s   |  | j t d S rE   )rI   r3   GetDebugStringTEST_FILE_DESCRIPTOR_DEBUGrG   rB   rB   rC   testGetDebugString   s   z!DescriptorTest.testGetDebugStringc                 C   s   |  | j t  |  | jjd  t  |  | j t  |  | jj	d  t
  |  | j t  |  | j t  d S rP   )rI   r7   
GetOptionsr   EnumOptionsrQ   EnumValueOptionsr5   MessageOptionsrS   FieldOptionsr;   MethodOptionsr9   ServiceOptionsrG   rB   rB   rC   testGetOptions   s$   zDescriptorTest.testGetOptionsc                 C   s  t j}t jj}|jd }|jd }|jd }|jd }|jd }t jj}|d}	|	 }
t j
}| d|
j|  |	 }t j}| d|j|  |	 }t j}| d	|j|  t j}| d
|j|  |	 }t j}| d|j|  |	 }t j}| d|j|  |	 }t j}| d|j|  |	 }t j}| d|j|  |		 }t j}| t j|j|  t jj}| |j | |j | |j | |j | |j | |j | |j d S )Nfield1AnOneofAnEnumANENUM_VAL2ANENUM_VAL1Fool   `	 il   -a *   ii{   l`	 )r   
DESCRIPTORTestMessageWithCustomOptionsfields_by_nameoneofs_by_namer6   enum_values_by_nameTestServiceWithCustomOptionsFindMethodByNamer\   	file_opt1rI   
Extensionsmessage_opt1
field_opt1
field_opt2
oneof_opt1	enum_opt1enum_value_opt1service_opt1method_opt1METHODOPT1_VAL2DummyMessageContainingEnum
assertTruehas_optionsassertFalse)r<   file_descriptormessage_descriptorfield_descriptoroneof_descriptorenum_descriptorenum_value_descriptorother_enum_value_descriptorservice_descriptormethod_descriptorfile_optionsrs   message_optionsru   field_optionsrv   rw   oneof_optionsrx   enum_optionsry   enum_value_optionsrz   service_optionsr{   method_optionsr|   rB   rB   rC   testSimpleCustomOptions   sl   



z&DescriptorTest.testSimpleCustomOptionsc                 C   s4   t jj}t }|| | t|j	 d d S )N   )
r   rm   rl   r   DescriptorProtoCopyToProtorI   lenoptions
ListFields)r<   r   r>   rB   rB   rC   testCustomOptionsCopyTo   s   
z&DescriptorTest.testCustomOptionsCopyToc           
      C   s  d}d}d}d}d}d}t jj}| }| d|jt j  | ||jt j  | ||jt j  | d|jt j	  | d|jt j
  | ||jt j  | ||jt j  | d|jt j  | d|jt j  | ||jt j  | ||jt j  t jj}| }| d	|jt j  | ||jt j  | ||jt j  | ||jt j	  | ||jt j
  | ||jt j  | ||jt j  | ||jt j  | ||jt j  | ||jt j  | ||jt j  t jj}| }| d
|jt j  | d|jt j d | d|jt j  | d|jt j  | d|jt j  t j}	| |	j|jt j  t jj}| }| d|jt j d | d|jt j  t jj}| }| d|jt j d | d|jt j  d S )Ni   l         il    l    l    Fr   Tig$(@r   gYB?zHello, "World"s   Hello World      iif)r   CustomOptionMinIntegerValuesrl   r\   rI   rt   bool_opt	int32_opt	int64_opt
uint32_opt
uint64_opt
sint32_opt
sint64_optfixed32_optfixed64_optsfixed32_optsfixed64_optCustomOptionMaxIntegerValuesCustomOptionOtherValuesassertAlmostEqual	float_opt
double_opt
string_opt	bytes_optr~   TEST_OPTION_ENUM_TYPE2enum_optSettingRealsFromPositiveIntsSettingRealsFromNegativeInts)
r<   	kint32min	kint64min	kint32max	kint64max
kuint32max
kuint64maxr   r   
dummy_enumrB   rB   rC   testDifferentCustomOptionTypes   s   
































z-DescriptorTest.testDifferentCustomOptionTypesc                 C   s  t jj}| }| d|jt j j | d|jt j jt j  | d|jt j jt j	 j
 | d|jt j j | d|jt j jt j  | d|jt j jj | d|jt j jjt j  | d|jt j jjt j	 j
 | d	|jt j jt j j | d
|jt j jt j jt j  | d|jt j jt j jt j	 j
 | d|jt jjj j | d|jt j jj | d|jt j j
 | d|jt j jj | d|jt j j d S )Nrj   iD  il  i  i  i  i  i  i  i  iI  i  iA  	         )r   VariousComplexOptionsrl   r\   rI   rt   complex_opt1foomooocorgemoocomplex_opt2bazgraultbargarplyComplexOptionType2ComplexOptionType4complex_opt4waldofredcomplex_opt3complexoptiontype5plughcomplexopt6xyzzy)r<   r   r   rB   rB   rC   testComplexExtensionOptionsC  s   















z*DescriptorTest.testComplexExtensionOptionsc           	      C   sJ  t j}t jj}|jd }t jj}|jd }t jj}|d}| j	t j
 }| d|j | d|j | d|jj | d|jj	t j
 j | d|jj	t jj j | d	| j	t j j | d
| j	t j j | d| j	t j j | d| j	t j j | d| j	t j j | d| j	t j j d S )N	fieldnameVALUEMethodd   FileAnnotationNestedFileAnnotationFileExtensionAnnotationEmbeddedMessageSetElementMessageAnnotationFieldAnnotationEnumAnnotationEnumValueAnnotationServiceAnnotationMethodAnnotation)r   rl   AggregateMessagern   AggregateEnumvalues_by_nameAggregateServicerr   r\   rt   fileoptrI   issubfilemsetAggregateMessageSetElementmessage_set_extensionmsgoptfieldoptenumopt
enumvalopt
serviceopt	methodopt)	r<   r   r   r   r   r   r   r   r   rB   rB   rC   testAggregateOptionsu  s   


z#DescriptorTest.testAggregateOptionsc                 C   s   t jjj}| d| jt j  |jd }| d| jt j	  t jj}|j
d }| d| jt j  |jd }| d| jt j  |jd }| d	| jt j  d S )
Ni  nested_fieldi  
NestedEnumi  NESTED_ENUM_VALUEi  nested_extensioni  )r   NestedOptionTyper   rl   rI   r\   rt   ru   rn   rv   r6   ry   rp   rz   extensions_by_namerw   )r<   nested_messager   outer_messagenested_enumnested_enum_valuer   rB   rB   rC   testNestedOptions  s.   




z DescriptorTest.testNestedOptionsc                 C   s(   |  | jj| j |  | jj| j d S rE   )rI   r7   r   r3   r5   rG   rB   rB   rC   testFileDescriptorReferences  s   z+DescriptorTest.testFileDescriptorReferencesc                 C   s   |  | jjd |  | jjd |  | jj| j | | jj |  d| jj t	 }| j
| |  | jj|  |  tjjt  d S )Nr   r   proto2)rI   r3   r   r   r0   r   r   syntaxr   r$   r   serialized_pbSerializeToStringr   rl   r	   rF   )r<   r=   rB   rB   rC   testFileDescriptor  s   
z!DescriptorTest.testFileDescriptorzAImmutability of descriptors is only enforced in v2 implementationc                 C   s  t j}t jj}|jd }|jd }|jd }| t d |_W d    n1 s)w   Y  | t d |jd< W d    n1 sCw   Y  | t |j	
d  W d    n1 s^w   Y  | t ||_W d    n1 svw   Y  | t d|_W d    n1 sw   Y  | t d|_W d    n1 sw   Y  | t d|_W d    n1 sw   Y  | t d|_W d    n1 sw   Y  | t}d|_W d    n1 sw   Y  | dt|j d S )Noptional_int32r   oneof_fieldAnotherFTz&attribute is not writable: has_options)r   rl   TestAllTypesrn   r6   ro   rL   AttributeErrorrN   rS   appendrT   r   rI   str	exception)r<   r   r   r   r   r   erB   rB   rC   testImmutableCppDescriptor  sF   


z)DescriptorTest.testImmutableCppDescriptorc                 C   sl   t jj}|jd }| |jg  |jd }| |jg  |jd }| |jd  |jd }| |jd  d S )Nrepeated_int32repeated_nested_messageoptionalgroupoptional_nested_message)r   r
  rl   rn   rI   default_value)r<   r   r'   rB   rB   rC   testDefault  s   



zDescriptorTest.testDefaultN)__name__
__module____qualname__rD   r/   rO   rR   rU   rW   unittestskipIfr   Typer[   rc   r   r   r   r   r   r   r  r  r  r  rB   rB   rB   rC   r   P   s6    $

6^21

r   c                   @   s   e Zd ZdZdd ZdS )NewDescriptorTestzARedo the same tests as above, but with a separate DescriptorPool.c                 C   s   t  S rE   )r	   DescriptorPoolrG   rB   rB   rC   r/     s   z#NewDescriptorTest.GetDescriptorPoolN)r  r  r  __doc__r/   rB   rB   rB   rC   r    s    r  c                   @   s`   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd ZdS )GeneratedDescriptorTestz:Tests for the properties of descriptors in generated code.c                 C   s   |  |jd |  |jd |  || |  |jd j| | ||g | ||d i | |j | |j | |j	 | |j
 | |j | |j | |j | |jd j |  |jg  d S )Nr
  zprotobuf_unittest.TestAllTypesr   )rI   r   	full_namerS   rT   assertInCheckDescriptorSequenceCheckDescriptorMappingrn   fields_by_numberfields_by_camelcase_namer6   rp   ro   
enum_typesr   extension_ranges)r<   r   rB   rB   rC   CheckMessageDescriptor  s&   z.GeneratedDescriptorTest.CheckMessageDescriptorc                 C   s   |  |jd |  |jd |  |jd |  |jjd |  |jtj |  || |  |jjd | |  |jj	d | | 
||g | 
||d i |  d |j |  d |j | |j t dkrr|  |j|j d S d S )Nr  optionalInt32z-protobuf_unittest.TestAllTypes.optional_int32r
  cpp)rI   r   camelcase_namer!  rT   r   r   rl   rn   r&  r"  extension_scoper+   r   has_presencer   r  id)r<   r   rB   rB   rC   CheckFieldDescriptor  s4   
z,GeneratedDescriptorTest.CheckFieldDescriptorc                 C   s  |  |tjjj |  |g  |  |d | |dk | || t|}| || | t	|d | t	|t	| | |t	|d  |d  |d }| ||d  | 
|| | ||d | ||d tjjjd }| || | ||d | t|j| | t|jg  t|}| t|t|d d d  | tt| d|d< |  || t dkr| tt|t| d S | t|d d d S )Nr   r   change valuerX   <)assertNotEqualr   TestAllExtensionsrl   rS   r   rI   listassertGreaterr   r"  indexcountNestedTestAllTypesassertNotInrL   
ValueErrorreversedStopIterationnextr   r  r  )r<   sequenceexpected_listitem
other_itemreversed_iteratorrB   rB   rC   r#  0  s<   z/GeneratedDescriptorTest.CheckDescriptorSequencec                 C   s  |  |tjjj |  |i  |  |d | |dk t| }| || | || | 	t
|d | t
|t
| tt| \}}| || | ||| | t |  W d    n1 smw   Y  t dkr| t|jg  n	| d |g  tt| tt| f}| |tt|  d||< |  || ||= d|d< |  || | t|jd | t|jt
|d  t dkr| t
tt| t
t| d S | t|d d d S )	Nr   r   rX   r2  newnew_key	key_errorr3  )r4  r   r5  rl   rn   r   dictitemsrI   r7  r   r?  iterr"  getrL   rN   r   r  keysrQ   rM   __getitem__r  )r<   mappingexcepted_dictkeyrB  rB   rB   rC   r$  S  s@   

 (z.GeneratedDescriptorTest.CheckDescriptorMappingc                 C   s   t jj}| | |jd }| | |jd }| | t jjd }| d |j	 | t j
jjdg | t jjjg d d S )Nr  r*  r   )r       ))rj   +   )i/  i  )i   rQ  )r   r
  rl   r)  rn   r0  r&  r6   rI   rT   r5  r(  TestMultipleExtensionRanges)r<   r   r   r   rB   rB   rC   testDescriptorz  s(   



z&GeneratedDescriptorTest.testDescriptorc                 C   sV   t j}| |j | |j | |j | |j | |j | t j	jj d S rE   )
r   rl   r#  dependenciesr$  r4   r6   r8   r   TestNestedExtension)r<   containing_filerB   rB   rC   testCppDescriptorContainer  s   z2GeneratedDescriptorTest.testCppDescriptorContainerc                 C   s0   t jjjd }t|j}~| dt|j d S )Nr   FOO)	r   r
  rl   r6   rJ  rQ   rI   r?  r   )r<   enumvalues_iterrB   rB   rC   #testCppDescriptorContainer_Iterator  s   
z;GeneratedDescriptorTest.testCppDescriptorContainer_Iteratorc                 C   sH   t jj}t jjj}| t|jd | d |jv  | ||jv  d S )N   )	r   r
  rl   r   rI   r   nested_typesr   r   )r<   r   nested_message_descriptorrB   rB   rC   "testDescriptorNestedTypesContainer  s   
z:GeneratedDescriptorTest.testDescriptorNestedTypesContainerc                 C   s\   t jjd }| |jd | |jd jd | |jt j | |jd | 	|j
 d S )NTestServicer   ri   )r   rl   r8   rI   r   methodsassertIsr   r8  r$  r:   )r<   r   rB   rB   rC   testServiceDescriptor  s   z-GeneratedDescriptorTest.testServiceDescriptorc                 C   sZ   t jj}|jd }| |j | ||j | d|j | d|j	 | d|j
 d S )Nr  z*protobuf_unittest.TestAllTypes.oneof_fieldr   )r   r
  rl   ro   r   r   rI   rT   r   r!  r8  )r<   r   r   rB   rB   rC   testOneofDescriptor  s   
z+GeneratedDescriptorTest.testOneofDescriptorN)r  r  r  r  r)  r0  r#  r$  rT  rX  r\  r`  rd  re  rB   rB   rB   rC   r     s    #'
r   c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zee dkddd ZdS )DescriptorCopyToProtoTestz)Tests for CopyTo functions of Descriptor.c                 C   s4   | }t || | ||dt|t|f  d S )Nz#Not equal,
Actual:
%s
Expected:
%s
)r   MergerI   r  )r<   actual_protoexpected_classexpected_asciiexpected_protorB   rB   rC   _AssertProtoEqual  s   z+DescriptorCopyToProtoTest._AssertProtoEqualc                 C   s"   | }| | | ||| d S rE   )r   rl  )r<   descexpected_proto_classexpected_proto_asciiactualrB   rB   rC   _InternalTestCopyToProto  s
   
z2DescriptorCopyToProtoTest._InternalTestCopyToProtoc                 C   s   |  tjjtjt d S rE   )rq  r   TestEmptyMessagerl   r   r   #TEST_EMPTY_MESSAGE_DESCRIPTOR_ASCIIrG   rB   rB   rC   testCopyToProto_EmptyMessage  s
   z6DescriptorCopyToProtoTest.testCopyToProto_EmptyMessagec                 C   s   d}|  tjjjtj| d S )Nz
      name: 'NestedMessage'
      field: <
        name: 'bb'
        number: 1
        label: 1  # Optional
        type: 5  # TYPE_INT32
      >
      )rq  r   r
  r   rl   r   r   )r<   TEST_NESTED_MESSAGE_ASCIIrB   rB   rC   testCopyToProto_NestedMessage  s   
z7DescriptorCopyToProtoTest.testCopyToProto_NestedMessagec                 C      d}|  tjjtj| d S )Nz
      name: 'TestForeignNested'
      field: <
        name: 'foreign_nested'
        number: 1
        label: 1  # Optional
        type: 11  # TYPE_MESSAGE
        type_name: '.protobuf_unittest.TestAllTypes.NestedMessage'
      >
      )rq  r   TestForeignNestedrl   r   r   )r<   TEST_FOREIGN_NESTED_ASCIIrB   rB   rC   $testCopyToProto_ForeignNestedMessage  s   z>DescriptorCopyToProtoTest.testCopyToProto_ForeignNestedMessagec                 C   rw  )Nz
      name: 'ForeignEnum'
      value: <
        name: 'FOREIGN_FOO'
        number: 4
      >
      value: <
        name: 'FOREIGN_BAR'
        number: 5
      >
      value: <
        name: 'FOREIGN_BAZ'
        number: 6
      >
      )rq  r   r   rl   r   EnumDescriptorProto)r<   TEST_FOREIGN_ENUM_ASCIIrB   rB   rC   testCopyToProto_ForeignEnum     z5DescriptorCopyToProtoTest.testCopyToProto_ForeignEnumc                 C   rw  )Na  
      name: 'TestDeprecatedFields'
      field: <
        name: 'deprecated_int32'
        number: 1
        label: 1  # Optional
        type: 5  # TYPE_INT32
        options: <
          deprecated: true
        >
      >
      field {
        name: "deprecated_int32_in_oneof"
        number: 2
        label: LABEL_OPTIONAL
        type: TYPE_INT32
        options {
          deprecated: true
        }
        oneof_index: 0
      }
      oneof_decl {
        name: "oneof_fields"
      }
      )rq  r   TestDeprecatedFieldsrl   r   r   )r<   TEST_DEPRECATED_FIELDS_ASCIIrB   rB   rC   testCopyToProto_Options	  s   z1DescriptorCopyToProtoTest.testCopyToProto_Optionsc                 C   rw  )Nz}
      name: 'TestEmptyMessageWithExtensions'
      extension_range: <
        start: 1
        end: 536870912
      >
      )rq  r   TestEmptyMessageWithExtensionsrl   r   r   )r<   (TEST_EMPTY_MESSAGE_WITH_EXTENSIONS_ASCIIrB   rB   rC   testCopyToProto_AllExtensions)  s   z7DescriptorCopyToProtoTest.testCopyToProto_AllExtensionsc                 C   rw  )Na  
      name: 'TestMultipleExtensionRanges'
      extension_range: <
        start: 42
        end: 43
      >
      extension_range: <
        start: 4143
        end: 4244
      >
      extension_range: <
        start: 65536
        end: 536870912
      >
      )rq  r   rS  rl   r   r   )r<   *TEST_MESSAGE_WITH_SEVERAL_EXTENSIONS_ASCIIrB   rB   rC   !testCopyToProto_SeveralExtensions7  r~  z;DescriptorCopyToProtoTest.testCopyToProto_SeveralExtensionsc                 C   s   d}|  tjtj| d S )Na7  
      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
    )rq  r   rl   r   r$   )r<   %UNITTEST_IMPORT_FILE_DESCRIPTOR_ASCIIrB   rB   rC   testCopyToProto_FileDescriptorM  s   5z8DescriptorCopyToProtoTest.testCopyToProto_FileDescriptorc                 C   rw  )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'
      >
      )rq  r   ra  rl   r   ServiceDescriptorProto)r<   TEST_SERVICE_ASCIIrB   rB   rC   !testCopyToProto_ServiceDescriptor  s   z;DescriptorCopyToProtoTest.testCopyToProto_ServiceDescriptorc                 C   s&   d}t jjd}| |tj| d S )Nz}
      name: 'Foo'
      input_type: '.protobuf_unittest.FooRequest'
      output_type: '.protobuf_unittest.FooResponse'
    ri   )r   ra  rl   rr   rq  r   MethodDescriptorProto)r<   rj  r   rB   rB   rC    testCopyToProto_MethodDescriptor  s   z:DescriptorCopyToProtoTest.testCopyToProto_MethodDescriptorrX   z!Pure python does not raise error.c                 C   sb   t  }| ttjjj| | ttjjj| | ttj	jj| t 
 }| ttjj| d S rE   )r   r$   rL   rN   r   rr  rl   r   r   ra  r   r   )r<   r=   protorB   rB   rC   testCopyToProto_TypeError  s$   z3DescriptorCopyToProtoTest.testCopyToProto_TypeErrorN)r  r  r  r  rl  rq  rt  rv  rz  r}  r  r  r  r  r  r  r  r  r   r  r  rB   rB   rB   rC   rf    s&    	 ;
rf  c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )MakeDescriptorTestc           	      C   s  t  }d|_|j }|j|_|j }d|_|j }d|_|j }d|_d|_|j	 }d|_d|_t
jj|_t
jj|_|j	 }d|_d	|_t
jj|_t
jj|_d|_|j	 }d|_d
|_t
jj|_t
jj|_d|_t
|}| |jd jt
jj | |jd jt
jj | |jd jj| | |jd jd jd | |jd jd j|jd jd  | |j | |jd j t  dkr| !t" d|jd _W d    d S 1 sw   Y  d S d S )NFoo2SubrY  BARr]  r   uint64_fieldr   nested_message_field	bar_fieldzFoo2.Sub.FOOr   zFoo2.Sub.bar_fieldr+  F)#r   r$   r   r%   r&   nested_typer+   r,   r   r'   r   FieldDescriptorLABEL_REQUIREDr   TYPE_UINT64r   TYPE_MESSAGE	type_name	TYPE_ENUMMakeDescriptorrI   rS   cpp_typeCPPTYPE_UINT64CPPTYPE_MESSAGErT   r^  r!  r'  r   r   r   r  rL   r  )	r<   file_descriptor_protor%   r  r+   enum_type_valr'   
enum_fieldresultrB   rB   rC   "testMakeDescriptorWithNestedFields  sf   













"z5MakeDescriptorTest.testMakeDescriptorWithNestedFieldsc                 C   s   t  }d|_|j }|j|_|j }d|_|j }d|_d|_|j }d|_d|_t	j
j|_t	j
j|_|j }d|_d|_t	j
j|_t	j
j|_d	|_t	|}| |jd
 jt	j
j d S )Nri   rY  r  r]  r   r  r   r  zFoo.FOOr   )r   r$   r   r%   r&   r+   r,   r   r'   r   r  r  r   r  r   r  r  r  rI   rS   r  r  )r<   r  r%   r+   r  r'   r  r  rB   rB   rC   &testMakeDescriptorWithUnsignedIntField  s0   









z9MakeDescriptorTest.testMakeDescriptorWithUnsignedIntFieldc                 C   sF   t  }tj}|j| t|}| }| 	d|j
tj j d S )Ne   )r   r   r   r   rl   r   r   r  r\   rI   rt   r   r   )r<   descriptor_protoaggregate_messagereformed_descriptorr   rB   rB   rC   testMakeDescriptorWithOptions	  s   
z0MakeDescriptorTest.testMakeDescriptorWithOptionsc                 C   s   t  }d|_g d}g d}tt|D ]}|j }|d |_|| |_qt	|}tt|D ]}| 
|j| j||  q2d S )NBar)foo_fooFooBarfooBazfooFoofoobar)r  fooBarr  r  r  r   )r   r   r   ranger   r'   r&   r   r   r  rI   rS   r,  )r<   r  namescamelcase_namesr8  r'   r  rB   rB   rC   testCamelcaseName  s   


z$MakeDescriptorTest.testCamelcaseNamec                 C   s   t  }d|_g d}g d}tt|D ]}|j }|d |_|| |_qd|_t	
|}tt|D ]}| |j| j||  q5d S )NTestJsonName)
field_name	fieldName	FieldName_field_name
FIELD_NAME	json_name)r  r  r  r  	FIELDNAME@typer   r  )r   r   r   r  r   r'   r&   r   r  r   r  rI   rS   )r<   r  r  
json_namesr8  r'   r  rB   rB   rC   testJsonName!  s   


zMakeDescriptorTest.testJsonNameN)r  r  r  r  r  r  r  r  rB   rB   rB   rC   r    s    /
r  __main__)r  
__author__r  warningsgoogle.protobufr   r   r   r   google.protobuf.internalr   r   r   r	   r
   r   rs  rZ   simplefilterDeprecationWarningTestCaser   r  r   rf  r  r  mainrB   rB   rB   rC   <module>   s>      ( >  v