__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

aptanhua@216.73.216.200: ~ $
3

���h���@s�dZddlZddlZddlZddlZddlZyddlZWnek
rTddlZYnXddl	m
Z
ddl	mZddl	mZddl	m
Z
ddl	mZddl	mZdd	l	mZdd
l	mZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZejZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�de�Z!Gdd�de�Z"Gdd �d e�Z#Gd!d"�d"e�Z$Gd#d$�d$e�Z%Gd%d&�d&e�Z&e'd'k�r�ej(�dS)(ziUnittest for reflection.py, which also indirectly tests the output of the
pure-Python protocol compiler.
�N)�unittest_import_pb2)�unittest_mset_pb2)�unittest_pb2)�descriptor_pb2)�
descriptor)�message)�
reflection)�text_format)�api_implementation)�more_extensions_pb2)�more_messages_pb2)�message_set_extensions_pb2)�wire_format)�	test_util)�testing_refleaks)�decoderc@s\eZdZdZdd�Zdd�ZeZeZeZeZ	dd�Z
e
Zdd	�Zd
d�Z
dd
�Zdd�ZdS)�_MiniDecodera�Decodes a stream of values from a string.

  Once upon a time we actually had a class called decoder.Decoder.  Then we
  got rid of it during a redesign that made decoding much, much faster overall.
  But a couple tests in this file used it to check that the serialized form of
  a message was correct.  So, this class implements just the methods that were
  used by said tests, so that we don't have to rewrite the tests.
  cCs||_d|_dS)Nr)�_bytes�_pos)�self�bytes�r�%/usr/lib/python3.6/reflection_test.py�__init__Osz_MiniDecoder.__init__cCstj|j|j�\}|_|S)N)rZ
_DecodeVarintrr)r�resultrrr�
ReadVarintSsz_MiniDecoder.ReadVarintcCstj|j��S)N)rZZigZagDecoder)rrrr�
ReadSInt64\sz_MiniDecoder.ReadSInt64cCstj|j��S)N)rZ	UnpackTagr)rrrr�ReadFieldNumberAndWireTypeasz'_MiniDecoder.ReadFieldNumberAndWireTypecCs4tjd|j|j|jd��d}|jd7_|S)Nz<f�r)�struct�unpackrr)rrrrr�	ReadFloatds"z_MiniDecoder.ReadFloatcCs4tjd|j|j|jd��d}|jd7_|S)Nz<d�r)rr rr)rrrrr�
ReadDoubleis"z_MiniDecoder.ReadDoublecCs|jt|j�kS)N)r�lenr)rrrr�EndOfStreamnsz_MiniDecoder.EndOfStreamN)�__name__�
__module__�__qualname__�__doc__rr�	ReadInt32�	ReadInt64�
ReadUInt32�
ReadUInt64r�
ReadSInt32rr!r#r%rrrrrEsrc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+dSdT�Z,dUdV�Z-dWdX�Z.dYdZ�Z/d[d\�Z0d]d^�Z1d_d`�Z2dadb�Z3dcdd�Z4dedf�Z5dgdh�Z6didj�Z7dkdl�Z8dmdn�Z9dodp�Z:dqdr�Z;dsdt�Z<dudv�Z=dwdx�Z>dydz�Z?d{d|�Z@d}d~�ZAdd��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d�d��ZRd�d��ZSeTjUeVjW�d�k�p�eVjX�d�kd��d�d���ZYd�d��ZZd�d��Z[d�d��Z\d�d��Z]d�d��Z^d�d��Z_d�S)��ReflectionTestcCsB|jt|�t|��x(tt|��D]}|j||||�q"WdS)N)�assertEqualr$�range)r�valuesZothers�irrr�assertListsEqualtszReflectionTest.assertListsEqualcCsPtjddddd�}|jd|j�|jd|j�|jd|j�|j|jd��dS)N�g+�)K@�optional_string)�optional_int32�optional_doubler6�optional_floatr9)r�TestAllTypesr0r7r8r6�assertFalse�HasField)r�protorrr�testScalarConstructorysz$ReflectionTest.testScalarConstructorcCs�tjddddgddgdddgd	gdd
�}|jddddgt|j��|jddgt|j��|jdddgt|j��|jd	gt|j��|jgt|j��dS)N���rg�G�z��?g+�)K@TFr6)�repeated_int32�repeated_double�
repeated_bool�repeated_string�repeated_float)	rr:r0�listrBrCrDrErF)rr=rrr�testRepeatedScalarConstructor�s
z,ReflectionTest.testRepeatedScalarConstructorcCstjtjjtjjd�tjjtjjd�gtjd
d�tjdd�tjdd�gtjj�tjjdd�tjjdd�gd	�}|jtjjtjjd�tjjtjjd�gt|j	��|jtjdd�tjdd�tjdd�gt|j
��|jtjj�tjjdd�tjjdd�gt|j��dS)N)�bb�+)�ci��r?)�ar@)�repeated_nested_message�repeated_foreign_message�
repeatedgroupi���i���)rr:�
NestedMessage�FOO�BAR�ForeignMessageZ
RepeatedGroupr0rGrNrOrP)rr=rrr� testRepeatedCompositeConstructor�s6





z/ReflectionTest.testRepeatedCompositeConstructorcCs tjddddgdddgtjjtjjd�tjjtjjd�gtjdd	�tjd
d	�tjdd	�gdd�}|jd|j�|jd|j�|jddgt	|j
��|jdddgt	|j��|jtjjtjjd�tjjtjjd�gt	|j��|jtjdd	�tjd
d	�tjdd	�gt	|j
��|j|jd
��dS)Nr5r6g�G�z��?g+�)K@TF)rIrJ)rKi�rL)r7r6rCrDrNrO�optional_nested_messagerVi���i���)rr:rQrRrSrTr0r7r6rGrCrDrNrOr;r<)rr=rrr�testMixedConstructor�s:





z#ReflectionTest.testMixedConstructorcCs�|jttjdd�|jttjdd�|jttjdd�|jttjdd�|jttjdgd�|jttjdd�|jttjdgd�|jttjdd�|jttjdgd�dS)	N�foo)r7i�)r6)rV)rB)rE)rN)�assertRaises�	TypeErrorrr:)rrrr�testConstructorTypeError�s$z'ReflectionTest.testConstructorTypeErrorcCs�tjdd�}|jd|j��tjtjj�d�}|jd|j��tjdgd�}|jd|j��tjtjj�gd�}|jd|j��dS)NrL)r7r@)rVrA)rB)rN)rr:r0�ByteSizerQ)rrrrr�(testConstructorInvalidatesCachedByteSize�sz7ReflectionTest.testConstructorInvalidatesCachedByteSizecCsptj�}|j|jd��|jd|j�|j|jd��d|_|j|jd��|jd�|j|jd��dS)Nr7rr?)rr:�
assertTruer<r0r7�
ClearField)rr=rrr�testSimpleHasBits�s
z ReflectionTest.testSimpleHasBitscs8�fdd�}|dd�|dd�|dd�|d	d
�dS)Ncs0tj�}t||�}t||�}�jd|��j|j|���j|j|��d}t|||��j|t||��|}�j|j|���j|j|��|j|�t||�}�j|j|���j|j|���jdt||���j||k	�t|||��j|j|���j|j|���jdt||��dS)Nr�)rr:�getattrr0r^r<�setattrr_)Zcomposite_field_nameZscalar_field_namer=Zcomposite_fieldZoriginal_scalar_valueZnew_valZold_composite_field)rrr�TestCompositeHasBits.s,



zNReflectionTest.testHasBitsWithSinglyNestedScalar.<locals>.TestCompositeHasBits�
optionalgrouprMrVrI�optional_foreign_messagerKZoptional_import_message�dr)rrdr)rr�!testHasBitsWithSinglyNestedScalars
"*


z0ReflectionTest.testHasBitsWithSinglyNestedScalarcCstj�}|j}~d|_dS)N�)rr:rVrI)rr=�nestedrrr�testReferencesToNestedMessage]sz,ReflectionTest.testReferencesToNestedMessagecCsTtj�}|j}|jd�|j||jk	�d|_|j|jd��|jd|jj�dS)NrVrir)rr:rVr_r^rIr<r0)rr=rjrrr�0testDisconnectingNestedMessageBeforeSettingFieldes
z?ReflectionTest.testDisconnectingNestedMessageBeforeSettingFieldcCs6tj�}|j}|jd�~~tj�tj�}|j}dS)NrV)rr:rVr_�gc�collect)rr=rjrrr�5testGetDefaultMessageAfterDisconnectingDefaultMessagens
zDReflectionTest.testGetDefaultMessageAfterDisconnectingDefaultMessagecCs�tj�}|j}d|_|j|jd��|jd�|jd|j�|jd|jj�|j||jk	�d|_|j|jd��|jd|jj�dS)N�rVrri)rr:rVrIr^r<r_r0)rr=rjrrr�/testDisconnectingNestedMessageAfterSettingField{s
z>ReflectionTest.testDisconnectingNestedMessageAfterSettingFieldcCs:tj�}|j|jd��|jd�|j|jd��dS)NrV)rr:r^r<r_)rr=rrr�0testDisconnectingNestedMessageBeforeGettingField�s
z?ReflectionTest.testDisconnectingNestedMessageBeforeGettingFieldcCsRtj�}tj�}d|j_|j|�|j|jd��|jd�|j|jd��dS)NrprV)rr:rVrI�	MergeFromr^r<r_)r�proto1�proto2rrr�(testDisconnectingNestedMessageAfterMerge�s

z7ReflectionTest.testDisconnectingNestedMessageAfterMergecCs8tj�dkrdStj�}d|j_|jd�~tj�dS)N�pythonrp�optional_lazy_message)	r
�Typerr:rxrIr_rmrn)rr=rrr�"testDisconnectingLazyNestedMessage�s
z1ReflectionTest.testDisconnectingLazyNestedMessagecCsttj�}|jjjd�|jdg|jj�|j|jd��|jd�|j|jd��|jj	j
�|j|jd��dS)NrprV)rZTestNestedMessageHasBitsrVZnestedmessage_repeated_int32�appendr0r^r<r_Z%nestedmessage_repeated_foreignmessage�add)rr=rrr�&testHasBitsWhenModifyingRepeatedFields�s
z5ReflectionTest.testHasBitsWhenModifyingRepeatedFieldscCs
tj�}|j|jd��|jd|jjjjjj�|j|jd��d|jjjjj_|jd|jjjjjj�|j|jd��|j|jjd��|j|jjjd��|j|jjjjd��|j|jjjjjd��|j|jjjjjjd��|j|jjjjjjd��dS)NrIrrprMr7)r�TestMutualRecursionAr^r<r0rIrMr7)rZrecursive_protorrr�!testHasBitsForManyLevelsOfNesting�sz0ReflectionTest.testHasBitsForManyLevelsOfNestingcCs�tj�}d|_d|_d|_|j}|j|jjddf|jjddf|jjddfg|j	��d|j_
|j|jjddf|jjddf|jjddf|jjd|fg|j	��dS)	Nr?rprXr7�optional_fixed32r6�{rV)rr:r�r7r6rVr0�
DESCRIPTOR�fields_by_name�
ListFieldsrI)rr=Znested_messagerrr�testSingularListFields�s$

