o
    ‹¨Êh—«  ã                   @   s$  d Z dZddlZzddlZW n ey   ddlZY nw 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 ¡  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'
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dd„ Ze e ¡ dkpMe ¡ 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© rA   úZ/var/www/html/env/lib/python3.10/site-packages/google/protobuf/internal/descriptor_test.pyÚsetUp?   sF   þÿüÿÿý
zDescriptorTest.setUpc                 C   s
   t  ¡ jS ©N)r
   ÚDefaultr/   ©r;   rA   rA   rB   r.   c   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)	ÚassertEqualr4   ÚEnumValueNamer5   Úvalues_by_numberr   ÚassertRaisesÚKeyErrorÚ	TypeErrorrF   rA   rA   rB   ÚtestEnumValueNamef   s*   ÿÿÿýÿÿ"ÿz DescriptorTest.testEnumValueNamec                 C   s   |   | j| jjd j¡ d S ©Nr   )rH   r6   Úvaluesr   rF   rA   rA   rB   ÚtestEnumFixupsu   s   zDescriptorTest.testEnumFixupsc                 C   s.   |   | j| jjd j¡ |   | j| jj¡ d S rO   )rH   r4   ÚfieldsÚcontaining_typer6   rF   rA   rA   rB   ÚtestContainingTypeFixupsx   s   z'DescriptorTest.testContainingTypeFixupsc                 C   s   |   | j| jj¡ d S rD   )rH   r8   r:   Úcontaining_servicerF   rA   rA   rB   ÚtestContainingServiceFixups|   s   z*DescriptorTest.testContainingServiceFixupsc                 C   s”   |   | j ¡ t ¡ ¡ |   | jjd  ¡ t ¡ ¡ |   | j ¡ t ¡ ¡ |   | jj	d  ¡ t 
¡ ¡ |   | j ¡ t ¡ ¡ |   | j ¡ t ¡ ¡ d S rO   )rH   r6   Ú
GetOptionsr   ÚEnumOptionsrP   ÚEnumValueOptionsr4   ÚMessageOptionsrR   ÚFieldOptionsr:   ÚMethodOptionsr8   ÚServiceOptionsrF   rA   rA   rB   Ú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   ê`	 iÈÿÿÿl   -aë é*   i�ÿÿÿiëüÿÿé{   lýÿÿÿê`	 )r   Ú
DESCRIPTORÚTestMessageWithCustomOptionsÚfields_by_nameÚoneofs_by_namer5   Úenum_values_by_nameÚTestServiceWithCustomOptionsÚFindMethodByNamerW   Ú	file_opt1rH   Ú
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_optionsrn   Úmessage_optionsrp   Úfield_optionsrq   rr   Úoneof_optionsrs   Úenum_optionsrt   Úenum_value_optionsru   Úservice_optionsrv   Úmethod_optionsrw   rA   rA   rB   ÚtestSimpleCustomOptions�   sl   ÿ


