o
    ˷eD                     @   sz   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 G dd	 d	ej	Z
ed
kr;e  dS dS )z(Tests for google.protobuf.proto_builder.    N)descriptor_pb2)
descriptor)descriptor_pool)proto_builder)text_formatc                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )ProtoBuilderTestc                 C   s0   t dtjjfdtjjfg| _t| j| _d S )Nfoobar)	collectionsOrderedDictr   FieldDescriptorProto
TYPE_INT64TYPE_STRINGordered_fieldsdict_fields)self r   b/var/www/ideatree/venv/lib/python3.10/site-packages/google/protobuf/internal/proto_builder_test.pysetUp-   s
   

zProtoBuilderTest.setUpc                 C   8   t j| jdd}| }d|_d|_| dt| dS )z&Test that we can create a proto class.0net.proto2.python.public.proto_builder_test.Test	full_name90  asdfzbar: "asdf"
foo: 12345
N)r   MakeSimpleProtoClassr   r   r	   assertMultiLineEqualr   MessageToStringr   	proto_clsprotor   r   r   testMakeSimpleProtoClass4      
z)ProtoBuilderTest.testMakeSimpleProtoClassc                 C   r   )zBTest that the field order is maintained when given an OrderedDict.z7net.proto2.python.public.proto_builder_test.OrderedTestr   r   r   zfoo: 12345
bar: "asdf"
N)r   r   r   r   r	   r   r   r   r   r   r   r   testOrderedFields?   r#   z"ProtoBuilderTest.testOrderedFieldsc                 C   s@   t  }tj| jd|d}tj| jd|d}| |j|j dS )z%Test that the DescriptorPool is used.r   )r   poolN)r   DescriptorPoolr   r   r   assertIs
DESCRIPTOR)r   r%   
proto_cls1
proto_cls2r   r   r   testMakeSameProtoClassTwiceJ   s   z,ProtoBuilderTest.testMakeSameProtoClassTwicec                 C   s^   d}dd t |D }tj|dd}tt tjjtjjd }t|jj	}| 
|| dS )z@Test that large created protos don't use reserved field numbers.i@ c                 S   s   i | ]	}d | t jjqS )zfoo%d)r   r   r   ).0ir   r   r   
<dictcomp>Z   s    z<ProtoBuilderTest.testMakeLargeProtoClass.<locals>.<dictcomp>z:net.proto2.python.public.proto_builder_test.LargeProtoTestr      N)ranger   r   setr   FieldDescriptorFIRST_RESERVED_FIELD_NUMBERLAST_RESERVED_FIELD_NUMBERr(   fields_by_numberassertFalseintersection)r   
num_fieldsfieldsr    reserved_field_numbersproto_field_numbersr   r   r   testMakeLargeProtoClassW   s   
z(ProtoBuilderTest.testMakeLargeProtoClassN)__name__
__module____qualname__r   r"   r$   r+   r<   r   r   r   r   r   +   s    r   __main__)__doc__r
   unittestgoogle.protobufr   r   r   r   r   TestCaser   r=   mainr   r   r   r   <module>   s   >