z%ReflectionTest.testSingularListFieldsc
Cs�tj�}|jjd�|jjd�|jjd�|jjddg�|jjg�|jjd�|jjdd�td	�D��d
|_|j	|j
|jjdd
f|jjdddgf|jjd
dgf|jjddddddgfg|j
��dS)Nr?rp�rX�bar�bazcss|]}t|�VqdS)N)�str)�.0�xrrr�	<genexpr>�sz8ReflectionTest.testRepeatedListFields.<locals>.<genexpr>r@�r7rB�repeated_fixed32rE�0�1)rr:r�r{rBrE�extendr1r7rDr0r�r�r�)rr=rrr�testRepeatedListFields�s"
z%ReflectionTest.testRepeatedListFieldscCsXtj�}d|jtj<d|jtj<d|jtj<|jtjdftjdftjdfg|j��dS)Nr?rprX)r�TestAllExtensions�
ExtensionsZoptional_fixed32_extension�optional_int32_extensionZoptional_string_extensionr0r�)rr=rrr�testSingularListExtensions�s
z)ReflectionTest.testSingularListExtensionscCs�tj�}|jtjjd�|jtjjd�|jtjjd�|jtjjd�|jtjjd�|jtjjd�d|jtj<|jtjdftjddgftjdgftjdddgfg|j	��dS)Nr?rpr�rXr�r�r�)
rr�r�Zrepeated_fixed32_extensionr{�repeated_int32_extension�repeated_string_extensionr�r0r�)rr=rrr�testRepeatedListExtensions�s
z)ReflectionTest.testRepeatedListExtensionscCsftj�}tj|�tj|j|jjddftjdf|jjddftjdf|jjddfg|j	��dS)	NZmy_intr?riZ	my_stringrXr�Zmy_floatg�?)
r�TestFieldOrderingsr�SetAllFieldsAndExtensionsZmy_extension_intr0r�r�Zmy_extension_stringr�)rr=rrr�testListFieldsAndExtensionss
z*ReflectionTest.testListFieldsAndExtensionscCs�tj�}|jd|j�|jd|j�|jd|j�|jd|j�|jd|j�|jd|j�|jd|j	�|jd|j
�|jd|j�|jd|j�|jd|j
�|jd|j�|jd|j�|jd|j�|jd|j�|jd|j�|jd|j�|jd|j�|jd	|j�|jd|j�|jd|j�|jd|j�|jd
|j�|jd|j�|jd|j�|jd|j�|jd|j�|jd|j�|jd|j�|jd|j �|jtjj!|j"�|jtj#|j$�|jt%j&|j'�tj(�}|jd|j)�dS)NrgF���)�*rJ�,�-�.�/�0�1�2g�I@gd�@TZhellosworlduሴi���i���)*rr:r0r7�optional_int64�optional_uint32�optional_uint64�optional_sint32�optional_sint64r��optional_fixed64�optional_sfixed32�optional_sfixed64r9r8�
optional_boolr6�optional_bytesZ
default_int32Z
default_int64Zdefault_uint32Zdefault_uint64Zdefault_sint32Zdefault_sint64Zdefault_fixed32Zdefault_fixed64Zdefault_sfixed32Zdefault_sfixed64Z
default_floatZdefault_doubleZdefault_boolZdefault_stringZ
default_bytesrSZdefault_nested_enum�FOREIGN_BARZdefault_foreign_enumrZ
IMPORT_BARZdefault_import_enumZTestExtremeDefaultValuesZutf8_string)rr=rrr�testDefaultValuessJz ReflectionTest.testDefaultValuescCstj�}|jt|jd�dS)N�nonexistent_field)rr:rY�
ValueErrorr<)rr=rrr� testHasFieldWithUnknownFieldName@sz/ReflectionTest.testHasFieldWithUnknownFieldNamecCstj�}|jt|jd�dS)Nr�)rr:rYr�r_)rr=rrr�"testClearFieldWithUnknownFieldNameDsz1ReflectionTest.testClearFieldWithUnknownFieldNamecsNtj��xtd�D]}�jj�qWtj�}�j|�|jt�fdd��dS)N�
cs
�jdS)Nrp)�repeated_messager)r=rr�<lambda>Qsz9ReflectionTest.testClearRemovesChildren.<locals>.<lambda>)r�TestRequiredForeignr1r�r|�CopyFromrY�
IndexError)rr3rur)r=r�testClearRemovesChildrenHs
z'ReflectionTest.testClearRemovesChildrencCs~tj�}|jtt|dd�|jtt|ddg�|jtt|dd�|jtt|jdd�|jtt|jdd�|jtt|dd�dS)	NrBr�rVrirI�"Zsome_attributer�)rr:rY�AttributeErrorrcrNrF)rr=rrr�testDisallowedAssignmentsSs
z(ReflectionTest.testDisallowedAssignmentscCs�tj�}|jtt|dd�|jtt|dd�|jtt|dd�|jtt|dd�|jtt|dd�|jtt|dd�|jtt|d	d�tj�d
kr�|jtt|dd�nd|_dS)Nr7g�������?rXr6r�r�r�r9r8rw)rr:rYrZrcr
ryr�)rr=rrr�testSingleScalarTypeSafetyhsz)ReflectionTest.testSingleScalarTypeSafetycs���fdd�}|ddt�|ddt�|ddt�yt}Wntk
rRt}YnXtjd�dkrp|dd|�n|ddt�|d
d|�|d
d|�|dd|�|dd|�d
S)z}Verifies setting of scalar integers.

    Args:
      integer_fn: A function to wrap the integers that will be assigned.
    csZtj�}�|�}t|||��jt||�|�tj�}|j|j���jt||�|�dS)N)rr:rc�assertIsInstancerb�ParseFromString�SerializeToString)�
field_name�valueZ
expected_typer=ru)�
integer_fnrrr�TestGetAndDeserialize}sz@ReflectionTest.assertIntegerTypes.<locals>.TestGetAndDeserializer7r?�r��Lr�r��<r�Ni@i@lli@li@l)�int�	NameErrorr�calcsize)rr�r�Z
integer_64r)r�rr�assertIntegerTypesws	
z!ReflectionTest.assertIntegerTypescCs|jdd��dS)NcSs|S)Nr)r�rrrr��sz1ReflectionTest.testIntegerTypes.<locals>.<lambda>)r�)rrrr�testIntegerTypes�szReflectionTest.testIntegerTypescCs|jtj�dS)N)r�r�NonStandardInteger)rrrr�testNonStandardIntegerTypes�sz*ReflectionTest.testNonStandardIntegerTypescCsNtj�}|jt��d|_WdQRX|jtd��tjdd�|_WdQRXdS)N�2Zmy_errorrp)	rr:rYrZr�ZassertRaisesRegex�RuntimeErrorrr�)r�pbrrr�testIllegalValuesForIntegers�s
z+ReflectionTest.testIllegalValuesForIntegersc
s���fdd�}|ddd�|ddd�|d	dd�|ddd�tj�}�jttf���d�|_Wd
QRXtj�}�d�|_�jd|j�d
S)z�Verifies bounds checking for scalar integer fields.

    Args:
      integer_fn: A function to wrap the integers that will be assigned.
    cs�tj�}�|�}�|�}t|||��j|t||��t|||��j|t||���jttft|||d��jttft|||d�dS)Nr?)rr:rcr0rbrYr�rZ)r�Zexpected_minZexpected_maxr�)r�rrr�TestMinAndMaxIntegers�s
zHReflectionTest.assetIntegerBoundsChecking.<locals>.TestMinAndMaxIntegersr7r?r�r�rl��r��?r�l����Nli�li���ll����ll����ll����)rr:rYr�rZr��optional_nested_enumr0)rr�r�r�r)r�rr�assetIntegerBoundsChecking�s

z)ReflectionTest.assetIntegerBoundsCheckingcCs|jdd��dS)NcSs|S)Nr)r�rrrr��sz?ReflectionTest.testSingleScalarBoundsChecking.<locals>.<lambda>)r�)rrrr�testSingleScalarBoundsChecking�sz-ReflectionTest.testSingleScalarBoundsCheckingcCs|jtj�dS)N)r�rr�)rrrr�)testNonStandardSingleScalarBoundsChecking�sz8ReflectionTest.testNonStandardSingleScalarBoundsCheckingcCs�tj�}|jt|jjd�|jt|jjd�|jt|jd�|jt|jd�|jjd�d|jd<|jt|jj	dd�|jt|jj	dd�|jt|jj	dg�|jt|jj	dd�|jjd	�|jt|jj	dd�dS)
Ng�������?rXr�riri��abc�indexr�)
rr:rYrZrBr{rEZrepeated_bytesr��__setitem__)rr=rrr�testRepeatedScalarTypeSafety�s
z+ReflectionTest.testRepeatedScalarTypeSafetycCsVtj�}|jd|j�d|_|jd|j�d|_|jd|j�d|_|jd|j�dS)Nrr?l���l����)rr:r0r7r�)rr=rrr�!testSingleScalarGettersAndSetters�sz0ReflectionTest.testSingleScalarGettersAndSetterscCsVtj�}|jd�d|_|j|jd��|jd�|jd|j�|j|jd��dS)Nr7r?r)rr:r_r7r^r<r0)rr=rrr�testSingleScalarClearField�s