ÿÿÿ
ÿÿz&DescriptorTest.testSimpleCustomOptionsc                 C   s4   t jj}t ¡ }| |¡ |  t|j 	¡ ƒd¡ d S )Né   )
r   rh   rg   r   ÚDescriptorProtoÚCopyToProtorH   ÚlenÚoptionsÚ
ListFields)r;   r~   r=   rA   rA   rB   Ú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   Tiœÿÿÿg¢Õ$Óü°(@r   gûYŒBÊÀó?zHello, "World"s   Hello Worldé   éš   iôÿÿÿifÿÿÿ)r   ÚCustomOptionMinIntegerValuesrg   rW   rH   ro   Ú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_optry   ÚTEST_OPTION_ENUM_TYPE2Úenum_optÚSettingRealsFromPositiveIntsÚSettingRealsFromNegativeInts)
r;   Ú	kint32minÚ	kint64minÚ	kint32maxÚ	kint64maxÚ
kuint32maxÚ
kuint64maxr~   r‡   Ú
dummy_enumrA   rA   rB   Ú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 )Nre   iD  il  iÛ  iŽ  iç  iÏ  iØ  iå  iÎ  iI  i³  iA  é	   é   é   )r   ÚVariousComplexOptionsrg   rW   rH   ro   Úcomplex_opt1ÚfooÚquuxÚcorgeÚquxÚcomplex_opt2ÚbazÚgraultÚbarÚgarplyÚComplexOptionType2ÚComplexOptionType4Úcomplex_opt4ÚwaldoÚfredÚcomplex_opt3Úcomplexoptiontype5ÚplughÚcomplexopt6Úxyzzy)r;   r   r“   rA   rA   rB   ÚtestComplexExtensionOptions)  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ÚMethodéd   ÚFileAnnotationÚNestedFileAnnotationÚFileExtensionAnnotationÚEmbeddedMessageSetElementÚMessageAnnotationÚFieldAnnotationÚEnumAnnotationÚEnumValueAnnotationÚServiceAnnotationÚMethodAnnotation)r   rg   ÚAggregateMessageri   ÚAggregateEnumÚvalues_by_nameÚAggregateServicerm   rW   ro   ÚfileoptrH   ÚiÚsÚsubÚfileÚmsetÚAggregateMessageSetElementÚmessage_set_extensionÚmsgoptÚfieldoptÚenumoptÚ
enumvaloptÚ
serviceoptÚ	methodopt)	r;   r}   r~   r   r�   r‚   r„   r…   r†   rA   rA   rB   ÚtestAggregateOptions[  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   rg   rH   rW   ro   rp   ri   rq   r5   rt   rk   ru   Úextensions_by_namerr   )r;   Únested_messagerñ   Úouter_messageÚnested_enumÚnested_enum_valuerô   rA   rA   rB   ÚtestNestedOptionsŒ  s.   ÿÿ
ÿÿ
ÿ
ÿ

ÿz DescriptorTest.testNestedOptionsc                 C   s(   |   | jj| j¡ |   | jj| j¡ d S rD   )rH   r6   ræ   r2   r4   rF   rA   rA   rB   Ú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)rH   r2   r   r   r/   r|   r{   Úsyntaxr   r#   r‘   Úserialized_pbÚSerializeToStringr   rg   r	   rE   )r;   r<   rA   rA   rB   ÚtestFileDescriptor¤  s   
ÿz!DescriptorTest.testFileDescriptorÚcppr�   zAImmutability 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 sŽw   Y  |  t¡� d|_W d   ƒ n1 s¦w   Y  |  t¡� d|_W d   ƒ n1 s¾w   Y  |  t¡� d|_W d   ƒ n1 sÖw   Y  |  t¡�}d|_W d   ƒ n1 sîw   Y  |  dt|jƒ¡ d S )NÚoptional_int32rò   Úoneof_fieldÚAnotherFTz&attribute is not writable: has_options)r   rg   ÚTestAllTypesri   r5   rj   rK   ÚAttributeErrorrM   rR   ÚappendrS   r{   rH   ÚstrÚ	exception)r;   r}   r~   r   r�   r€   ÚerA   rA   rB   Ú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  rg   ri   rH   Údefault_value)r;   r~   r&   rA   rA   rB   ÚtestDefaultÏ  s   



