<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
h1                 @   s$  d Z dZddlZyddlZW n ek
r8   ddlZY nX 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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r ej  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'
c               @   s   e 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dd Zdd Zejej dkpej dkd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 | _| jj|j | _d S )Nzsome/filename/some.protoprotobuf_unittest)namepackageNestedMessage)r   Zbb   )r   numbertypelabelForeignEnumFOREIGN_FOO   )r   r   ZFOREIGN_BAR   ZFOREIGN_BAZ   ZResponseMessageZServiceZ
CallMethodz .protobuf_unittest.NestedMessagez".protobuf_unittest.ResponseMessage)r   Z
input_typeZoutput_type)r   FileDescriptorProtomessage_typeaddfieldZFieldDescriptorProtoZ
TYPE_INT32ZLABEL_OPTIONAL	enum_typevalueZservicemethodGetDescriptorPoolpoolZAddZ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_protoZmessage_protoZ
enum_protoZservice_protoZmethod_proto r.   %/usr/lib/python3.6/descriptor_test.pysetUp>   s:    
zDescriptorTest.setUpc             C   s
   t j jS )N)r
   Defaultr"   )r,   r.   r.   r/   r!   b   s    z DescriptorTest.GetDescriptorPoolc             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 W d Q R X | jt | jjdd W d Q R X | jt | jj  W d Q R X d S )Nr   r   r   i  ZNoneEnum)	assertEqualr%   ZEnumValueNamer&   Zvalues_by_numberr   assertRaisesKeyError	TypeError)r,   r.   r.   r/   testEnumValueNamee   s    z DescriptorTest.testEnumValueNamec             C   s   | j | j| jjd j d S )Nr   )r2   r'   valuesr   )r,   r.   r.   r/   testEnumFixupst   s    zDescriptorTest.testEnumFixupsc             C   s.   | j | j| jjd j | j | j| jj d S )Nr   )r2   r%   fieldscontaining_typer'   )r,   r.   r.   r/   testContainingTypeFixupsw   s    z'DescriptorTest.testContainingTypeFixupsc             C   s   | j | j| jj d S )N)r2   r)   r+   Zcontaining_service)r,   r.   r.   r/   testContainingServiceFixups{   s    z*DescriptorTest.testContainingServiceFixupsc             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 )Nr   )r2   r'   
GetOptionsr   ZEnumOptionsr7   ZEnumValueOptionsr%   ZMessageOptionsr9   ZFieldOptionsr+   ZMethodOptionsr)   ZServiceOptions)r,   r.   r.   r/   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}|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 )NZfield1ZAnOneofZAnEnumZANENUM_VAL2ZANENUM_VAL1Fool   `	 8   l   -a *   c   i  {   iiil`	 )r   
DESCRIPTORZTestMessageWithCustomOptionsfields_by_nameoneofs_by_namer&   enum_values_by_nameZTestServiceWithCustomOptionsFindMethodByNamer=   	file_opt1r2   
Extensionsmessage_opt1
field_opt1
field_opt2
oneof_opt1	enum_opt1enum_value_opt1service_opt1method_opt1ZMETHODOPT1_VAL2DummyMessageContainingEnumZ
assertTruehas_optionsassertFalse)r,   file_descriptormessage_descriptorfield_descriptoroneof_descriptorenum_descriptorenum_value_descriptorZother_enum_value_descriptorservice_descriptormethod_descriptorfile_optionsrI   message_optionsrK   Zfield_optionsrL   rM   Zoneof_optionsrN   Zenum_optionsrO   Zenum_value_optionsrP   Zservice_optionsrQ   Zmethod_optionsrR   r.   r.   r/   testSimpleCustomOptions   s\    