z)ReflectionTest.testSingleScalarClearFieldcCsftj�}|jd|j�|jdtjj�|jd|j�|jdtjj�|jd|j�|jdtjj�dS)Nr?r@rA)rr:r0rRrS�BAZ)rr=rrr�	testEnums�szReflectionTest.testEnumscCs|jdtjjtj��|jdtjjtj��|jdtjjtj��|jttjjd�tj	�}|jd|j
j|j��|jdtj	j
j|j��|jd|j
j|j��|jdtj	j
j|j��|jd|j
j|j
��|jdtj	j
j|j
��|jt|j
jd�|jttj	j
jd�dS)N�FOREIGN_FOOr��FOREIGN_BAZi0,rRrSr�)r0r�ForeignEnum�Namer�r�r�rYr�r:�
NestedEnumrRrSr�)rr=rrr�
testEnum_Names2zReflectionTest.testEnum_NamecCs|jtjtjjd��|jtjtjjd��|jtjtjjd��|jttjjd�tj	�}|j|j
|jjd��|j|j
tj	jjd��|j|j|jjd��|j|jtj	jjd��|j|j
|jjd��|j|j
tj	jjd��|jt|jjd�|jttj	jjd�dS)	Nr�r�r�ZFOrRrSr�ZFoo)r0rr�r�ZValuer�r�rYr�r:rRr�rSr�)rr=rrr�testEnum_Value"s2zReflectionTest.testEnum_ValuecCs�|jdddgttjj���|jdddgttjj���|jdddgttjj���tj�}|jddd	d
gt|jj���|jddd
dgt|jj���|jddddgt|jj���dS)Nr�r�r�rrp�rRrSr��NEGr?r@rA)r�r)r�rp)r�r����)rRr?)rSr@)r�rAr�)r�r�)	r0rGrr��keysr2�itemsr:r�)rr=rrr�testEnum_KeysAndValues>sz%ReflectionTest.testEnum_KeysAndValuescCs|tj�}|j|j�|jdt|j��|jjd�|jjd�|jjd�|j|j�|jdt|j��|jdddg|j�|jd|jd�|jd|jd�|jt|jj	d�|jt|jj	d�|jt
|jj	d�|jt
|jj	d�d	|jd<|jdd	dg|j�|jjdd
�|jdd
d	dg|j�|jjd�|jd
d	dg|jdd��|jdd
d	ddg|jdd��d
d�td�D�|jdd�<|jdddddg|j�dddg|jdd�<|jdddddg|j�g}x|jD]}|j|��q�W|jdddddg|�|jd=|jddddg|j�|jdd�=|jddg|j�|jj
ddg�|jddddg|j�|jd�|j|j�|jdt|j��|jjd�|jd|jd�d|jd<|jd|jd�ddddg|jdd�<|jd=|jdddg|j�|jd=|jddg|j�|jt|jjd�|jt|jjd�|jd d!�=|jdg|j�|jdd�=|jdg|j�dS)"Nrrpr��rAr?i�rXra�r�rcss|]
}|VqdS)Nr)r�r3rrrr�rsz5ReflectionTest.testRepeatedScalars.<locals>.<genexpr>r@�#�(r��
rBi,�di'r�i.���r�r�r�r�������r�r�)rr:r^rBr0r$r{rYr��__getitem__rZ�insertr1r�r_�__delitem__)rr=rr3rrr�testRepeatedScalarsMsl
 

z"ReflectionTest.testRepeatedScalarscCsFtj�}|j|j�|jdt|j��|jjd�|jjd�|jjd�|jjd�|jdt|j��|jjd�|jdt|j��|jd|jd�|jd|jd�|jd|jd�|jjd�|jdt|j��|jd|jd�|jd|jd�|jjd�|jdt|j��|jd|jd�|jt	|jjd�dS)	Nrrpr�rrAr?r@r�)
rr:r^rBr0r$r{�removerYr�)rr=rrr�testRepeatedScalarsRemove�s*z(ReflectionTest.testRepeatedScalarsRemovec
Cs(tj�}|j|j�|jdt|j��|jj�}|jj�}|j|j�|jdt|j��|j||g|j�|j|tjj	�|j
t|jjd�|j
t|jjd�|j
t
|jjd�|j
t
|jjd�|jj�}|jj�}|jj�}|j|||g|jdd��|j|||||g|jdd��|j||g|jdd��|j|||g|jdd��|j||jd�|j|g|jdd��g}x|jD]}|j|��q�W|j|||||g|�|jd=|j||||g|j�|jdd�=|j||g|j�tjj	dd�}	tjj	dd�}
|jj|	|
g�|jdt|j��|j|	|jd�|j|
|jd�|j
t
|jj|	�|j
t
|jjdg�tj�}|j
t
|jj|g�|jd	�|j|j�|jdt|j��|jjd
d�|jdt|j��|jd
|jdj�|j
t
|jjd
�|j
t��d
|jd<WdQRXdS)Nrr@i�rXr?r)rIrArNrii.���)rr:r^rNr0r$r|r4r�rQrYr�r�rZr{r�r_rI�	Exception)rr=�m0�m1�m2Zm3Zm4rr3Zn1Zn2Zwrong_message_typerrr�testRepeatedComposites�s~





z%ReflectionTest.testRepeatedCompositescCs<tj�}|jdt|j��|jj�}t|j�|_|jj�}t|j�|_|j||k�|jj�}t|j�|_|j|||g|j�|jdt|j��|jj	|�|jdt|j��|j||jd�|j||jd�|j
t|jj	|�|j
t|jj	d�|jdt|j��|jj	|�|jdt|j��|j||jd�dS)NrrAr@r?)rr:r0r$rNr|rIr^r4rrYr�)rr=rrrrrr�testRepeatedCompositeRemoves*


z*ReflectionTest.testRepeatedCompositeRemovecs�tj�dkrdStj}|dddd|j|j|jddddddtj�d�}tj	ddd	dgg|ggtj
�d
�	�G�fdd�dtjt
jtj��}|�}|jd|j�|j|jd��d
|_|jd
|j�|j|jd��dS)Nrw�	foo_fieldzMyProto.foo_fieldrr?F)�name�	full_namer��number�typeZcpp_type�labelZ
default_value�containing_type�message_typeZ	enum_typeZis_extensionZextension_scope�optionsZMyProtoZignored)	r	r
�filenamer�nested_types�
enum_types�fields�
extensionsrcseZdZ�ZdS)z>ReflectionTest.testHandWrittenReflection.<locals>.MyProtoClassN)r&r'r(r�r)�mydescriptorrr�MyProtoClassHsrri)r
ryr�FieldDescriptor�
TYPE_INT64Z
CPPTYPE_INT64�LABEL_OPTIONALrZFieldOptions�
DescriptorZMessageOptions�six�with_metaclassr�GeneratedProtocolMessageTyper�Messager0rr^r<)rrZfoo_field_descriptorrZmyproto_instancer)rr�testHandWrittenReflection4s. z(ReflectionTest.testHandWrittenReflectioncs�tj�dkrdS�fdd��d�_tj�}d|_tj}�|d|j��|d|j��|d|j	��|d	|j
��jd
7_|jj�}d|_|j|_
�j|_tjj|_tj|��|jd�jk�|jd�jk�|jd�jk�|jd	�jk�|jd�jk�G�fdd
�d
tjtjtj��}|�}d|_d|_d|_d|_|jjddg�|j �}tj!�|�}|j||k	�|j"||�|j"|j|j�|j"|j|j�|j"|j|j�|j"|j|j�|j"|j|j�dS)Nrwcs:�jd7_|jj�}||_||_�j|_tjj|_	dS)Nr?)
�field_index�fieldr|r	rrr�FieldDescriptorProtorr
)r=r�Z
field_type�	new_field)�AddDescriptorFieldrrr%Ws
zEReflectionTest.testDescriptorProtoSupport.<locals>.AddDescriptorFieldrZCarr	�year�	automatic�pricer?�ownerscseZdZ�ZdS)z=ReflectionTest.testDescriptorProtoSupport.<locals>.CarMessageN)r&r'r(r�r)�descrr�
CarMessagewsr+�priusi�Tg���@ZbobZsusan)#r
ryr!rZDescriptorProtor	r#ZTYPE_STRINGrZ	TYPE_BOOLZTYPE_DOUBLEr"r|rr�LABEL_REPEATEDr
r�MakeDescriptorr^r�rrrrrrr&r'r(r)r�r�ZParseMessager0)rZ
desc_protoZfdpr$r+r,Zserialized_priusZ	new_priusr)r%r*r�testDescriptorProtoSupportQsN


 z)ReflectionTest.testDescriptorProtoSupportcCs�tj�}tj}|j|j|��|jd|j|�|j|j|��d|j|<|jd|j|�|j|j|��|j|�|jd|j|�|j|j|��dS)Nrri)rr�r�r^�HasExtensionr0r��ClearExtension)r�extendee_proto�	extensionrrr�'testTopLevelExtensionsForOptionalScalar�s

z6ReflectionTest.testTopLevelExtensionsForOptionalScalarcCs�tj�}tj}|jdt|j|��|j|jd�|jdg|j|�|j|}|j|�|jdt|j|��|j||j|k	�|j	t
tj|j|d�dS)NrrXrM)
rr�r�r0r$r�r{r1r^rYrZ�operator�setitem)rr2r3Zstring_listrrr�'testTopLevelExtensionsForRepeatedScalar�s

z6ReflectionTest.testTopLevelExtensionsForRepeatedScalarcCs�tj�}tj}|j|j|��|jd|j|j�|j|j|��d|j|_|jd|j|j�|j|j|��|j|}|j|�|j||j|k	�d|_|jd|j�|j|j	d��|j|j|��|j
ttj
|j|d�dS)Nrrir�rKrM)rr�Z"optional_foreign_message_extensionr^r0r0r�rKr1r<rYrZr5r6)rr2r3Zforeign_messagerrr�(testTopLevelExtensionsForOptionalMessage�s"

z7ReflectionTest.testTopLevelExtensionsForOptionalMessagecCs�tj�}tj}|jdt|j|��|j|j�}d|_|jd|j|dj�d|_|jd|j|dj�|j|}|j|�|jdt|j|��|j	||j|k	�|j
ttj
|j|d�dS)Nrrir�rM)rr��repeatedgroup_extensionr0r$r�r|rMr1r^rYrZr5r6)rr2r3�groupZ
group_listrrr�(testTopLevelExtensionsForRepeatedMessage�s

z7ReflectionTest.testTopLevelExtensionsForRepeatedMessagecCs�tj�}tjj}|j|j|��|j|}|jd|j�|j|j|��d|_|jd|j|j�|j|j|��|j	|�|j||j|k	�|j|j|��dS)Nrri)
rr��TestRequired�singler^r0r�r0rMr1)rr2r3Zrequiredrrr�testNestedExtensions�s