zDescriptorTest.testDefaultN)Ú__name__Ú
__module__Ú__qualname__rC   r.   rN   rQ   rT   rV   r^   rŽ   r•   r¶   rÏ   rð   rû   rü   r  ÚunittestÚskipIfr   ÚTypeÚVersionr  r  rA   rA   rA   rB   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  ¡ S rD   )r	   ÚDescriptorPoolrF   rA   rA   rB   r.   Þ  s   z#NewDescriptorTest.GetDescriptorPoolN)r  r  r  Ú__doc__r.   rA   rA   rA   rB   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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   )rH   r   Ú	full_namerR   rS   ÚassertInÚCheckDescriptorSequenceÚCheckDescriptorMappingri   Úfields_by_numberÚfields_by_camelcase_namer5   rk   rj   Ú
enum_typesrà   Úextension_ranges)r;   r~   rA   rA   rB   Ú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¡ t ¡ dkrl|   |j|j¡ d S d S )Nr  ÚoptionalInt32z-protobuf_unittest.TestAllTypes.optional_int32r  r  )rH   r   Úcamelcase_namer  rS   ræ   r   rg   ri   r#  r  Úextension_scoper*   r   r  Úid)r;   r   rA   rA   rB   ÚCheckFieldDescriptorü  s2   ÿ
þÿýþ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 valueÚpythonú<)ÚassertNotEqualr   ÚTestAllExtensionsrg   rR   r|   rH   ÚlistÚassertGreaterr’   r  ÚindexÚcountÚNestedTestAllTypesÚassertNotInrK   Ú
ValueErrorÚreversedÚStopIterationÚnextr   r  r	  )r;   ÚsequenceÚexpected_listÚitemÚ
other_itemÚreversed_iteratorrA   rA   rB   r     s<   ÿz/GeneratedDescriptorTest.CheckDescriptorSequencec                    sX  ˆ   |tjjj¡ ˆ   |i ¡ ˆ   |d¡ ˆ  |dk¡ t| ¡ ƒ}ˆ  ||¡ ˆ  ||¡ ˆ  	t
|ƒd¡ ˆ  t
|ƒt
|ƒ¡ tjdkrPtt| ¡ ƒƒ\}}n| ¡ d \}}ˆ  ||¡ ˆ  | |¡|¡ ˆ  t¡� | ¡  W d   ƒ n1 s{w   Y  t ¡ dkr�ˆ  t|jg ¡ n	ˆ  d | g ¡¡ tt| ¡ ƒƒtt| ¡ ƒƒf}ˆ  |tt| ¡ ƒƒ¡ tjdk rÚ‡ fdd„}|| ¡ | ¡ ƒ || ¡ | ¡ ƒ || ¡ | ¡ ƒ 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   )é   r.  c                    s0   ˆ   t|ƒ| d ¡ ˆ   t|ƒ| dd … ¡ d S )Nr   r   )rH   r;  r2  )ÚseqÚiteratorrF   rA   rB   Ú
CheckItemsV  s   zBGeneratedDescriptorTest.CheckDescriptorMapping.<locals>.CheckItemsr-  ÚnewÚnew_keyÚ	key_errorr/  )r0  r   r1  rg   ri   r|   ÚdictÚitemsrH   r3  r’   ÚsysÚversion_infor;  Úiterr  ÚgetrK   rM   r   r  ÚkeysrP   ÚiterkeysÚ
itervaluesÚ	iteritemsrL   Ú__getitem__r	  )r;   ÚmappingÚexcepted_dictÚkeyr>  rD  rA   rF   rB   r!  8  sN   
ÿ

ÿ 
(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   é    ))re   é+   )i/  i”  )i   rV  )r   r  rg   r&  ri   r+  r#  r5   rH   rS   r1  r%  ÚTestMultipleExtensionRanges)r;   r~   r   r�   rA   rA   rB   ÚtestDescriptori  s(   