z&DescriptorTest.testSimpleCustomOptionsc       
      C   s  d}d}d}d}d}d}t jj}|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  | jd|jt j  | jd|jt j  | j||jt j  | j||jt j  t jj}|j }| jd	|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 )!N      ?   r       @   Fr   Td   g$(@r   gYB?zHello, "World"s   Hello World      l        i   l            l         l        il            l    l        l    l            l    iiif)r   ZCustomOptionMinIntegerValuesrD   r=   r2   rJ   Zbool_optZ	int32_optZ	int64_optZ
uint32_optZ
uint64_optZ
sint32_optZ
sint64_optZfixed32_optZfixed64_optZsfixed32_optZsfixed64_optZCustomOptionMaxIntegerValuesZCustomOptionOtherValuesZassertAlmostEqualZ	float_optZ
double_optZ
string_optZ	bytes_optrS   ZTEST_OPTION_ENUM_TYPE2Zenum_optZSettingRealsFromPositiveIntsZSettingRealsFromNegativeInts)
r,   Z	kint32minZ	kint64minZ	kint32maxZ	kint64maxZ
kuint32maxZ
kuint64maxrW   r_   Z
dummy_enumr.   r.   r/   testDifferentCustomOptionTypes   s    

























































z-DescriptorTest.testDifferentCustomOptionTypesc             C   s  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 )NrA   iD  il  i  i  i  i  i  i  i  iI  i  iA  	         )r   ZVariousComplexOptionsrD   r=   r2   rJ   Zcomplex_opt1ZfooZquuxZcorgeZquxZcomplex_opt2ZbazZgraultZbarZgarplyZComplexOptionType2ZComplexOptionType4Zcomplex_opt4ZwaldoZfredZcomplex_opt3Zcomplexoptiontype5ZplughZcomplexopt6Zxyzzy)r,   r   optionsr.   r.   r/   testComplexExtensionOptions   sX    





















z*DescriptorTest.testComplexExtensionOptionsc       	      C   sJ  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 )NZ	fieldnameZVALUEZMethodrf   ZFileAnnotationZNestedFileAnnotationZFileExtensionAnnotationZEmbeddedMessageSetElementZMessageAnnotationZFieldAnnotationZEnumAnnotationZEnumValueAnnotationZServiceAnnotationZMethodAnnotation)r   rD   AggregateMessagerE   ZAggregateEnumvalues_by_nameZAggregateServicerH   r=   rJ   Zfileoptr2   issubfileZmsetZAggregateMessageSetElementZmessage_set_extensionmsgoptZfieldoptZenumoptZ
enumvaloptZ
serviceoptZ	methodopt)	r,   rV   rW   rX   rZ   r[   r\   r]   r^   r.   r.   r/   testAggregateOptionsR  sP    


z#DescriptorTest.testAggregateOptionsc             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  nested_fieldi  
NestedEnumi  ZNESTED_ENUM_VALUEi  nested_extensioni  )r   ZNestedOptionTyper   rD   r2   r=   rJ   rK   rE   rL   r&   rO   rG   rP   extensions_by_namerM   )r,   Znested_messagerw   Zouter_messageZnested_enumZnested_enum_valuery   r.   r.   r/   testNestedOptions  s     








z DescriptorTest.testNestedOptionsc             C   s(   | j | jj| j | j | jj| j d S )N)r2   r'   rt   r#   r%   )r,   r.   r.   r/   testFileDescriptorReferences  s    z+DescriptorTest.testFileDescriptorReferencesc             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 )Nzsome/filename/some.protor   Zproto2)r2   r#   r   r   r"   rU   rT   Zsyntaxr   r   CopyToProtoZserialized_pbZSerializeToStringr   rD   r	   r1   )r,   r-   r.   r.   r/   testFileDescriptor  s    