z#ReflectionTest.testNestedExtensionscCsTtjj}|j|jtjjd��|j|jd�jtjj�|j	dt
|jtjj���dS)Nr?z*protobuf_unittest.optional_int32_extensionr)
rr��poolr^ZFindExtensionByNumberr�ZassertIsZFindExtensionByNamerr0r$ZFindAllExtensionsr:)rr?rrr�testRegisteredExtensions�s
z'ReflectionTest.testRegisteredExtensionscCs�tj�}|j|jd��|jd|jjtj�|j|jd��d|jjtj<|jd|jjtj�|j|jd��tj�}|j|jd��|jg|jjtj�|j|jd��|jjtjj	d�|jdg|jjtj�|j|jd��tj�}|j|jd��|jd|jjtj
j�|j|jd��d|jjtj
_|jd|jjtj
j�|j|jd��tj�}|j|jd��|jdt|jjtj
��|j|jd��|jjtj
j�}|j||jjtj
d�|j|jd��dS)N�
submessagerri)r�TopLevelMessager^r<r0rAr��optional_int_extension�repeated_int_extensionr{�optional_message_extension�foreign_message_intr$�repeated_message_extensionr|)r�toplevel�foreignrrr�(testHasBitsForAncestorsOfExtendedMessage�sL



z7ReflectionTest.testHasBitsForAncestorsOfExtendedMessagecCsFtj�}|j}tj}|j|}|j|�d|_|j||j|k	�dS)Nri)rrBrArEr�r1rFr^)rrHr2r3Zextension_protorrr�*testDisconnectionAfterClearingEmptyMessage*s

z9ReflectionTest.testDisconnectionAfterClearingEmptyMessagecCs�tj�}|jt|jd�|jt|jd�|jt|jjd�|jt|jjdd�xbt	j
t	jt	jt	j
fD]J}|jt|j|�|jt|j|�|jt|jj|�|jt|jj|d�qdW|jt|jtj�dS)Ni�rp)rr�rY�KeyErrorr0r1r�r�r�rrCrErDrGr�)rr2Zunknown_handlerrr�testExtensionFailureModes4s&


z(ReflectionTest.testExtensionFailureModescCs6tj�}tj|�|j�}tjj|�}|j||�dS)N)rr:r�SetAllFieldsr��
FromStringr0)rrt�string1rurrr�testStaticParseFromSs

z"ReflectionTest.testStaticParseFromcCsFtj�}d|_tj�}d|_|j|�|jd|j�|jd|j�dS)Nr?r�)rr:r7r6rsr0)rrtrurrr�testMergeFromSingularField]s
z)ReflectionTest.testMergeFromSingularFieldcCsxtj�}|jjd�|jjd�tj�}|jjd�|j|�|jd|jd�|jd|jd�|jd|jd�dS)Nr?r@r)rr:rBr{rsr0)rrtrurrr�testMergeFromRepeatedFieldjs
z)ReflectionTest.testMergeFromRepeatedFieldcCs6tj�}d|j_tj�}|j|�|jd|jj�dS)NrL)rr:rerMrsr0)rrtrurrr�testMergeFromOptionalGroupxs

z)ReflectionTest.testMergeFromOptionalGroupcCs�tj�}|jj�}d|_|jj�}d|_tj�}|jj�}d|_|j|�|jd|jdj�|jd|jdj�|jd|jdj�tj�}|jj|j�|jd|jdj�|jd|jdj�|jd|jdj�dS)Nr�iAi�rr?r@)rr:rNr|rIrsr0)rrt�mruZproto3rrr�"testMergeFromRepeatedNestedMessage�s"



z1ReflectionTest.testMergeFromRepeatedNestedMessagecCsPtj�}tj|�tj�}|j|�|j||�|j�}|j�}|j||�dS)N)rr:rrNrsr0r�)rrtrurP�string2rrr�testMergeFromAllFields�s

z%ReflectionTest.testMergeFromAllFieldscCs>tj�}d|jtj<tj�}|j|�|jd|jtj�dS)Nr?)rr�r�r�rsr0)rrtrurrr�testMergeFromExtensionsSingular�s
z.ReflectionTest.testMergeFromExtensionsSingularcCs�tj�}|jtjjd�|jtjjd�tj�}|jtjjd�|j|�|jdt|jtj��|jd|jtjd�|jd|jtjd�|jd|jtjd�dS)Nr?r@rrA)rr�r�r�r{rsr0r$)rrtrurrr�testMergeFromExtensionsRepeated�s
z.ReflectionTest.testMergeFromExtensionsRepeatedcCs�tj�}|jtj}|j�}d|_|j�}d|_tj�}|jtj}|j�}d|_|j|�|jtj}|jdt|��|jd|dj�|jd|dj�|jd|dj�dS)N��iM�orArr?r@)	rr�r��!repeated_nested_message_extensionr|rIrsr0r$)rrtZext1rUruZext2rrr�$testMergeFromExtensionsNestedMessage�s&
z3ReflectionTest.testMergeFromExtensionsNestedMessagecCsDtj�}tj�}|j|j|jd��|j|�|j|jd��dS)NrV)rr:rVr;r<rs)r�message1�message2rrr�testMergeFromBug�s
zReflectionTest.testMergeFromBugcCsLtj�}d|_d|_tj�}d|_|j|�|jd|j�|jd|j�dS)Nr?zimportant-textr�)rr:r7r6r�r0)rrtrurrr�testCopyFromSingularField�s
z(ReflectionTest.testCopyFromSingularFieldcCsftj�}|jjd�|jjd�tj�}|jjd�|j|�|jd|jd�|jd|jd�dS)Nr?r@r)rr:rBr{r�r0)rrtrurrr�testCopyFromRepeatedField�s
z(ReflectionTest.testCopyFromRepeatedFieldcCsPtj�}tj|�tj�}|j|�|j||�|j�}|j�}|j||�dS)N)rr:rrNr�r0r�)rrtrurPrWrrr�testCopyFromAllFields�s

z$ReflectionTest.testCopyFromAllFieldscCs\tj�}|jjd�d|_d|_|j|�|jd|jd�|jd|j�|jd|j�dS)Nr?r@zimportant-textr)rr:rBr{r7r6r�r0)rrtrrr�testCopyFromSelfs
zReflectionTest.testCopyFromSelfcCs4tj�dkrdStj�}tj�}|jt|j|�dS)Nrw)r
ryrr:r�rYrZr�)rrtrurrr�testCopyFromBadTypes
z"ReflectionTest.testCopyFromBadTypecCs�tj�}d|_tj|�}|jd|j�|jjd�|jjd�tj|j�}|jddg|�|jj	�}d|_
tj|j�}|j|j|�d|_
|j|j|�dS)Nr?r@rA)rr:r7�copy�deepcopyr0rBr{rNr|rI�assertNotEqual)rrtruZ	containerr_Zmessagesrrr�testDeepCopy s

zReflectionTest.testDeepCopycCs�tj�}tj�dkr tj|�n
tj|�|j�|j|j	�d�tj�}|j||�tj
�}tj|�|j�|j|j	�d�tj
�}|j||�dS)Nrwr)rr:r
ryrrNZSetAllNonLazyFields�Clearr0r\r��SetAllExtensions)rr=Zempty_protorrr�	testClear4s

zReflectionTest.testClearcCstj�}|j}|j�|j||jk	�d|_|j|jd��|jd|jj�tj�}|j}d|_|j}d|_	|j�|j||jk	�|j||jk	�|jd|j�|jd|j	�d|_d|_	|j
|jd��|jd|jj�|j
|jd��|jd|jj	�dS)	NrirVrrpr�r��rf)rr:rVrkr^rIr<r0rfrKr;)rr=rjrIrrr�testDisconnectingBeforeClearKs.z+ReflectionTest.testDisconnectingBeforeClearcCsftj�}d|j_|j}|j|jjd�|j|jjd�d|j_|j|jjd�|j|jd�d|_dS)Nrprr��)rZ
TestOneof2Zfoo_messageZqux_intr0Zfoo_lazy_message)rrUZsub_messagerrr�testDisconnectingInOneoffsz'ReflectionTest.testDisconnectingInOneofcCsrtj�}d|_d|j_|jd|jj�|j|jd��|j}d|_|jd|j�|jd|j�|j|jd��dS)Nr�r��oneof_uint32r��oneof_nested_message)	rr:rrrsrIr0r;r<Zoneof_string)rr=rjrrr�	testOneOftszReflectionTest.testOneOfcCs"|j|j��|j�|j�dS)N)r^�
IsInitializedr��SerializePartialToString)rr=rrr�assertInitialized�sz ReflectionTest.assertInitializedNcCsNg}|j|j��|j|j|��|j|t|��|jtj|j�|j�dS)N)	r;rur0r$rYr�EncodeErrorr�rv)rr=Z
error_size�errorsrrr�assertNotInitialized�sz#ReflectionTest.assertNotInitializedcCs�tj�}|j|�tj�}|j|�tj�}|j|d�d|_|_|_|j|�tj	�}|j|�d|j
_|j|d�d|j
_d|j
_|j|�|jj�}|j|d�d|_|_|_|j|�tj�}tjj
}|j|j�}|j|j�}|j|d�d|_d|_d|_|j|d�d|_d|_d|_|j|�tj�}tjj}d|j|_|j|d�d|j|_d|j|_|j|�g}tj�}|j|j|��|j|dddg�dS)	NrAr@r?rr�rM�brK)rr:rwr�r<rzrMr{rKr��optional_messager�r|�multir�r=r;rur0)rr=r_r3r`ryrrr�testIsInitialized�sV








z ReflectionTest.testIsInitialized�cppr@zBErrors are only available from the most recent C++ implementation.cCs�d}d}tj�}||_||_|jj�}d|_tj|||j�d�d}||_|jj�}d|_|j	t
��`}tj|||j�d�|jt|d�dt
|jd|j��|jdt|j��|jd	t|j��WdQRXdS)
Nz!test_file_descriptor_errors.protoZmsg1)Z
serialized_pbz)another_test_file_descriptor_errors.protoZmsg2�	exceptionz
%s not raisedr&z test_file_descriptor_errors.msg1)r�FileDescriptorProtor	�packagerr|rZFileDescriptorr�rYrZr^�hasattrrb�expected�assertInr�r�)r�	file_nameZpackage_nameZfile_descriptor_protorZanother_file_namer�cmrrr�testFileDescriptorErrors�s0

