U
    4JeD                     @   sv   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rre  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_INT64ZTYPE_STRINGordered_fieldsdict_fields)self r   O/tmp/pip-unpacked-wheel-0oacnh65/google/protobuf/internal/proto_builder_test.pysetUp-   s
    

zProtoBuilderTest.setUpc                 C   s8   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   s     z)ProtoBuilderTest.testMakeSimpleProtoClassc                 C   s8   t j| jdd}| }d|_d|_| dt| dS )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?   s     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   ZDescriptorPoolr   r   r   ZassertIs
DESCRIPTOR)r   r"   Z
proto_cls1Z
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   ZFieldDescriptorZFIRST_RESERVED_FIELD_NUMBERZLAST_RESERVED_FIELD_NUMBERr#   Zfields_by_numberZassertFalseintersection)r   
num_fieldsfieldsr   Zreserved_field_numbersZ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
   ZunittestZgoogle.protobufr   r   r   r   r   ZTestCaser   r/   mainr   r   r   r   <module>   s   >