z!DescriptorTest.testFileDescriptorcppra   zAImmutability of descriptors is only enforced in v2 implementationc          C   C   sH  t j}t jj}|jd }|jd }|jd }| jt d |_W d Q R X | jt d |jd< W d Q R X | jt |j	j
d  W d Q R X | jt ||_W d Q R X | jt d|_W d Q R X | jt d|_W d Q R X | jt d|_W d Q R X | jt d|_W d Q R X | jt}d|_W d Q R X | jdt|j d S )Noptional_int32rx   oneof_fieldZAnotherFTz&attribute is not writable: has_options)r   rD   TestAllTypesrE   r&   rF   r3   AttributeErrorr5   r9   appendr:   rT   r2   strZ	exception)r,   rV   rW   rX   rZ   rY   er.   r.   r/   testImmutableCppDescriptor  s2    


z)DescriptorTest.testImmutableCppDescriptorN)__name__
__module____qualname__r0   r!   r6   r8   r;   r<   r>   r`   ri   rn   rv   r{   r|   r~   unittestskipIfr   TypeZVersionr   r.   r.   r.   r/   r   <   s"   $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 j S )N)r	   ZDescriptorPool)r,   r.   r.   r/   r!     s    z#NewDescriptorTest.GetDescriptorPoolN)r   r   r   __doc__r!   r.   r.   r.   r/   r     s   r   c               @   sX   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S )GeneratedDescriptorTestz:Tests for the properties of descriptors in generated code.c             C   s   | j |jd | j |jd | j || | j |jd j| | j||g | j||d i | j|j | j|j | j|j	 | j|j
 | j|j | j|j | j|j | j|jd j | j |jg  d S )Nr   zprotobuf_unittest.TestAllTypesr   )r2   r   	full_namer9   r:   assertInCheckDescriptorSequenceCheckDescriptorMappingrE   Zfields_by_numberfields_by_camelcase_namer&   rG   rF   
enum_typesrp   extension_ranges)r,   rW   r.   r.   r/   CheckMessageDescriptor  s"    z.GeneratedDescriptorTest.CheckMessageDescriptorc             C   s   | j |jd | j |jd | j |jd | j |jjd | j |jtj | j || | j |jjd | | j |jj	d | | j
||g | j
||d i | j d |j | j d |j tj dkr| j |j|j d S )Nr   optionalInt32z-protobuf_unittest.TestAllTypes.optional_int32r   r   )r2   r   camelcase_namer   r:   rt   r   rD   rE   r   r   Zextension_scoper   r   r   id)r,   rX   r.   r.   r/   CheckFieldDescriptor  s(    
z,GeneratedDescriptorTest.CheckFieldDescriptorc             C   s  | j |tjjj | j |g  | j |d | j|dk | j|| t|}| j|| | jt	|d | jt	|t	| | j|t	|d  |d  |d }| j||d  | j
|| | j|j|d | j|j|d tjjjd }| j|| | j|j|d | jt|j| | jt|jg  t|}| jt|t|d d d  | jtt| d|d< | j || tj dkr| jtt|t| n| jt|d d d S )Nr   r   zchange valuepython<r   )assertNotEqualr   TestAllExtensionsrD   r9   rU   r2   listassertGreaterlenr   indexcountZNestedTestAllTypesZassertNotInr3   
ValueErrorreversedStopIterationnextr   r   r   )r,   ZsequenceZexpected_listitemZ
other_itemZreversed_iteratorr.   r.   r/   r     s:    z/GeneratedDescriptorTest.CheckDescriptorSequencec                sz   j |tjjj  j |i   j |d  j|dk tt|j } j	||  j	||  j
t|d  j	t|t| tjdkrttt|j \}}nt|j d \}} j||  j	|j||  jt |j  W d Q R X tj dkr jt|jg  n j	d |jg  ttt|j ttt|j f} j	|ttt|j  tjdk rԇ fdd}|t|j t|j  |t|j t|j  |t|j t|j  d||<  j || ||= d|d	<  j ||  jt|jd
  jt|jt|d  tj dkrb j	tttt|j tt| n j	t|d d d S )Nr   r      r   c                s0    j t|| d   j t|| dd   d S )Nr   r   )r2   r   r   )seqiterator)r,   r.   r/   
CheckItemsB  s    zBGeneratedDescriptorTest.CheckDescriptorMapping.<locals>.CheckItemszchange valuenewZnew_keyZ	key_errorr   )r   )r   )r   r   r   rD   rE   rU   dictr   itemsr2   r   r   sysversion_infor   iterr   getr3   r5   r   r   keysr7   r4   __getitem__r   )r,   mappingZexcepted_dictkeyr   r   r.   )r,   r/   r   $  sJ    
(*z.GeneratedDescriptorTest.CheckDescriptorMappingc             C   s   t jj}| j| |jd }| j| |jd }| j| t jjd }| jd |j	 | jt j
jjdg | jt jjjdddg d S )Nr   r   r   r       rA   +   /       )r   r   )rA   r   )r   r   )r   r   )r   r   rD   r   rE   r   r   r&   r2   r:   r   r   TestMultipleExtensionRanges)r,   rW   rX   rZ   r.   r.   r/   testDescriptorU  s     



z&GeneratedDescriptorTest.testDescriptorc             C   sV   t j}| j|j | j|j | j|j | j|j | j|j | jt j	jj d S )N)
r   rD   r   Zdependenciesr   r$   r&   r(   rz   ZTestNestedExtension)r,   Zcontaining_filer.   r.   r/   testCppDescriptorContainerh  s    z2GeneratedDescriptorTest.testCppDescriptorContainerc             C   s0   t jjjd }t|j}~| jdt|j d S )Nrx   FOO)	r   r   rD   r&   r   r7   r2   r   r   )r,   enumZvalues_iterr.   r.   r/   #testCppDescriptorContainer_Iteratorr  s    
z;GeneratedDescriptorTest.testCppDescriptorContainer_Iteratorc             C   s\   t jjd }| j|jd | j|jd jd | j|jt j | j|jd | j	|j
 d S )NTestServicer   r?   )r   rD   r(   r2   r   methodsZassertIsrt   r   r   r*   )r,   r\   r.   r.   r/   testServiceDescriptory  s    z-GeneratedDescriptorTest.testServiceDescriptorc             C   sZ   t jj}|jd }| j|j | j||j | jd|j | jd|j	 | jd|j
 d S )Nr   z*protobuf_unittest.TestAllTypes.oneof_fieldr   )r   r   rD   rF   rU   rT   r2   r:   r   r   r   )r,   rW   rY   r.   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   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ejej dkddd Zejej dkddd ZdS ) DescriptorCopyToProtoTestz)Tests for CopyTo functions of Descriptor.c             C   s4   | }t j|| | j||dt|t|f  d S )Nz#Not equal,
Actual:
%s
Expected:
%s
)r   ZMerger2   r   )r,   Zactual_protoZexpected_classexpected_asciiZexpected_protor.   r.   r/   _AssertProtoEqual  s    z+DescriptorCopyToProtoTest._AssertProtoEqualc             C   s"   | }|j | | j||| d S )N)r}   r   )r,   ZdescZexpected_proto_classZexpected_proto_asciiactualr.   r.   r/   _InternalTestCopyToProto  s    
z2DescriptorCopyToProtoTest._InternalTestCopyToProtoc             C   s   | j tjjtjt d S )N)r   r   TestEmptyMessagerD   r   DescriptorProto#TEST_EMPTY_MESSAGE_DESCRIPTOR_ASCII)r,   r.   r.   r/   testCopyToProto_EmptyMessage  s    z6DescriptorCopyToProtoTest.testCopyToProto_EmptyMessagec             C   s   d}| j tjjjtj| d S )Nz
      name: 'NestedMessage'
      field: <
        name: 'bb'
        number: 1
        label: 1  # Optional
        type: 5  # TYPE_INT32
      >
      )r   r   r   r   rD   r   r   )r,   ZTEST_NESTED_MESSAGE_ASCIIr.   r.   r/   testCopyToProto_NestedMessage  s
    	z7DescriptorCopyToProtoTest.testCopyToProto_NestedMessagec             C   s   d}| j 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'
      >
      )r   r   ZTestForeignNestedrD   r   r   )r,   ZTEST_FOREIGN_NESTED_ASCIIr.   r.   r/   $testCopyToProto_ForeignNestedMessage  s
    
z>DescriptorCopyToProtoTest.testCopyToProto_ForeignNestedMessagec             C   s   d}| j tjjtj| d S )Nz
      name: 'ForeignEnum'
      value: <
        name: 'FOREIGN_FOO'
        number: 4
      >
      value: <
        name: 'FOREIGN_BAR'
        number: 5
      >
      value: <
        name: 'FOREIGN_BAZ'
        number: 6
      >
      )r   r   r   rD   r   ZEnumDescriptorProto)r,   ZTEST_FOREIGN_ENUM_ASCIIr.   r.   r/   testCopyToProto_ForeignEnum  s
    z5DescriptorCopyToProtoTest.testCopyToProto_ForeignEnumc             C   s   d}| j tjjtj| d S )Nz
      name: 'TestDeprecatedFields'
      field: <
        name: 'deprecated_int32'
        number: 1
        label: 1  # Optional
        type: 5  # TYPE_INT32
        options: <
          deprecated: true
        >
      >
      )r   r   ZTestDeprecatedFieldsrD   r   r   )r,   ZTEST_DEPRECATED_FIELDS_ASCIIr.   r.   r/   testCopyToProto_Options  s
    z1DescriptorCopyToProtoTest.testCopyToProto_Optionsc             C   s   d}| j tjjtj| d S )Nz}
      name: 'TestEmptyMessageWithExtensions'
      extension_range: <
        start: 1
        end: 536870912
      >
      )r   r   ZTestEmptyMessageWithExtensionsrD   r   r   )r,   Z(TEST_EMPTY_MESSAGE_WITH_EXTENSIONS_ASCIIr.   r.   r/   testCopyToProto_AllExtensions  s
    z7DescriptorCopyToProtoTest.testCopyToProto_AllExtensionsc             C   s   d}| j tjjtj| d S )Na  
      name: 'TestMultipleExtensionRanges'
      extension_range: <
        start: 42
        end: 43
      >
      extension_range: <
        start: 4143
        end: 4244
      >
      extension_range: <
        start: 65536
        end: 536870912
      >
      )r   r   r   rD   r   r   )r,   Z*TEST_MESSAGE_WITH_SEVERAL_EXTENSIONS_ASCIIr.   r.   r/   !testCopyToProto_SeveralExtensions  s
    z;DescriptorCopyToProtoTest.testCopyToProto_SeveralExtensionsc             C   s   d}| j tjtj| d S )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   r   rD   r   r   )r,   Z%UNITTEST_IMPORT_FILE_DESCRIPTOR_ASCIIr.   r.   r/   testCopyToProto_FileDescriptor  s    0 z8DescriptorCopyToProtoTest.testCopyToProto_FileDescriptorc             C   s   d}| j tjjtj| d S )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   r   r   rD   r   ZServiceDescriptorProto)r,   ZTEST_SERVICE_ASCIIr.   r.   r/   !testCopyToProto_ServiceDescriptorN  s
    z;DescriptorCopyToProtoTest.testCopyToProto_ServiceDescriptorr   z It is not implemented in python.c             C   s&   d}t jjjd}| j|tj| d S )Nz}
      name: 'Foo'
      input_type: '.protobuf_unittest.FooRequest'
      output_type: '.protobuf_unittest.FooResponse'
    r?   )r   r   rD   rH   r   r   ZMethodDescriptorProto)r,   r   r]   r.   r.   r/    testCopyToProto_MethodDescriptora  s    	z:DescriptorCopyToProtoTest.testCopyToProto_MethodDescriptorz!Pure python does not raise error.c             C   sb   t j }| jttjjj| | jttjjj| | jttj	jj| t j
 }| jttjj| d S )N)r   r   r3   r5   r   r   rD   r}   r   r   r   r   )r,   r-   protor.   r.   r/   testCopyToProto_TypeErrorr  s    z3DescriptorCopyToProtoTest.testCopyToProto_TypeErrorN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r.   r.   r.   r/   r     s$   	;

r   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 j }d|_|jj }|j|_|jj }d|_|jj }d|_|jj }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|jd jt
jj | j|jd jt
jj | j|jd jj| | j|jd jd jd | j|jd jd j|jd jd  | j|j | j|jd j tj  dkr| j!t" d|jd _W d Q R X d S )NZFoo2ZSubr   BARr   r   uint64_fieldra   Z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   ZTYPE_MESSAGE	type_name	TYPE_ENUMMakeDescriptorr2   r9   cpp_typeCPPTYPE_UINT64ZCPPTYPE_MESSAGEr:   Znested_typesr   r   rU   rT   r   r   r3   r   )	r,   file_descriptor_protor   r   r   enum_type_valr   
enum_fieldresultr.   r.   r/   "testMakeDescriptorWithNestedFields  sX    















z5MakeDescriptorTest.testMakeDescriptorWithNestedFieldsc             C   s   t j }d|_|jj }|j|_|jj }d|_|jj }d|_d|_|jj }d|_d|_t	j
j|_t	j
j|_|jj }d|_d|_t	j
j|_t	j
j|_d	|_t	j|}| j|jd
 jt	j
j d S )Nr?   r   r   r   r   r   ra   r   zFoo.FOOr   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r2   r9   r   r   )r,   r   r   r   r   r   r   r   r.   r.   r/   &testMakeDescriptorWithUnsignedIntField  s.    









z9MakeDescriptorTest.testMakeDescriptorWithUnsignedIntFieldc             C   sF   t j }tj}|jj| tj|}|j }| j	d|j
tj j d S )Ne   )r   r   r   ro   rD   r}   r   r   r=   r2   rJ   ru   rq   )r,   descriptor_protoZaggregate_messageZreformed_descriptorrm   r.   r.   r/   testMakeDescriptorWithOptions  s    
z0MakeDescriptorTest.testMakeDescriptorWithOptionsc             C   s   t j }d|_dddddg}dddddg}x2tt|D ]"}|jj }|d |_|| |_q8W tj	|}x,tt|D ]}| j
|j| j||  qvW d S )	NZBarZfoo_fooZFooBarZfooBazZfooFooZfoobarZfooBarr   )r   r   r   ranger   r   r   r   r   r   r2   r9   r   )r,   r   namesZcamelcase_namesr   r   r   r.   r.   r/   testCamelcaseName  s    


z$MakeDescriptorTest.testCamelcaseNamec             C   s   t j }d|_ddddddg}dddddd	g}x2tt|D ]"}|jj }|d
 |_|| |_q<W d	|_t	j
|}x,tt|D ]}| j|j| j||  qW d S )NZTestJsonNameZ
field_nameZ	fieldNameZ	FieldNameZ_field_nameZ
FIELD_NAME	json_nameZ	FIELDNAMEz@typer   )r   r   r   r   r   r   r   r   r   r   r   r2   r9   )r,   r   r   Z
json_namesr   r   r   r.   r.   r/   testJsonName  s    




zMakeDescriptorTest.testJsonNameN)r   r   r   r   r   r   r   r   r.   r.   r.   r/   r     s
   /
r   __main__)r   
__author__r   Z	unittest2r   ImportErrorZgoogle.protobufr   r   r   r   Zgoogle.protobuf.internalr   r   r   r	   r
   r   r   ZTestCaser   r   r   r   r   r   mainr.   r.   r.   r/   <module>    s:       ? |v