z'ReflectionTest.testFileDescriptorErrorscCs�tj�}|jtt|dd�|jt|j�tj	�tj	d�|_|j|jt
d��t
d�|_|j|jtj	d��|jtt|dd�djd�}||_d|_d|_dS)	Nr�zunicode objectZTestingr6sa�auТестzutf-8r�)
rr:rYrZrcr0rr6r�	text_typer�r��encode)rr=Z
utf8_bytesrrr�testStringUTF8Encoding�s

z%ReflectionTest.testStringUTF8Encodingc
Csjtj�}tj}|j}d}|jd�}||j|_|j�}|j|j	�t
|��tj�}|j
|�}|jt
|�|�tj�}	|jdt
|j��|j|jdjd�|j|jdjj|��|	j
|jdj�}|jt
|jdj�|�|jt|	j�tj�|j|	j|�|jdjj|t
|�d�}
d}y|	j
|
�Wntk
�rFd}YnX|	j}|j|�pbt|�tk�dS)	NuТестzutf-8r?riʿ���FT)r
�TestMessageSet�TestMessageSetExtension2�message_set_extensionr�r�r�r�r0r\r$r�
RawMessageSet�MergeFromString�item�type_idr^r�endswithrrr��replace�UnicodeDecodeErrorr)
rr=Zextension_messager3Z	test_utf8Ztest_utf8_bytes�
serialized�raw�
bytes_readr`ZbadbytesZunicode_decode_failedZstring_fieldrrr�testStringUTF8Serializations8

	
z*ReflectionTest.testStringUTF8SerializationcCs"tjdd�}|jdtj|��dS)Ns��)r�z#optional_bytes: "\000\177\200\377"
)rr:r0rr�)rr=rrr�testBytesInTextFormat=sz$ReflectionTest.testBytesInTextFormatcCs�tj�}|jjtjj��|j|jd��tj�}|jjtjj��|j|jd��tj�}|jjd�}|j	d|�|j|jd��tj�}|jj
d�|j|jd��|j�}tj�}|j	t|�|j|��|j|jd��dS)NrVr�r)
rr:rVrsrQr^r<r�r�r0r�r�r$)rr=r�r�rurrr�testEmptyNestedMessageBs*z%ReflectionTest.testEmptyNestedMessagecCs6tj�}|j|jd��|jj�|j|jd��dS)Nre)rr:r;r<reZSetInParentr^)rr=rrr�testSetInParent]s
zReflectionTest.testSetInParentcCs*ddlm}|jj�}|jd|jj�dS)a�Test that we can import nested messages from their __init__.py.

    Such setup is not trivial since at the time of processing of __init__.py one
    can't refer to its submodules by name in code, so expressions like
    google.protobuf.internal.import_test_package.inner_pb2
    don't work. They do work in imports, so we have assign an alias at import
    and then use that alias in generated code.
    r)�import_test_package�9N)�google.protobuf.internalr�ZmyprotoZOuterr0�innerr�)rr��msgrrr�testPackageInitializationImportcs
z.ReflectionTest.testPackageInitializationImport)N)`r&r'r(r4r>rHrUrWr[r]r`rhrkrlrorqrrrvrzr}rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr r/r4r7r8r;r>r@rJrKrMrQrRrSrTrVrXrYrZr^rarbrcrdrerfrjrmrorqrtrwrzr~�unittest�skipIfr
ry�Versionr�r�r�r�r�r�r�rrrrr/rs�
"#Q	



)"!	ZS=1


	


	
	: 6r/c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TestAllTypesEqualityTestcCstj�|_tj�|_dS)N)rr:�first_proto�second_proto)rrrr�setUp{s
zTestAllTypesEqualityTest.setUpcCs|jtt|j�dS)N)rYrZ�hashr�)rrrr�testNotHashablesz(TestAllTypesEqualityTest.testNotHashablecCs|j|j|j�dS)N)r0r�)rrrr�testSelfEquality�sz)TestAllTypesEqualityTest.testSelfEqualitycCs|j|j|j�dS)N)r0r�r�)rrrr�testEmptyProtosEqual�sz-TestAllTypesEqualityTest.testEmptyProtosEqualN)r&r'r(r�r�r�r�rrrrr�ysr�c@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�FullProtosEqualityTestz@Equality tests using completely-full protos as a starting point.cCs0tj�|_tj�|_tj|j�tj|j�dS)N)rr:r�r�rrN)rrrrr��s

zFullProtosEqualityTest.setUpcCs|jtt|j�dS)N)rYrZr�r�)rrrrr��sz&FullProtosEqualityTest.testNotHashablecCs |j|jd�|jd|j�dS)N)rir�r�)rrrr�testNoneNotEqual�sz'FullProtosEqualityTest.testNoneNotEqualcCs(tj�}|j|j|�|j||j�dS)N)rr<rir�r�)rZthird_protorrr�testNotEqualToOtherMessage�sz1FullProtosEqualityTest.testNotEqualToOtherMessagecCs|j|j|j�dS)N)r0r�r�)rrrr�testAllFieldsFilledEquality�sz2FullProtosEqualityTest.testAllFieldsFilledEqualitycCs@|jjd7_|j|j|j�|jjd�|j|j|j�dS)Nr?r7)r�r7rir�r_)rrrr�testNonRepeatedScalar�sz,FullProtosEqualityTest.testNonRepeatedScalarcCs�|jjjd7_|j|j|j�|jjjd8_|j|j|j�|jjjd�|j|j|j�|jjj|jj_|j|j|j�|jjd�|j|j|j�dS)Nr?rIrV)r�rVrIrir�r0r_)rrrr�testNonRepeatedComposite�sz/FullProtosEqualityTest.testNonRepeatedCompositecCs>|jjjd�|j|j|j�|jjd�|j|j|j�dS)NrprB)r�rBr{rir�r_)rrrr�testRepeatedScalar�sz)FullProtosEqualityTest.testRepeatedScalarcCs�|jjdjd7_|j|j|j�|jjdjd8_|j|j|j�|jjj�|j|j|j�|jjj�|j|j|j�dS)Nrr?)r�rNrIrir�r0r|)rrrr�testRepeatedComposite�sz,FullProtosEqualityTest.testRepeatedCompositecCs(|jjd�d|j_|j|j|j�dS)Nr7r)r�r_r�r7ri)rrrr�testNonRepeatedScalarHasBits�sz3FullProtosEqualityTest.testNonRepeatedScalarHasBitscCsV|jjd�|jjjd�|j|j|j�d|jj_|jjjd�|j|j|j�dS)NrVrIr)r�r_r�rVrirIr0)rrrr�testNonRepeatedCompositeHasBits�s
z6FullProtosEqualityTest.testNonRepeatedCompositeHasBitsN)r&r'r(r)r�r�r�r�r�r�r�r�r�r�r�rrrrr��sr�c@seZdZdd�ZdS)�ExtensionEqualityTestcCs�tj�}tj�}|j||�tj|�|j||�tj|�|j||�|jtjd7<|j||�|jtjd8<|j||�|jtj�d|jtj<|j||�d|jtj<|j||�tj�}tj�}|jd|jtj�|j||�dS)Nr?r)	rr�r0rrlrir�r�r1)rr�r�rrr�testExtensionEquality�s*

z+ExtensionEqualityTest.testExtensionEqualityN)r&r'r(r�rrrrr��sr�c@seZdZdd�ZdS)�MutualRecursionEqualityTestcCsPtj�}tj�}|j||�d|jjj_|j||�d|jjj_|j||�dS)Nri)rr~r0rIrMr7ri)rr�r�rrr�testEqualityWithMutualRecursionsz;MutualRecursionEqualityTest.testEqualityWithMutualRecursionN)r&r'r(r�rrrrr�sr�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-S).�ByteSizeTestcCs,tj�|_tj�|_tj�|_tj�|_	dS)N)
rr:r=rZExtendedMessage�extended_proto�TestPackedTypes�packed_proto�TestPackedExtensions�packed_extended_proto)rrrrr�s


zByteSizeTest.setUpcCs
|jj�S)N)r=r\)rrrr�SizeszByteSizeTest.SizecCs|jd|jj��dS)Nr)r0r=r\)rrrr�testEmptyMessageszByteSizeTest.testEmptyMessagecCs8tj�}|jd|j��tjdd�}|jd|j��dS)Nrr?)r�r@)rr:r0r\)rr=Zproto_kwargsrrr�testSizedOnKwargsszByteSizeTest.testSizedOnKwargscs��fdd�}|dd�|dd�x>tttddd��ttdd���D]\}}|d|>d|�qBW|d
d�|dd�|d
d�dS)Ncs*�jj�|�j_�j|d�j��dS)Nr?)r=rkr�r0r�)r3Zexpected_varint_size)rrr�Test#s
z&ByteSizeTest.testVarints.<locals>.Testrr?rpr�i'r�r@r�r�ll����)�ziprGr1)rr�r3Z	num_bytesr)rr�testVarints"s

*

zByteSizeTest.testVarintscCshd|j_|jd|j��d|j_|jdt|jj�|j��dd|j_|jdt|jj�|j��dS)Nr�r@r�r��rA)r=r6r0r�r$)rrrr�testStrings1szByteSizeTest.testStringscCs�d|j_|jd|j��tj�|_d|j_|jd|j��tj�|_d|j_|jd|j��tj�|_d|j_|jd|j��tj�|_d|j_	|jd|j��tj�|_dS)Ni�rp�	gX9��v��?�@rA)
r=r�r0r�rr:r�r9r8r�)rrrr�testOtherNumerics>s



