<!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
h%                 @   s   d Z dZyddlZW n ek
r0   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 G dd dejZedkrej  dS )z*Tests for google.protobuf.message_factory.z"matthewtoia@google.com (Matt Toia)    N)descriptor_pb2)api_implementation)factory_test1_pb2)factory_test2_pb2)descriptor_database)descriptor_pool)message_factoryc               @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )MessageFactoryTestc             C   s(   t jjtjj| _t jjtjj| _d S )N)	r   FileDescriptorProto
FromStringr   
DESCRIPTORZserialized_pbfactory_test1_fdr   factory_test2_fd)self r   */usr/lib/python3.6/message_factory_test.pysetUp4   s    zMessageFactoryTest.setUpc             C   s<  | }d|_ d|_d|j_d|j_d|j_d|jj_d|j_|jj	j
dddg |jj	jd	 d|_d|_d|j_d|j_ d
|jj_ d|j_d|_|j	j
d	ddg |j	jd |jj  d|jd _d|jd _|jjddd d
|jj_ d|jjjj_ |j }tjj|}|j }| j|| |j|}| j|| d S )N*   r   znested message value      ZoneZtwoZthreeZfour   zone deepz	zero deepZhelloZworldZtestingZ123)part_1part_2   )Z	mandatoryZnested_factory_2_enumZnested_factory_2_messagevalueZfactory_1_messageZfactory_1_enumZnested_factory_1_enumZnested_factory_1_messageZscalar_valueZ
list_valueextendappendZcircular_messageZgroupedaddr   r   ZloopZSerializeToStringr   Factory2Messager   assertEqual)r   clsmsgZ
serializedZ	convertedZreserializedresultr   r   r   _ExerciseDynamicClass:   s>    




z(MessageFactoryTest._ExerciseDynamicClassc             C   s~   t j }tj|}|j| j |j| j tj }|j	|j
d}| j|tjk | j| |j	|j
d}| j||k d S )Nz/google.protobuf.python.internal.Factory2Message)r   ZDescriptorDatabaser   DescriptorPoolAddr   r   r   MessageFactoryZGetPrototypeZFindMessageTypeByNameZassertFalser   r   r#   
assertTrue)r   Zdbpoolfactoryr    Zcls2r   r   r   testGetPrototype\   s    

z#MessageFactoryTest.testGetPrototypec             C   s  xt dD ]v}| j| jj| jj tj| j| jg}| jt	ddgj
t	|j  | j|d  |d }| jt	ddgj
t	dd |jjjj|jD  |d  }|jjd}|jjd}d|j|< d	|j|< | jd|j|  | jd	|j|  | jd |jjd
 tj dkr\| jt|jt|j | jt|jjd | jt|jjd q| jd |jjd | jd |jjd qW d S )Nr   z/google.protobuf.python.internal.Factory2Messagez/google.protobuf.python.internal.Factory1Messagez>google.protobuf.python.internal.Factory2Message.one_more_fieldz-google.protobuf.python.internal.another_fieldc             s   s   | ]}|j V  qd S )N)Z	full_name).0extr   r   r   	<genexpr>   s   z5MessageFactoryTest.testGetMessages.<locals>.<genexpr>Ztest1Ztest2i!0  Zcppr    )rangeassertInr   namer   
dependencyr   GetMessagesr'   setissubsetkeysr#   r   filer(   ZFindAllExtensionsZ
ExtensionsZ_FindExtensionByNamer   Z_FindExtensionByNumberr   ZTypelenassertRaises	TypeError)r   _ZmessagesZfactory_msg1Zmsg1Zext1Zext2r   r   r   testGetMessagesj   sN    








z"MessageFactoryTest.testGetMessagesc       	      C   s  t j }tj|d}tj }d|_d|_|jj	 }d|_|j
j	 }d|_d|_|j| |j|jg}| jd| tj }d|_d|_|jjd |jj	 }d	|_|jj	 }d
|_d|_tjj|_d	|_d|_|j| |j|jg}| jd| tj }d|_d|_|jjd |jj	 }d|_|jj	 }d
|_d|_tjj|_d|_d|_|j| | jt}|j|jg W d Q R X | jt|jddg d S )N)r(   z(google/protobuf/internal/container.protozgoogle.protobuf.python.internal	Containerr   
   z)google.protobuf.python.internal.Containerz(google/protobuf/internal/extension.protoZ	ExtensionZextension_fieldr   z)google.protobuf.python.internal.Extensionz(google/protobuf/internal/duplicate.protoZ	DuplicatezExtensions "google.protobuf.python.internal.Duplicate.extension_field" and "google.protobuf.python.internal.Extension.extension_field" both try to extend message type "google.protobuf.python.internal.Container" with field number 2.z!Double registration of Extensions)r   r$   r   r&   r   r
   r1   packageZmessage_typer   Zextension_rangestartendr%   r3   r0   r2   r   	extensionZnumberZFieldDescriptorProtoZLABEL_OPTIONALZlabelZ	type_nameZextendeer9   	ExceptionstrZ	exception)	r   r(   r)   fr!   rngZmsgsr,   cmr   r   r   testDuplicateExtensionNumber   s\    










z/MessageFactoryTest.testDuplicateExtensionNumberN)__name__
__module____qualname__r   r#   r*   r<   rH   r   r   r   r   r	   2   s
   "4r	   __main__)__doc__
__author__Z	unittest2ZunittestImportErrorZgoogle.protobufr   Zgoogle.protobuf.internalr   r   r   r   r   r   ZTestCaser	   rI   mainr   r   r   r   <module>    s     +