o
    ‹¨Êhµ9  ã                   @   sè   d Z d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jƒZedkrre ¡  dS dS )zàUnittest that directly tests the output of the pure-Python protocol
compiler.  See //google/protobuf/internal/reflection_test.py for a test which
further ensures that we can use Python protocol message objects as we expect.
z#robinson@google.com (Will Robinson)é    N)Útest_bad_identifiers_pb2)Úunittest_custom_options_pb2)Úunittest_import_pb2)Úunittest_import_public_pb2)Úunittest_mset_pb2)Úunittest_mset_wire_format_pb2)Ú unittest_no_generic_services_pb2)Úunittest_pb2)Úservice)Úsymbol_databasei    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dd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-S ).ÚGeneratorTestc                 C   s(   d}t j}|  |jj|jj| j¡ d S )NÚoptional_nested_message)r	   ÚTestAllTypesÚassertEqualÚNestedMessageÚ
DESCRIPTORÚfields_by_nameÚmessage_type)ÚselfÚ
field_nameÚ
proto_type© r   úY/var/www/html/env/lib/python3.10/site-packages/google/protobuf/internal/generator_test.pyÚtestNestedMessageDescriptorA   s   þz)GeneratorTest.testNestedMessageDescriptorc                 C   s�   |   dtj¡ |   dtj¡ |   dtj¡ t ¡ }|   d|j¡ |   dtjj¡ |   d|j¡ |   dtjj¡ |   d|j¡ |   dtjj¡ d S )Né   é   é   é   é   é   )	r   r	   ÚFOREIGN_FOOÚFOREIGN_BARÚFOREIGN_BAZr   ÚFOOÚBARÚBAZ©r   Úprotor   r   r   Ú	testEnumsH   s   zGeneratorTest.testEnumsc                    sÎ   t  ¡ }dd„ ‰ ‡ fdd„}|  ||jƒ¡ |  |jdk¡ |  ||jƒ¡ |  |jdk ¡ |  ˆ |jƒ¡ |  ||jƒ¡ |  |jdk¡ |  ||jƒ¡ |  |jdk ¡ |  ˆ |jƒ¡ |  	d|j
¡ d S )Nc                 S   s   | | kS ©Nr   ©Úvalr   r   r   Úisnan]   s   z5GeneratorTest.testExtremeDefaultValues.<locals>.isnanc                    s   ˆ | ƒ o
ˆ | d ƒS ©Nr   r   r*   ©r,   r   r   Úisinf`   s   z5GeneratorTest.testExtremeDefaultValues.<locals>.isinfr   z? ? ?? ?? ??? ??/ ??-)r	   ÚTestExtremeDefaultValuesÚ
assertTrueÚ
inf_doubleÚneg_inf_doubleÚ
nan_doubleÚ	inf_floatÚneg_inf_floatÚ	nan_floatr   Úcpp_trigraph)r   Úmessager/   r   r.   r   ÚtestExtremeDefaultValuesX   s   z&GeneratorTest.testExtremeDefaultValuesc                    s>   t jj}dddddœ‰ t‡ fdd„|jD ƒƒ}|  ˆ |¡ d S )NFT)Úoptional_int32Úrepeated_int32r   Údefault_int32c                    s"   g | ]}|j ˆ v r|j |jf‘qS r   )ÚnameÚhas_default_value)Ú.0Úf©Úexpected_has_default_by_namer   r   Ú
<listcomp>|   s
    

þz6GeneratorTest.testHasDefaultValues.<locals>.<listcomp>)r	   r   r   ÚdictÚfieldsr   )r   ÚdescÚhas_default_by_namer   rB   r   ÚtestHasDefaultValuesq   s   ü
ÿÿz"GeneratorTest.testHasDefaultValuesc                 C   s.   |   tjjtjj¡ |   tjjjtjj¡ d S r)   )r   r	   Úoptional_int32_extensionÚcontaining_typeÚTestAllExtensionsr   ÚTestRequiredÚsingle©r   r   r   r   Ú'testContainingTypeBehaviorForExtensions�   s   
ÿÿz5GeneratorTest.testContainingTypeBehaviorForExtensionsc                 C   s*   |   tjjd ¡ |   tjjjtjj¡ d S r)   )r   r	   rJ   Úextension_scoperM   rN   r   rO   r   r   r   ÚtestExtensionScope‡   s   
ÿÿz GeneratorTest.testExtensionScopec                 C   sB   |   tjj¡ |   tjjj¡ tjj}|jd }|   |j ¡ d S )NÚa)r1   r	   rJ   Úis_extensionrM   rN   r   r   )r   Úmessage_descriptorÚnon_extension_descriptorr   r   r   ÚtestIsExtension�   s
   
zGeneratorTest.testIsExtensionc                 C   s   t  ¡ }|  |j ¡ j¡ d S r)   )r   ÚTestMessageSetr1   r   Ú
GetOptionsÚmessage_set_wire_formatr&   r   r   r   ÚtestOptions•   s   zGeneratorTest.testOptionsc                 C   s*   t  ¡ }|jjd  ¡ }|  |d u¡ d S )NÚAnEnum)r   ÚTestMessageWithCustomOptionsr   Úenum_types_by_namerY   r1   )r   r'   Úenum_optionsr   r   r   ÚtestMessageWithCustomOptions™   s   z*GeneratorTest.testMessageWithCustomOptionsc                 C   s\   |   ttjjjƒttjjjtjjjtjjjgƒ¡ |   tj	jjg ¡ |   tjjjjg ¡ d S r)   )
r   Úsetr	   r   r   Únested_typesr   ÚOptionalGroupÚRepeatedGroupÚTestEmptyMessagerO   r   r   r   ÚtestNestedTypes    s   ýþÿzGeneratorTest.testNestedTypesc                 C   st   |   tjjjd u ¡ |   tjjjd u ¡ |  tjjjjtjj¡ |  tjjjjtjj¡ |  tjjjjtjj¡ d S r)   )	r1   r	   re   r   rK   r   r   r   rd   rO   r   r   r   ÚtestContainingType¬   s$   ÿÿ
þ
þ
þz GeneratorTest.testContainingTypec                 C   s*   |   tjjd u ¡ |  tjjtjj¡ d S r)   )r1   r	   Ú_FOREIGNENUMrK   r   Ú_TESTALLTYPES_NESTEDENUMr   r   rO   r   r   r   Ú"testContainingTypeInEnumDescriptor»   s   
ÿz0GeneratorTest.testContainingTypeInEnumDescriptorc                 C   s|   |   tjjjjd¡ tjjj}|   |jjd¡ |   tjjjjd¡ |   tj	jjd¡ |   tj
jjd¡ |   tjjjd¡ d S )NÚprotobuf_unittestÚprotobuf_unittest_import)r   r	   r   r   ÚfileÚpackager   r   ÚImportMessagerh   ri   Ú_IMPORTENUM)r   rG   r   r   r   ÚtestPackageÀ   s*   
þ

þ
ÿþþzGeneratorTest.testPackagec                 C   sJ   |   tjjjg ¡ |   tjjjdtfg¡ |   tjjjdddtfg¡ d S )Nr   )é*   é+   )i/  i”  i   )r   r	   r   r   Úextension_rangesrL   ÚMAX_EXTENSIONÚTestMultipleExtensionRangesrO   r   r   r   ÚtestExtensionRangeÓ   s   
ÿþþz GeneratorTest.testExtensionRangec                 C   sr   |   tjjd¡ |   tjjd¡ |  tjjd u ¡ |   tjjtjg¡ |   tjjt	jg¡ |   tjj
t	jg¡ d S )Núgoogle/protobuf/unittest.protork   )r   r	   r   r>   rn   ÚassertFalseÚserialized_pbÚdependenciesr   r   Úpublic_dependenciesrO   r   r   r   ÚtestFileDescriptorÝ   s   
ÿ
ÿ
ÿ
ÿz GeneratorTest.testFileDescriptorc                 C   sV   |   ttdƒ¡ |   ttdƒ¡ |   ttdƒ¡ ttdƒr)|  ttjtjƒ¡ d S d S )NÚTestMessager#   Útest_extensionÚTestService)r1   Úhasattrr   ry   Ú
issubclassr€   r
   ÚServicerO   r   r   r   ÚtestNoGenericServicesè   s   


ÿÿz#GeneratorTest.testNoGenericServicesc                 C   s6   t j}|  t j|jt jj ¡ |  t jj|jv ¡ d S r)   )r	   r   r   Ú_TESTALLTYPESÚmessage_types_by_namer>   ry   Ú_TESTALLTYPES_NESTEDMESSAGE©r   Ú	file_typer   r   r   ÚtestMessageTypesByNameó   s   þÿÿz$GeneratorTest.testMessageTypesByNamec                 C   ó"   t j}|  t j|jt jj ¡ d S r)   )r	   r   r   rh   r^   r>   rˆ   r   r   r   ÚtestEnumTypesByNameÿ   ó
   þz!GeneratorTest.testEnumTypesByNamec                 C   r‹   r)   )r	   r   r   Úmy_extension_stringÚextensions_by_namer>   rˆ   r   r   r   ÚtestExtensionsByName  r�   z"GeneratorTest.testExtensionsByNamec                 C   sD   t  ¡ }|  d|jj¡ t ¡ }|  d|j¡ |  tjtju ¡ d S r-   )	r	   r   r   Úoptional_public_import_messageÚer   ÚPublicImportMessager1   r   )r   Úall_type_protoÚpublic_import_protor   r   r   ÚtestPublicImports  s   
ÿzGeneratorTest.testPublicImportsc                 C   s\   t  ¡ }|  |jt j d¡ |  |jt j d¡ |  |jt j d¡ |  |jt j d¡ d S )NÚfooÚbarÚbazÚqux)r   ÚTestBadIdentifiersr   Ú
Extensionsr9   Ú
descriptorÚ
reflectionr
   )r   r9   r   r   r   ÚtestBadIdentifiers  s   ÿÿÿÿz GeneratorTest.testBadIdentifiersc                 C   sÞ   t jj}|  dt|jƒ¡ |  d|jd j¡ |  d|jd j¡ |  ||jd j	¡ |  |jd |j
d ¡ tg d¢ƒ}|  |tdd„ |jd jD ƒƒ¡ |j ¡ D ]\}}||v rf|  |jd |j¡ qS|  |j¡ qSd S )Nr   Úoneof_fieldr   )Úoneof_uint32Úoneof_nested_messageÚoneof_stringÚoneof_bytesc                 S   s   g | ]}|j ‘qS r   )r>   )r@   Úfieldr   r   r   rD   .  s    z+GeneratorTest.testOneof.<locals>.<listcomp>)r	   r   r   r   ÚlenÚoneofsr>   ÚindexÚassertIsrK   Úoneofs_by_namera   rF   r   ÚitemsÚcontaining_oneofÚassertIsNone)r   rG   Únested_namesr   Ú
field_descr   r   r   Ú	testOneof#  s    þüzGeneratorTest.testOneofN)Ú__name__Ú
__module__Ú__qualname__r   r(   r:   rI   rP   rR   rW   r[   r`   rf   rg   rj   rq   rw   r}   r„   rŠ   rŒ   r�   r–   rŸ   r°   r   r   r   r   r   ?   s.    
r   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚSymbolDatabaseRegistrationTestz?Checks that messages, enums and files are correctly registered.c                 C   s¢   |   tjt ¡  d¡¡ |   tjjt ¡  d¡¡ |  t¡� t ¡  d¡ W d   ƒ n1 s0w   Y  |   tjj	t ¡  d¡¡ |   tjj
t ¡  d¡¡ d S )Nzprotobuf_unittest.TestAllTypesz,protobuf_unittest.TestAllTypes.NestedMessagezprotobuf_unittest.NestedMessagez,protobuf_unittest.TestAllTypes.OptionalGroupz,protobuf_unittest.TestAllTypes.RepeatedGroup)r   r	   r   r   ÚDefaultÚ	GetSymbolr   ÚassertRaisesÚKeyErrorrc   rd   rO   r   r   r   ÚtestGetSymbol9  s4   ÿÿÿþÿÿþÿþz,SymbolDatabaseRegistrationTest.testGetSymbolc                 C   s8   |   dt ¡ j d¡j¡ |   dt ¡ j d¡j¡ d S )Nzprotobuf_unittest.ForeignEnumz)protobuf_unittest.TestAllTypes.NestedEnum)r   r   rµ   ÚpoolÚFindEnumTypeByNameÚ	full_namerO   r   r   r   r(   L  s   
ÿý
ÿýz(SymbolDatabaseRegistrationTest.testEnumsc                 C   s   |   dt ¡ j d¡j¡ d S )Nrx   )r   r   rµ   rº   ÚFindFileByNamer>   rO   r   r   r   ÚtestFindFileByNameV  s   
ÿýz1SymbolDatabaseRegistrationTest.testFindFileByNameN)r±   r²   r³   Ú__doc__r¹   r(   r¾   r   r   r   r   r´   6  s
    
r´   Ú__main__)r¿   Ú
__author__Ú	unittest2ÚunittestÚImportErrorÚgoogle.protobuf.internalr   Úgoogle.protobufr   r   r   r   r   r   r	   r
   r   ru   ÚTestCaser   r´   r±   Úmainr   r   r   r   Ú<module>   s0   $ÿ x&ÿ