zByteSizeTest.testOtherNumericscCsd|jj_|jd|j��dS)	Nr?�rAr@i@rrprp)r=rVrIr0r�)rrrr�testCompositesXs
zByteSizeTest.testCompositescCsd|jj_|jd|j��dS)	Nr?r�rr@i r�rr�)r=rerMr0r�)rrrr�
testGroups`s
zByteSizeTest.testGroupscCs0|jjjd�|jjjd�|jd|j��dS)Nr�r�r?r@rArrp)r=rBr{r0r�)rrrrr�gsz ByteSizeTest.testRepeatedScalarscCs&|jjjddg�|jd|j��dS)Nr�r�r?r@rArrp)r=rBr�r0r�)rrrr�testRepeatedScalarsExtendmsz&ByteSizeTest.testRepeatedScalarsExtendcCsN|jjjd�|jjjd�|jd|j��|jjjd�|jd|j��dS)	Nr�r�r?r@rArrprA)r=rBr{r0r�r)rrrrrrs
z&ByteSizeTest.testRepeatedScalarsRemovecCs2|jjj�}|jjj�}d|_|jd|j��dS)	Nrpr@r?rArpr�rpr")r=rNr|rIr0r�)r�foreign_message_0�foreign_message_1rrrrzsz#ByteSizeTest.testRepeatedCompositescCs|jjj�}|jjj�}d|_|jd|j��tj|jj�}|jjd=|jd|j��|jjj�}d|_|jd|j��|jjd=|jd|j��|jjd=|jd|j��|jdt|��|dd�=t	j
�dk�r�|jdt|��|d=t	j
�dk�r|jdt|��dS)Nr�r@r?rrLrwrArpr�rpr"rArrprArrprpr"r�r�rArrpr�)r=rNr|rIr0r�rgrhr$r
ry)rr�r�rNZforeign_message_2rrr�testRepeatedCompositesDelete�s,




z)ByteSizeTest.testRepeatedCompositesDeletecCs2|jjj�}|jjj�}d|_|jd|j��dS)	Nrpr@r?rr�r"r�r�)r=rPr|rMr0r�)rZgroup_0Zgroup_1rrr�testRepeatedGroups�szByteSizeTest.testRepeatedGroupsc
Csjtj�}|jd|j��tj}d|j|<|jd|j��tjjjd}|j	t
��d|j|<WdQRXdS)Nrrir@r7)rr�r0r\r�r�r:r�r�rYrL)rr=r3r"rrr�testExtensions�s
zByteSizeTest.testExtensionscCs�d|j_|jd|jj��d|j_|jd|jj��|jjd�|jd|jj��tj}d|jj|<|jd|jj��d|jj|<|jd|jj��|jj	|�|jd|jj��dS)Nr?r@r�rAr7r)
r=r7r0r\r_rrCr�r�r1)rr3rrr�)testCacheInvalidationForNonrepeatedScalar�sz6ByteSizeTest.testCacheInvalidationForNonrepeatedScalarcCs|jjjd�|jd|jj��|jjjd�|jd|jj��d|jjd<|jd|jj��|jjd�|jd|jj��tj}|jj	|}|jd�|jd|jj��|jd�|jd	|jj��d|d<|jd
|jj��|jj
|�|jd|jj��dS)Nr?rAr�r�rprBrr@rrp)r=rBr{r0r\r_rrDr�r�r1)rr3Zrepeatedrrr�&testCacheInvalidationForRepeatedScalar�s$

z3ByteSizeTest.testCacheInvalidationForRepeatedScalarcCs$d|jj_|jd|jj��d|jj_|jd|jj��|jjjd�|jd|jj��|jjd�|jd|jj��tj�d	kr�|jj}|jjd�d|_|jd|jj��tj	}|j
j|}|jd|j
j��d|_|jd
|j
j��d|_|jd|j
j��|j
j
|�|jd|j
j��dS)Nr?rpr�r�rKrArfrrwr)r=rfrKr0r\r_r
ryrrEr�r�rFr1)r�childr3rrr�*testCacheInvalidationForNonrepeatedMessage�s,

z7ByteSizeTest.testCacheInvalidationForNonrepeatedMessagecCs|jjj�}|jd|jj��|jjj�|jd|jj��d|_|jd|jj��|jjd�|jd|jj��tj}|j	j
|}|j�}|jd|j	j��|j�|jd|j	j��d|_|jd|j	j��|jd	�|jd|j	j��|j	j|�|jd|j	j��dS)
NrAr�r?r"rOrr@rrF)
r=rOr|r0r\rKr_rrGr�r�rFr1)rZchild0r3Z
child_listrrr�'testCacheInvalidationForRepeatedMessage	s(
z4ByteSizeTest.testCacheInvalidationForRepeatedMessagecCs�|jd|jj��|jjjd�|jjjd�d}|j||jj��|jjjd�|jjjd�d}|j|||jj��|jjd
�|j||jj��dS)Nrr�r�r?r@rAg������@g
@r"�packed_int32rAr�rn�)r0r�r\r�r{�
packed_doubler_)rZint_sizeZdouble_sizerrr�testPackedRepeatedScalars	sz&ByteSizeTest.testPackedRepeatedScalarscCsH|jd|jj��|jjtj}|jddddg�|jd|jj��dS)Nrr?r@rArr�)r0r�r\r�rZpacked_fixed32_extensionr�)rr3rrr�testPackedExtensions0	s
z!ByteSizeTest.testPackedExtensionsN)r&r'r(r�r�r�r�r�r�r�r�r�r�r�rrr�r�r�r�r�r�r�r�r�rrrrr�s,
'	r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9S):�SerializationTestcCsRtj�}tj�}|j�}|j|j�t|��|jt|�|j|��|j||�dS)N)rr:r�r0r\r$r�)rr�r�r�rrr�testSerializeEmtpyMessageF	sz+SerializationTest.testSerializeEmtpyMessagecCs\tj�}tj�}tj|�|j�}|j|j�t|��|jt|�|j|��|j||�dS)N)	rr:rrNr�r0r\r$r�)rr�r�r�rrr�testSerializeAllFieldsP	s
z(SerializationTest.testSerializeAllFieldscCsHtj�}tj�}tj|�|j�}|jt|�|j|��|j||�dS)N)rr�rrlr�r0r$r�)rr�r�r�rrr�testSerializeAllExtensions[	s
z,SerializationTest.testSerializeAllExtensionscCsFtj�}tj�}d|j_|j�}|jt|�|j|��|j||�dS)N��)rr:rerMr�r0r$r�)rr�r�r�rrr�testSerializeWithOptionalGroupe	sz0SerializationTest.testSerializeWithOptionalGroupcCsLtj�}d|_d
|_d|_d
|_d|_d|_tjj|j	��}|j
||�dS)Nr?r@r�rArrpr�r�ll����r�ll�������ll����)rr:r7r�r�r�r�r�rOr�r0)rr�r�rrr�testSerializeNegativeValueso	s
z-SerializationTest.testSerializeNegativeValuescCs�tj�dkrdStj�}tj|�|j�}x�tt|�d�D]�}yntj�}tj	�}|j
|d|�}|j||�y|j
|d|�}|j||�Wn tj
k
r�|jd�YnXWq<tj
k
r�|jtj
|j
|d|�Yq<Xq<WdS)Nrwr?rz@Parsing unknown fields failed when parsing known fields did not.)r
ryrr:rrNr�r1r$�TestEmptyMessageZ_InternalParser0rZDecodeErrorZfailrY)rr�r�Ztruncation_pointr�Zunknown_fields�posZpos2rrr�testParseTruncated~	s&
z$SerializationTest.testParseTruncatedcCstj�}d|_d|jtj<d|_d|jtj<d|_|j�}|j	|j
�t|��t|�}|j
}|j	dtjf|��|j	d|j��|j	dtjf|��|j	d|j��|j	dtjf|��|j	d|j��|j	dtjf|��|j	d|j��|j	dtjf|��|j	d|j��dS)NrprrAr@r?)rZOutOfOrderFieldsr�r�r�r�r�r7r�r0r\r$rrrZWIRETYPE_VARINTr*r+r,r-r.)rr=r�rg�ReadTagrrr�testCanonicalSerializationOrder�	s(z1SerializationTest.testCanonicalSerializationOrdercCs(tj�}tj|�|j�}tj|�dS)N)rr�rr�r�Z#ExpectAllFieldsAndExtensionsInOrder)rr=r�rrr�(testCanonicalSerializationOrderSameAsCpp�	s
z:SerializationTest.testCanonicalSerializationOrderSameAsCppcCs�tj�}|jjd�d|_d|j_|j�}tj�}|jjd�d|_d|j_|j|�}|j	t
|�|�|j	ddgt|j��|j	d|j�|j	d|jj�dS)NZfoobarrir�r�r�i�)rr:rEr{r7rVrIr�r�r0r$rG)rr�r�r�Zbytes_parsedrrr�'testMergeFromStringWhenFieldsAlreadySet�	s
z9SerializationTest.testMergeFromStringWhenFieldsAlreadySetc
Cs�tj�}tj}tj}|j}|j}tj}d|j|_d|j|_d|j|_	|j
�}tj�}|j
d|jj�j�|j
t|�|j|��|j
dt|j��tj�}	|j
t|jdj�|	j|jdj��|j
d|	j�tj�}
|j
t|jdj�|
j|jdj��|j
d|
j�tj�}|j
t|jdj�|j|jdj��|j
d|j	�tj�}|j
t|�|j|��|j
d|j|j�|j
d|j|j�|j
d|j|j	�|j
|j�t|��|j
|j�t|��dS)	Nr�rXr�FrArr?r@)r
r��TestMessageSetExtension1r�r�Zmessage_set_extension3r�r3r��textr�rr�r0r��
GetOptions�message_set_wire_formatr$r�r�rZTestMessageSetExtension3r\)
rr=�extension_message1Zextension_message2�
extension1Z
extension2Z
extension3r�r�r_r`Zmessage3rurrr�testMessageSetWireFormat�	sRz*SerializationTest.testMessageSetWireFormatcCs�tj�}|jj�}d|_tj}tj�}d|_|j�|_	|jj�}d|_tj}tj�}d|_|j�|_	|jj�}d|_tj
�}d|_|j�|_	|j�}tj�}|j
t|�|j|��tj}|j}|j
d|j|j�dS)Ni���i90i���i:0i���rX)rr�r�r|r�r
r�r3r�rr�r�r�r0r$r�r�r�)rr�r�r�r_r�r=r�rrr�(testMessageSetWireFormatUnknownExtension	
s4





z:SerializationTest.testMessageSetWireFormatUnknownExtensioncCsptj�}tj|�|j�}tj�}|jt|�|j|��tj�}d|_	|j�}tj�}|jt|�|j|��dS)Nl����)
rr:rrNr�r�r0r$r�r�)rr=r�rurrr�testUnknownFields2
s
z#SerializationTest.testUnknownFieldscCsRy
|�Wn0|k
r:}z|j|t|��dSd}~XnX|jdt|���dS)zEThis method checks if the excpetion type and message are as expected.Nz
%s not raised)r0r�ZfailureException)rZ	exc_classZcallable_objr�Zexrrr�_CheckRaisesM
s
zSerializationTest._CheckRaisescCs6tj�}|jtj|jd�|j�}tj�}|j|jd��|j	|�|j|jd��d|_
|jtj|jd�|j�}d|_|jtj|jd�|j�}d|_|j�}|j�}tj�}|j
t|�|j|��|j
d|j
�|j
d|j�|j
d|j�|j
t|�|j|��|j
d|j
�|j
d|j�|j
d|j�dS)NzHMessage protobuf_unittest.TestRequired is missing required fields: a,b,crMr?zFMessage protobuf_unittest.TestRequired is missing required fields: b,cr@zDMessage protobuf_unittest.TestRequired is missing required fields: crA)rr<r�rrxr�rvr;r<r�rMr{rKr0r$r�)rr=�partialrur�rrr�testSerializeUninitializedX
sL
z,SerializationTest.testSerializeUninitializedcCs�tj�}|j�d|j_|jtj|jd�d|j_d|j_	|j�d|j
j�_d|j
j�_|jtj|jd�d|j
d_d|j
d_	d|j
d_d|j
d_	|j�dS)Nr?zoMessage protobuf_unittest.TestRequiredForeign is missing required fields: optional_message.b,optional_message.cr@rAz�Message protobuf_unittest.TestRequiredForeign is missing required fields: repeated_message[0].b,repeated_message[0].c,repeated_message[1].a,repeated_message[1].cr)rr�r�r|rMr�rrxr{rKr�r|)rr=rrr�$testSerializeUninitializedSubMessage�
s*z6SerializationTest.testSerializeUninitializedSubMessagecCs`tj�}tj�}tj|�|j�}|j|j�t|��|j|�}|j|j�|�|j||�dS)N)	rr�r�SetAllPackedFieldsr�r0r\r$r�)rr�r�r�r�rrr�testSerializeAllPackedFields�
s

z.SerializationTest.testSerializeAllPackedFieldscCsLtj�}tj�}tj|�|j�}|j|�}|j|j�|�|j||�dS)N)rr�rZSetAllPackedExtensionsr�r�r0r\)rr�r�r�r�rrr� testSerializeAllPackedExtensions�
s

z2SerializationTest.testSerializeAllPackedExtensionscCs�tj�}|jjddg�|jjd�|j�}tj�}|jjd�|jjddg�|jjd�|jt	|�|j
|��|jdddg|j�|jdddg|j�|jdg|j�dS)Nr?r@g@rAg�?g@r)rr�r�r�r�r{r�Z
packed_sint32r0r$r�)rr�r�r�rrr�1testMergePackedFromStringWhenSomeFieldsAlreadySet�
szCSerializationTest.testMergePackedFromStringWhenSomeFieldsAlreadySetcCsPtj�}|jjddddg�|jjddg�|jjd�|j�}|j|j	�t
|��t|�}|j}|jdt
jf|��|jd|j��|jd|j��|jd|j��|jd|j��|jd|j��|jd	t
jf|��|jd
|j��|jd|j��|jdt
jf|��|jd|j��|jd|j��|jd|j��|j|j��dS)Nr?r@�rAg�?g@�@g@�Zr�r�er"r@rArprn)rr�r�r�r�Zpacked_floatr{r�r0r\r$rrrZWIRETYPE_LENGTH_DELIMITEDr*r!r#r^r%)rr=r�rgr�rrr�testPackedFieldsWireFormat�
s,z,SerializationTest.testPackedFieldsWireFormatcCsZtj�}tj|�tj�}|j�}|jt|�|j|��tj�}tj	|�|j||�dS)N)
r�TestUnpackedTypesr�SetAllUnpackedFieldsr�r�r0r$r�r�)r�unpacked�packedr�r�rrr�testParsePackedFromUnpacked�
s

z-SerializationTest.testParsePackedFromUnpackedcCsZtj�}tj|�tj�}|j�}|jt|�|j|��tj�}tj	|�|j||�dS)N)
rr�rr�rr�r0r$r�r)rrrr�r�rrr�testParseUnpackedFromPacked�
s

z-SerializationTest.testParseUnpackedFromPackedcCs�tj�}|jtjjjd�|jtjjd�|jtjjd�|jtjjd�|jtjjd�|jtjj	d�|jtjj
d�|jtjjd�|jtjjd�dS)	Nr?rn�r�r�r�r��3)
rr:r0rQZBB_FIELD_NUMBERZOPTIONAL_INT32_FIELD_NUMBERZOPTIONALGROUP_FIELD_NUMBERZ$OPTIONAL_NESTED_MESSAGE_FIELD_NUMBERZ!OPTIONAL_NESTED_ENUM_FIELD_NUMBERZREPEATED_INT32_FIELD_NUMBERZREPEATEDGROUP_FIELD_NUMBERZ$REPEATED_NESTED_MESSAGE_FIELD_NUMBERZ!REPEATED_NESTED_ENUM_FIELD_NUMBER)rr=rrr�testFieldNumberssz"SerializationTest.testFieldNumberscCs8|jtjjjd�|jtjjd�|jtjjjd�|jtjjd�|jtjjd�|jtj	d�|jtj
jd�|jtjd�|jtjjd�|jtj
d�|jtjjd�|jtjd�|jtjjd�|jtjd�|jtjjd�|jtjd�|jtjjd	�|jtjd	�|jtjjd
�|jtjd
�dS)Ni�i�r?rnrr�r�r�r�r)r0rr<r=rZSINGLE_FIELD_NUMBERr}ZMULTI_FIELD_NUMBERr�Z%OPTIONAL_INT32_EXTENSION_FIELD_NUMBERZoptionalgroup_extensionZ$OPTIONALGROUP_EXTENSION_FIELD_NUMBERZ!optional_nested_message_extensionZ.OPTIONAL_NESTED_MESSAGE_EXTENSION_FIELD_NUMBERZoptional_nested_enum_extensionZ+OPTIONAL_NESTED_ENUM_EXTENSION_FIELD_NUMBERr�Z%REPEATED_INT32_EXTENSION_FIELD_NUMBERr9Z$REPEATEDGROUP_EXTENSION_FIELD_NUMBERr]Z.REPEATED_NESTED_MESSAGE_EXTENSION_FIELD_NUMBERZrepeated_nested_enum_extensionZ+REPEATED_NESTED_ENUM_EXTENSION_FIELD_NUMBER)rrrr�testExtensionFieldNumberss0

z+SerializationTest.testExtensionFieldNumberscCsZtjddddtjjdd�tjdd�tjjtjdddgd	�	}|j|j��|j|jd
��|j|jd��|j|jd��|j|jd
��|j|jd��|j|jd��|j|jd��|j|jd��|j	d|j
�|j	d|j�|j	d|j�|j	d|j
�|j	d|jj�|j	d|jj�|j	tjj|j�|j	tj|j�|j	dddg|j�dS)Nr?rXTsbar)rI)rKr@rA)	r7r6r�r�rVrfr��optional_foreign_enumrBr7r6r�r�rVrfr�r)rr:rQrTrRr�r^rur<r0r7r6r�r�rVrIrfrKr�rrB)rr=rrr�testInitKwargs+s:

z SerializationTest.testInitKwargscCsdd�}|jt|d�dS)NcSstjdd�}dS)N�unknown)r)rr�)Zunused_protorrr�(InitalizeEmptyMessageWithExtraKeywordArgKsz`SerializationTest.testInitArgsUnknownFieldName.<locals>.InitalizeEmptyMessageWithExtraKeywordArgz9Protocol message TestEmptyMessage has no "unknown" field.)r�r�)rrrrr�testInitArgsUnknownFieldNameJs
z.SerializationTest.testInitArgsUnknownFieldNamecCs�tjdddd�}|j|j��|j|jd��|j|jd��|j|jd��|j|jd��|jd|j�|jd|j�|jd|j�dS)Nr?)rMr{rKrMr{rK�dummy2)	rr<r^rur<r0rMr{rK)rr=rrr�testInitRequiredKwargsRsz(SerializationTest.testInitRequiredKwargscCs�tjtjdddd�d�}|j|j��|j|jd��|j|jj��|j|jjd��|j|jjd��|j|jjd��|j|jjd��|jtjdddd�|j�|jd|jj�|jd|jj	�|jd|jj
�dS)	Nr?)rMr{rK)r|r|rMr{rKr)rr�r<r^rur<r|r0rMr{rK)rr=rrr�testInitRequiredForeignKwargs]sz/SerializationTest.testInitRequiredForeignKwargscCsZtjdddgd�}|j|j��|jd|jd�|jd|jd�|jd|jd�dS)Nr?r@rA)rBr)rr:r^rur0rB)rr=rrr�testInitRepeatedKwargsms
z(SerializationTest.testInitRepeatedKwargsN)r&r'r(r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr	r
r
rrrrrrrrrrr�D	s8