ÿ
ÿþþz&GeneratedDescriptorTest.testDescriptorc                 C   sV   t j}|  |j¡ |  |j¡ |  |j¡ |  |j¡ |  |j¡ |  t j	jj¡ d S rD   )
r   rg   r   Údependenciesr!  r3   r5   r7   rö   ÚTestNestedExtension)r;   Úcontaining_filerA   rA   rB   ÚtestCppDescriptorContainer|  s   ÿz2GeneratedDescriptorTest.testCppDescriptorContainerc                 C   s0   t jjjd }t|jƒ}~|  dt|ƒj¡ d S )Nrò   ÚFOO)	r   r  rg   r5   rL  rP   rH   r;  r   )r;   ÚenumÚvalues_iterrA   rA   rB   Ú#testCppDescriptorContainer_Iterator†  s   
z;GeneratedDescriptorTest.testCppDescriptorContainer_Iteratorc                 C   s\   t jjd }|  |jd¡ |  |jd jd¡ |  |jt j¡ |  |jd¡ |  	|j
¡ d S )NÚTestServicer   rd   )r   rg   r7   rH   r   ÚmethodsÚassertIsræ   r4  r!  r9   )r;   r„   rA   rA   rB   Ú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  rg   rj   r|   r{   rH   rS   r   r  r4  )r;   r~   r€   rA   rA   rB   ÚtestOneofDescriptor•  s   
ÿz+GeneratedDescriptorTest.testOneofDescriptorN)r  r  r  r  r&  r+  r   r!  rY  r]  ra  re  rf  rA   rA   rA   rB   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 e ¡ dkd¡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   ÚMergerH   r	  )r;   Úactual_protoÚexpected_classÚexpected_asciiÚexpected_protorA   rA   rB   Ú_AssertProtoEqual£  s   ÿþz+DescriptorCopyToProtoTest._AssertProtoEqualc                 C   s"   |ƒ }|  |¡ |  |||¡ d S rD   )r‘   rm  )r;   ÚdescÚexpected_proto_classÚexpected_proto_asciiÚactualrA   rA   rB   Ú_InternalTestCopyToProto¬  s
   
ÿz2DescriptorCopyToProtoTest._InternalTestCopyToProtoc                 C   s   |   tjjtjt¡ d S rD   )rr  r   ÚTestEmptyMessagerg   r   r�   Ú#TEST_EMPTY_MESSAGE_DESCRIPTOR_ASCIIrF   rA   rA   rB   Ú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
      >
      )rr  r   r  r   rg   r   r�   )r;   ÚTEST_NESTED_MESSAGE_ASCIIrA   rA   rB   Ú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'
      >
      )rr  r   ÚTestForeignNestedrg   r   r�   )r;   ÚTEST_FOREIGN_NESTED_ASCIIrA   rA   rB   Ú$testCopyToProto_ForeignNestedMessageÉ  s   ýz>DescriptorCopyToProtoTest.testCopyToProto_ForeignNestedMessagec                 C   rx  )Nzð
      name: 'ForeignEnum'
      value: <
        name: 'FOREIGN_FOO'
        number: 4
      >
      value: <
        name: 'FOREIGN_BAR'
        number: 5
      >
      value: <
        name: 'FOREIGN_BAZ'
        number: 6
      >
      )rr  r   r   rg   r   ÚEnumDescriptorProto)r;   ÚTEST_FOREIGN_ENUM_ASCIIrA   rA   rB   ÚtestCopyToProto_ForeignEnumÚ  ó   ýz5DescriptorCopyToProtoTest.testCopyToProto_ForeignEnumc                 C   rx  )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"
      }
      )rr  r   ÚTestDeprecatedFieldsrg   r   r�   )r;   ÚTEST_DEPRECATED_FIELDS_ASCIIrA   rA   rB   ÚtestCopyToProto_Optionsð  s   ýz1DescriptorCopyToProtoTest.testCopyToProto_Optionsc                 C   rx  )Nz}
      name: 'TestEmptyMessageWithExtensions'
      extension_range: <
        start: 1
        end: 536870912
      >
      )rr  r   ÚTestEmptyMessageWithExtensionsrg   r   r�   )r;   Ú(TEST_EMPTY_MESSAGE_WITH_EXTENSIONS_ASCIIrA   rA   rB   ÚtestCopyToProto_AllExtensions  s   ýz7DescriptorCopyToProtoTest.testCopyToProto_AllExtensionsc                 C   rx  )Na  
      name: 'TestMultipleExtensionRanges'
      extension_range: <
        start: 42
        end: 43
      >
      extension_range: <
        start: 4143
        end: 4244
      >
      extension_range: <
        start: 65536
        end: 536870912
      >
      )rr  r   rX  rg   r   r�   )r;   Ú*TEST_MESSAGE_WITH_SEVERAL_EXTENSIONS_ASCIIrA   rA   rB   Ú!testCopyToProto_SeveralExtensions  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
    )rr  r   rg   r   r#   )r;   Ú%UNITTEST_IMPORT_FILE_DESCRIPTOR_ASCIIrA   rA   rB   ÚtestCopyToProto_FileDescriptor4  s   5ýz8DescriptorCopyToProtoTest.testCopyToProto_FileDescriptorc                 C   rx  )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'
      >
      )rr  r   rb  rg   r   ÚServiceDescriptorProto)r;   ÚTEST_SERVICE_ASCIIrA   rA   rB   Ú!testCopyToProto_ServiceDescriptoro  s   ýz;DescriptorCopyToProtoTest.testCopyToProto_ServiceDescriptorr.  z It is not implemented in python.c                 C   s&   d}t jj d¡}|  |tj|¡ d S )Nz}
      name: 'Foo'
      input_type: '.protobuf_unittest.FooRequest'
      output_type: '.protobuf_unittest.FooResponse'
    rd   )r   rb  rg   rm   rr  r   ÚMethodDescriptorProto)r;   rk  r…   rA   rA   rB   Ú testCopyToProto_MethodDescriptor‚  s   ÿýz:DescriptorCopyToProtoTest.testCopyToProto_MethodDescriptorz!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 rD   )r   r#   rK   rM   r   rs  rg   r‘   r   rb  r�   r   )r;   r<   ÚprotorA   rA   rB   ÚtestCopyToProto_TypeError“  s$   þþþþz3DescriptorCopyToProtoTest.testCopyToProto_TypeErrorN)r  r  r  r  rm  rr  ru  rw  r{  r~  r‚  r…  r‡  r‰  rŒ  r  r  r   r  rŽ  r�  rA   rA   rA   rB   rg     s.    	 ;