6)3!
	r�c@seZdZdd�Zdd�ZdS)�OptionsTestcCs<tj�}|jd|jj�j�tj�}|jd|jj�j�dS)NTF)r
r�r0r�r�r�rr:)rr=rrr�testMessageOptionswszOptionsTest.testMessageOptionscCs�tj�}d|_d|_x&|j�D]\}}|jd|j�j�qWtj�}|j	j
d�|jj
d�x8|j�D],\}}|jd|j�j�|jtj
j|j�qfWdS)Nr?g@FT)rr:r7r8r�r0r�rr�r�r{r�rrr-r
)rr=Zfield_descriptor�_rrr�testPackedOptionss
zOptionsTest.testPackedOptionsN)r&r'r(rrrrrrrusrc@sreZdZejej�dko"ej�dkd�dd��Zdd�Z	e
jd�d	d
��Ze
jd�dd��Z
e
jd�d
d��ZdS)�ClassAPITestrr@z6C++ implementation requires a call to MakeDescriptor()c
Cs�tjddddggggd�}tjddddg|gggd�}tjddddggggd�}tjd	d
ddg||gggd�}tj|�}|jd|j�|jd|j�|jd|jj�dS)NZleafzpackage.parent.child.leafr�)rrrrrr�zpackage.parent.childZsiblingzpackage.parent.sibling�parentzpackage.parent)rrr�	MakeClassr��__dict__r�)rZ	leaf_descZ
child_descZsibling_descZparent_descZ
message_classrrr�!testMakeClassWithNestedDescriptor�s(




z.ClassAPITest.testMakeClassWithNestedDescriptorcCs(d|d}tj�}tj||�|j�S)a Get a serialized representation of a test FileDescriptorProto.

    Args:
      name: All calls to this must use a unique message name, to avoid
          collisions in the cpp descriptor pool.
    Returns:
      A string containing the serialized form of a test FileDescriptorProto.
    zmessage_type {  name: "ai"  field {    name: "flat"    number: 1    label: LABEL_REPEATED    type: TYPE_UINT32  }  field {    name: "bar"    number: 2    label: LABEL_OPTIONAL    type: TYPE_MESSAGE    type_name: "Bar"  }  nested_type {    name: "Bar"    field {      name: "baz"      number: 3      label: LABEL_OPTIONAL      type: TYPE_MESSAGE      type_name: "Baz"    }    nested_type {      name: "Baz"      enum_type {        name: "deep_enum"        value {          name: "VALUE_A"          number: 0        }      }      field {        name: "deep"        number: 4        label: LABEL_OPTIONAL        type: TYPE_UINT32      }    }  }})rr�r	�Merger�)rr	Zfile_descriptor_str�file_descriptorrrr�_GetSerializedFileDescriptor�s)z)ClassAPITest._GetSerializedFileDescriptorz MakeDescriptor is not repeatablecs�tj�dkrdStj�}|j|jd��tj|jd��G�fdd�dt	j
tjt
j��}|�}d}tj||�|j|jddd	g�dS)
z7Test that the generated class can parse a flat message.rwN�ArcseZdZ�ZdS)zSClassAPITest.testParsingFlatClassWithExplicitClassDeclaration.<locals>.MessageClassN)r&r'r(r�r)�msg_descriptorrr�MessageClass�sr&zflat: 0 flat: 1 flat: 2 r?r@)r
ryrr�r�r#rr.rrrrrrrr	r!r0�flat)rr"r&r��msg_strr)r%r�0testParsingFlatClassWithExplicitClassDeclaration�s
 z=ClassAPITest.testParsingFlatClassWithExplicitClassDeclarationcCs`tj�}|j|jd��tj|jd�}tj|�}|�}d}t	j
||�|j|jdddg�dS)z7Test that the generated class can parse a flat message.�Brzflat: 0 flat: 1 flat: 2 r?r@N)
rr�r�r#rr.rrrr	r!r0r')rr"r%�	msg_classr�r(rrr�testParsingFlatClass�s
z!ClassAPITest.testParsingFlatClasscCs^tj�}|j|jd��tj|jd�}tj|�}|�}d}t	j
||�|j|jj
jd�dS)z9Test that the generated class can parse a nested message.�Crzbar {  baz {    deep: 4  }}rN)rr�r�r#rr.rrrr	r!r0r�r�Zdeep)rr"r%r+r�r(rrr�testParsingNestedClasss
z#ClassAPITest.testParsingNestedClassN)r&r'r(r�r�r
ryr�r r#rZSkipReferenceLeakCheckerr)r,r.rrrrr�s8r�__main__))r)rgrmr5rrZ	unittest2r��ImportErrorZgoogle.protobufrrrrrrrr	r�r
rrr
rrrrZBaseTestCase�objectrr/r�r�r�r�r�r�rrr&�mainrrrr�<module>#sv-V!:5


Filemanager

Name Type Size Permission Actions
__init__.cpython-36.opt-1.pyc File 113 B 0644
__init__.cpython-36.pyc File 113 B 0644
_parameterized.cpython-36.opt-1.pyc File 13.17 KB 0644
_parameterized.cpython-36.pyc File 13.54 KB 0644
any_test_pb2.cpython-36.opt-1.pyc File 3.56 KB 0644
any_test_pb2.cpython-36.pyc File 3.56 KB 0644
api_implementation.cpython-36.opt-1.pyc File 2.48 KB 0644
api_implementation.cpython-36.pyc File 2.48 KB 0644
containers.cpython-36.opt-1.pyc File 19.77 KB 0644
containers.cpython-36.pyc File 19.77 KB 0644
decoder.cpython-36.opt-1.pyc File 20.5 KB 0644
decoder.cpython-36.pyc File 20.58 KB 0644
descriptor_database_test.cpython-36.opt-1.pyc File 2.09 KB 0644
descriptor_database_test.cpython-36.pyc File 2.09 KB 0644
descriptor_pool_test.cpython-36.opt-1.pyc File 28.47 KB 0644
descriptor_pool_test.cpython-36.pyc File 28.47 KB 0644
descriptor_pool_test1_pb2.cpython-36.opt-1.pyc File 8.48 KB 0644
descriptor_pool_test1_pb2.cpython-36.pyc File 8.48 KB 0644
descriptor_pool_test2_pb2.cpython-36.opt-1.pyc File 5.95 KB 0644
descriptor_pool_test2_pb2.cpython-36.pyc File 5.95 KB 0644
descriptor_test.cpython-36.opt-1.pyc File 29.15 KB 0644
descriptor_test.cpython-36.pyc File 29.15 KB 0644
encoder.cpython-36.opt-1.pyc File 23.43 KB 0644
encoder.cpython-36.pyc File 23.57 KB 0644
enum_type_wrapper.cpython-36.opt-1.pyc File 2.65 KB 0644
enum_type_wrapper.cpython-36.pyc File 2.65 KB 0644
factory_test1_pb2.cpython-36.opt-1.pyc File 4.26 KB 0644
factory_test1_pb2.cpython-36.pyc File 4.26 KB 0644
factory_test2_pb2.cpython-36.opt-1.pyc File 10.6 KB 0644
factory_test2_pb2.cpython-36.pyc File 10.6 KB 0644
file_options_test_pb2.cpython-36.opt-1.pyc File 2.29 KB 0644
file_options_test_pb2.cpython-36.pyc File 2.29 KB 0644
generator_test.cpython-36.opt-1.pyc File 10.52 KB 0644
generator_test.cpython-36.pyc File 10.52 KB 0644
json_format_test.cpython-36.opt-1.pyc File 28.12 KB 0644
json_format_test.cpython-36.pyc File 28.12 KB 0644
message_factory_test.cpython-36.opt-1.pyc File 5.34 KB 0644
message_factory_test.cpython-36.pyc File 5.34 KB 0644
message_listener.cpython-36.opt-1.pyc File 2.23 KB 0644
message_listener.cpython-36.pyc File 2.23 KB 0644
message_set_extensions_pb2.cpython-36.opt-1.pyc File 4.06 KB 0644
message_set_extensions_pb2.cpython-36.pyc File 4.06 KB 0644
message_test.cpython-36.opt-1.pyc File 58.58 KB 0644
message_test.cpython-36.pyc File 58.69 KB 0644
missing_enum_values_pb2.cpython-36.opt-1.pyc File 4.61 KB 0644
missing_enum_values_pb2.cpython-36.pyc File 4.61 KB 0644
more_extensions_dynamic_pb2.cpython-36.opt-1.pyc File 3.09 KB 0644
more_extensions_dynamic_pb2.cpython-36.pyc File 3.09 KB 0644
more_extensions_pb2.cpython-36.opt-1.pyc File 3.81 KB 0644
more_extensions_pb2.cpython-36.pyc File 3.81 KB 0644
more_messages_pb2.cpython-36.opt-1.pyc File 2.7 KB 0644
more_messages_pb2.cpython-36.pyc File 2.7 KB 0644
packed_field_test_pb2.cpython-36.opt-1.pyc File 7.8 KB 0644
packed_field_test_pb2.cpython-36.pyc File 7.8 KB 0644
proto_builder_test.cpython-36.opt-1.pyc File 2.26 KB 0644
proto_builder_test.cpython-36.pyc File 2.26 KB 0644
python_message.cpython-36.opt-1.pyc File 41.32 KB 0644
python_message.cpython-36.pyc File 41.41 KB 0644
reflection_test.cpython-36.opt-1.pyc File 78.49 KB 0644
reflection_test.cpython-36.pyc File 78.49 KB 0644
service_reflection_test.cpython-36.opt-1.pyc File 4.06 KB 0644
service_reflection_test.cpython-36.pyc File 4.06 KB 0644
symbol_database_test.cpython-36.opt-1.pyc File 3.65 KB 0644
symbol_database_test.cpython-36.pyc File 3.65 KB 0644
test_bad_identifiers_pb2.cpython-36.opt-1.pyc File 3.47 KB 0644
test_bad_identifiers_pb2.cpython-36.pyc File 3.47 KB 0644
test_util.cpython-36.opt-1.pyc File 24.73 KB 0644
test_util.cpython-36.pyc File 24.77 KB 0644
testing_refleaks.cpython-36.opt-1.pyc File 2.95 KB 0644
testing_refleaks.cpython-36.pyc File 2.95 KB 0644
text_encoding_test.cpython-36.opt-1.pyc File 1.33 KB 0644
text_encoding_test.cpython-36.pyc File 1.33 KB 0644
text_format_test.cpython-36.opt-1.pyc File 46.88 KB 0644
text_format_test.cpython-36.pyc File 46.88 KB 0644
type_checkers.cpython-36.opt-1.pyc File 8.94 KB 0644
type_checkers.cpython-36.pyc File 8.94 KB 0644
unknown_fields_test.cpython-36.opt-1.pyc File 8.94 KB 0644
unknown_fields_test.cpython-36.pyc File 8.94 KB 0644
well_known_types.cpython-36.opt-1.pyc File 25.43 KB 0644
well_known_types.cpython-36.pyc File 25.43 KB 0644
well_known_types_test.cpython-36.opt-1.pyc File 20.19 KB 0644
well_known_types_test.cpython-36.pyc File 20.19 KB 0644
wire_format.cpython-36.opt-1.pyc File 6.27 KB 0644
wire_format.cpython-36.pyc File 6.27 KB 0644
wire_format_test.cpython-36.opt-1.pyc File 5.43 KB 0644
wire_format_test.cpython-36.pyc File 5.43 KB 0644