þ

þrg  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 säw   Y  d S d S )NÚFoo2ÚSubr^  ÚBARrA  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ÚMakeDescriptorrH   rR   Úcpp_typeÚCPPTYPE_UINT64ÚCPPTYPE_MESSAGErS   Únested_typesr  r$  r|   r{   r   r  rK   r  )	r;   Úfile_descriptor_protor$   r˜  r*   Úenum_type_valr&   Ú
enum_fieldÚresultrA   rA   rB   Ú"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 )Nrd   r^  r”  rA  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Ÿ  rH   rR   r   r¡  )r;   r¤  r$   r*   r¥  r&   r¦  r§  rA   rA   rB   Ú&testMakeDescriptorWithUnsignedIntFieldÙ  s0   









ÿz9MakeDescriptorTest.testMakeDescriptorWithUnsignedIntFieldc                 C   sF   t  ¡ }tj}|j |¡ t |¡}| ¡ }|  	d|j
tj j¡ d S )Née   )r   r�   r   rÞ   rg   r‘   r   rŸ  rW   rH   ro   rê   rã   )r;   Údescriptor_protoÚaggregate_messageÚreformed_descriptorr“   rA   rA   rB   Ú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Ÿ  rH   rR   r(  )r;   r«  ÚnamesÚcamelcase_namesr4  r&   r§  rA   rA   rB   Ú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Ÿ  rH   rR   )r;   r«  r·  Ú
json_namesr4  r&   r§  rA   rA   rB   ÚtestJsonName  s   


ÿÿzMakeDescriptorTest.testJsonNameN)r  r  r  r¨  r©  r®  r¹  rÄ  rA   rA   rA   rB   r‘  ¨  s    /
r‘  Ú__main__)r  Ú
__author__rJ  Ú	unittest2r  ÚImportErrorÚgoogle.protobufr   r   r   r   Úgoogle.protobuf.internalr   r   r   r	   r
   r   rt  ÚTestCaser   r  r  rg  r‘  r  ÚmainrA   rA   rA   rB   Ú<module>   sB    ÿ   ! ?  
vÿ