HEX
Server: LiteSpeed
System: Linux server334.web-hosting.com 4.18.0-553.124.4.lve.el8.x86_64 #1 SMP Fri May 15 13:02:13 UTC 2026 x86_64
User: richfield (1256)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/google/protobuf/internal/__pycache__/message_test.cpython-36.pyc
3

���hnV�@s(dZdZddlZddlZddlZddlZddlZddlZddlZddl	Z	yddl
ZWnek
rpddlZYnXye
Wnek
r�dd�Z
YnXddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZej �rXe!Z"dd�Z#dd�Z$dd�Z%dd�Z&ej'Z'ej(defdef�Gdd �d e'��Z)Gd!d"�d"e'�Z*Gd#d$�d$e'�Z+Gd%d&�d&e'�Z,Gd'd(�d(e'�Z-ej.ej/�d)k�p�ej0d0kd,�Gd-d.�d.e'��Z1e2d/k�r$ej3�dS)1a�Tests python protocol buffers against the golden message.

Note that the golden messages exercise every known field type, thus this
test ends up exercising and verifying nearly all of the parsing and
serialization code in the whole library.

TODO(kenton):  Merge with wire_format_test?  It doesn't make a whole lot of
sense to call this a test of the "message" module, which only declares an
abstract interface.
z!gps@google.com (Gregory P. Smith)�NcCs||k||kS)N�)�x�yrr�"/usr/lib/python3.6/message_test.py�<lambda>>sr)�map_proto2_unittest_pb2)�map_unittest_pb2)�unittest_pb2)�unittest_proto3_arena_pb2)�descriptor_pb2)�descriptor_pool)�message_factory)�text_format)�api_implementation)�encoder)�packed_field_test_pb2)�	test_util)�testing_refleaks)�message)�_parameterizedcCs||kS)Nr)�valrrr�isnanVsrcCst|�ot|d�S)Nr)r)rrrr�isinfYsrcCst|�o|dkS)Nr)r)rrrr�IsPosInf\srcCst|�o|dkS)Nr)r)rrrr�IsNegInf^srZ_proto2Z_proto3c
@s8eZdZdd�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^d_d`dadbe1�gie2�g
Z3dcdd�Z4dedf�Z5dgdh�Z6didj�Z7dkdl�Z8dmdn�Z9dodp�Z:Gdqdr�dre;�Z<dsdt�Z=dudv�Z>dwdx�Z?dydz�Z@d{d|�ZAd}d~�ZBdd��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd]S)��MessageTestcCsXtj�dkr|jd�tjd�}|jt��}|jj|�WdQRX|j	dt
|j��dS)N�pythonz�Skipping testBadUtf8String, currently only the python api implementation raises UnicodeDecodeError when a string field contains bad utf-8.Zbad_utf8_stringzTestAllTypes.optional_string)r�TypeZskipTestr�GoldenFileData�assertRaises�UnicodeDecodeError�TestAllTypes�
FromString�assertIn�str�	exception)�self�message_moduleZ
bad_utf8_data�contextrrr�testBadUtf8Stringjs

zMessageTest.testBadUtf8StringcCsr|tkrtjd�}n
tjd�}|j�}|j|�|tkrDtj||�|j||j��tj	|�}|j||j��dS)NZ golden_message_oneof_implementedZgolden_message_proto3)
r	rrr!�ParseFromStringZExpectAllFieldsSet�assertEqual�SerializeToString�copy�deepcopy)r&r'�golden_data�golden_message�golden_copyrrr�testGoldenMessagets


zMessageTest.testGoldenMessagecCshtjd�}|j�}|j|�|j�}tj|�|j||�|j||j��tj|�}|j||j��dS)N�golden_packed_fields_message)	rr�TestPackedTypesr*ZSetAllPackedFieldsr+r,r-r.)r&r'r/r0�all_setr1rrr�testGoldenPackedMessage�s



z#MessageTest.testGoldenPackedMessagecCs�|j�}|jt|jd�|jt|jd�tjdd�}tj�dkrv|jt	j
��}|j|�WdQRX|jdt|j
��nftjdd��T}tjd	�|j|�t|�dks�t�t|djt�s�t�|jd
t|dj	��WdQRXdS)
Nr�0��rzUnexpected end-group tag.T)�record�alwaysz4Unexpected end-group tag: Not all data was converted���r<)r!r�	TypeErrorr"�	ExceptionrZTagBytesrrr�DecodeErrorr+r$r%�warnings�catch_warnings�simplefilter�len�AssertionError�
issubclass�category�RuntimeWarning)r&r'�msgZend_tagr(�wrrr�testParseErrors�s

zMessageTest.testParseErrorsc
s�d}|j�}|jjddddg�|j||jdd��|j||jdd��|j||jdd��Gd	d
�d
t��G�fdd�dt�}|j���|j|�d�WdQRXdS)
Ns5�
One string�
Two string�
Red string�Blue stringz
One stringz
Two stringz
Red stringzBlue string)�
deterministicFTc@seZdZdS)z:MessageTest.testDeterminismParameters.<locals>.BadArgErrorN)�__name__�
__module__�__qualname__rrrr�BadArgError�srOcs$eZdZ�fdd�Z�fdd�ZdS)z5MessageTest.testDeterminismParameters.<locals>.BadArgcs
���dS)Nr)r&)rOrr�__bool__�sz>MessageTest.testDeterminismParameters.<locals>.BadArg.__bool__cs
���dS)Nr)r&)rOrrrP�sN)rLrMrNrPr)rOrr�BadArg�srQ)r!�repeated_string�extendr+r,r>�objectr)r&r'r/r0rQr)rOr�testDeterminismParameters�s"z%MessageTest.testDeterminismParameterscCs@tjd�}|j�}|j|�tj|�}tj|�}|j||�dS)Nr0)rrr!r*�pickle�dumps�loadsr+)r&r'r/r0�pickled_message�unpickled_messagerrr�testPickleSupport�s



zMessageTest.testPickleSupportcCs�|tkrd}nd}|j�}|j|�|jt|j��|jt|j��|jt|jd��|jt|jd��|j	||j
��dS)Ns]�a�����s ]�a�����r)r	r!r*�
assertTruer�optional_float�optional_double�repeated_float�repeated_doubler+r,)r&r'r/r0rrr�testPositiveInfinity�s
z MessageTest.testPositiveInfinitycCs�|tkrd}nd}|j�}|j|�|jt|j��|jt|j��|jt|jd��|jt|jd��|j	||j
��dS)Ns]��a������s ]��a������r)r	r!r*r\rr]r^r_r`r+r,)r&r'r/r0rrr�testNegativeInfinity�s
z MessageTest.testNegativeInfinitycCs�d}|j�}|j|�|jt|j��|jt|j��|jt|jd��|jt|jd��|j�}|j�}|j|�|jt|j��|jt|j��|jt|jd��|jt|jd��dS)Ns]�a�����r)	r!r*r\rr]r^r_r`r,)r&r'r/r0�
serializedrrrr�testNotANumber�s

zMessageTest.testNotANumbercCsRd}|j�}|j|�|jt|jd��|jt|jd��|j||j��dS)Ns����r)r4r*r\r�packed_float�
packed_doubler+r,)r&r'r/r0rrr�testPositiveInfinityPackeds
z&MessageTest.testPositiveInfinityPackedcCsRd}|j�}|j|�|jt|jd��|jt|jd��|j||j��dS)Ns�����r)r4r*r\rrerfr+r,)r&r'r/r0rrr�testNegativeInfinityPackeds
z&MessageTest.testNegativeInfinityPackedcCs�d}|j�}|j|�|jt|jd��|jt|jd��|j�}|j�}|j|�|jt|jd��|jt|jd��dS)Ns����r)r4r*r\rrerfr,)r&r'r/r0rcrrrr�testNotANumberPacked%s

z MessageTest.testNotANumberPackedcCst|j�}tjdd�}||_|j|j��|j|j|k�dtjdd�}||_|j|j��|j|j|k�||_|j|j��|j|j|k�||_|j|j��|j|j|k�tjdd�}||_|j|j��|j|j|k�dtjdd�}||_|j|j��|j|j|k�||_|j|j��|j|j|k�||_|j|j��|j|j|k�dS)N��g�?i����i����)r!�math�powr]r*r,r\)r&r'r�kMostPosExponentNoSigBits�kMostPosExponentOneSigBit�kMostNegExponentNoSigBits�kMostNegExponentOneSigBitrrr�testExtremeFloatValues3s:z"MessageTest.testExtremeFloatValuescCst|j�}tjdd�}||_|j|j��|j|j|k�dtjdd�}||_|j|j��|j|j|k�||_|j|j��|j|j|k�||_|j|j��|j|j|k�tjdd�}||_|j|j��|j|j|k�dtjdd�}||_|j|j��|j|j|k�||_|j|j��|j|j|k�||_|j|j��|j|j|k�dS)Nrji�g�?i���i���)r!rlrmr^r*r,r\)r&r'rrnrorprqrrr�testExtremeDoubleValues`s:z#MessageTest.testExtremeDoubleValuescCs"|j�}d|_|jt|�d�dS)Ng@zoptional_float: 2.0
)r!r]r+r$)r&r'rrrr�testFloatPrinting�szMessageTest.testFloatPrintingcCs>|j�}d|_tjdkr*|jt|�d�n|jt|�d�dS)Ng^!�7ݚ�?�z%optional_double: 0.12345678912345678
z optional_double: 0.123456789123
)ru)r!r^�sys�version_infor+r$)r&r'rrrr�testHighPrecisionFloatPrinting�s

z*MessageTest.testHighPrecisionFloatPrintingcCs<|j�}tj|�|j�}|j|j��|jt|�d�dS)N�)r!rZSetAllNonLazyFieldsZTestEmptyMessager*r,r+r$)r&r'Z	populated�emptyrrr�testUnknownFieldPrinting�s

z$MessageTest.testUnknownFieldPrintingcCs�|j�}|jjdd�|jjdd�|jjdd�|jjdd�|jddddgdd�|jD��|jddddgdd�t|j�D��|jddddgd	d�|jddd
�D��dS)Nr8)�bbrjrur9cSsg|]
}|j�qSr)r|)�.0�mrrr�
<listcomp>�sz@MessageTest.testRepeatedNestedFieldIteration.<locals>.<listcomp>cSsg|]
}|j�qSr)r|)r}r~rrrr�scSsg|]
}|j�qSr)r|)r}r~rrrr�sr<)r!�repeated_nested_message�addr+�reversed)r&r'rHrrr� testRepeatedNestedFieldIteration�sz,MessageTest.testRepeatedNestedFieldIterationcCs�|j�}|jjd�|jjd�|jjd�|jj�|j|jdd�|j|jdd�|j|jdd�|jt|j�tdddg��|jjd�|jjd�|jjd�|jj�|j|jdd�|j|jdd�|j|jdd�|jjd�|jjd	�|jjd
�|jj�|j|jdd�|j|jdd
�|j|jdd	�|jt|j�tdd
d	g��|j	jd�|j	jd�|j	jd
�|j	j�|j|j	dd�|j|j	dd
�|j|j	dd�|jt|j	�tdd
dg��dS)z7Check some different types with the default comparator.r8rurjrg�������?g�������?g333333�?�a�c�b�a�c�bN)
r!�repeated_int32�append�sortr+r$r_�assertAlmostEqualrRZrepeated_bytes)r&r'rrrr�0testSortingRepeatedScalarFieldsDefaultComparator�s@



z<MessageTest.testSortingRepeatedScalarFieldsDefaultComparatorcCs�|j�}|jjd
�|jjd�|jjd�|jjtd�|j|jdd
�|j|jdd�|j|jdd�|jjd�|jjd�|jjd�|jjtd�|j|jdd�|j|jdd�|j|jdd�d	S)z2Check some different types with custom comparator.rurjr8)�keyr�aaar|r�N������r<r<r�r�)r!r�r�r��absr+rRrC)r&r'rrrr�/testSortingRepeatedScalarFieldsCustomComparator�sz;MessageTest.testSortingRepeatedScalarFieldsCustomComparatorcCs�|j�}d|jj�_d|jj�_d|jj�_d|jj�_d|jj�_d|jj�_|jjtjd�d�|j|jd	jd�|j|jdjd�|j|jdjd�|j|jdjd�|j|jdjd�|j|jdjd�|jt|j�d
�dS)zECheck passing a custom comparator to sort a repeated composite field.r8rurj��r9r|)r�rz0[bb: 1
, bb: 2
, bb: 3
, bb: 4
, bb: 5
, bb: 6
]N)	r!r�r�r|r��operator�
attrgetterr+r$)r&r'rrrr�2testSortingRepeatedCompositeFieldsCustomComparator�s z>MessageTest.testSortingRepeatedCompositeFieldsCustomComparatorcCs�|j�}d|jj�_d|jj�_d|jj�_d|jj�_d|jj�_d|jj�_d|jj�_|jjdd	�d
�|jdddddddgdd�|jD��|j�}|j�|j|�|jdddddddgd
d�|jD��dS)zECheck passing a custom comparator to sort a repeated composite field.���
�!���
cSs
|jdS)Nr�)r|)�zrrrr
szFMessageTest.testSortingRepeatedCompositeFieldsStable.<locals>.<lambda>)r�cSsg|]
}|j�qSr)r|)r}�nrrrr
szHMessageTest.testSortingRepeatedCompositeFieldsStable.<locals>.<listcomp>cSsg|]
}|j�qSr)r|)r}r�rrrrsN)	r!r�r�r|r�r+r,�ClearZMergeFromString)r&r'r�pbrrr�(testSortingRepeatedCompositeFieldsStable�s$
z4MessageTest.testSortingRepeatedCompositeFieldsStablecCs@|j�}tjd�}dd�}d|jj�_d|jj�_d|jj�_d|jj�_d|jj�_d	|jj�_|jj|d
�|jdd�|jD�dddd	ddg�|jj|d
d�|jdd�|jD�ddd	dddg�tj	dkr�dS|jj|d�|jdd�|jD�dddd	ddg�|jj|d
d�|jdd�|jD�ddd	dddg�dS)zECheck sorting a repeated composite field using list.sort() arguments.r|cSst|j|j�S)N)�cmpr|)r�r�rrrrszEMessageTest.testRepeatedCompositeFieldSortArguments.<locals>.<lambda>r8rurjr�r�r9)r�cSsg|]
}|j�qSr)r|)r}�krrrr%szGMessageTest.testRepeatedCompositeFieldSortArguments.<locals>.<listcomp>T)r��reversecSsg|]
}|j�qSr)r|)r}r�rrrr(sN)�
sort_functioncSsg|]
}|j�qSr)r|)r}r�rrrr,s)r�r�cSsg|]
}|j�qSr)r|)r}r�rrrr/s)ru)
r!r�r�r�r�r|r�r+rvrw)r&r'rZget_bbZcmp_bbrrr�'testRepeatedCompositeFieldSortArgumentss.

z3MessageTest.testRepeatedCompositeFieldSortArgumentscCs�|j�}|jjd�|jjd�|jjd�|jjtd�|jt|j�dddg�|jjtdd�|jt|j�dddg�tjdkr�dd�}|jj|d	�|jt|j�dddg�|jj|dd
�|jt|j�dddg�|j	jd�|j	jd�|j	jd
�|j	jt
d�|jt|j	�d
ddg�|j	jt
dd�|jt|j	�ddd
g�tjd k�r�dd�}|j	j|d	�|jt|j	�d
ddg�|j	j|dd
�|jt|j	�ddd
g�dS)!z9Check sorting a scalar field using list.sort() arguments.rurjr8)r�T)r�r�cSstt|�t|��S)N)r�r�)r�r�rrrr>szBMessageTest.testRepeatedScalarFieldSortArguments.<locals>.<lambda>)r�)r�r�r�r|r�cSstt|�t|��S)N)r�rC)r�r�rrrrLsNr�r�r<r<r�r�r�r�r<)rur<r�r�r�r�r<)ru)r!r�r�r�r�r+�listrvrwrRrC)r&r'rZabs_cmpZlen_cmprrr�$testRepeatedScalarFieldSortArguments2s6
z0MessageTest.testRepeatedScalarFieldSortArgumentscCsJ|j�}|j�}|jjd�|jjd�|jjd�|jjd�|jjd�|jjd�d|jj�_d|jj�_d|jj�_d|jj�_d|jj�_d|jj�_tjdkr�dS||k}|j|jk}|jt	||�d�|jt	|j|j�d�|jt	|jdddg�d�|jt	|j|j�d�|j
t��t	|j|jdd��WdQRXdS)Nrr8rjru)ru)r!r�r�r�r�r|rvrwr+r�rr=)r&r'�m1�m2�_rrr�testRepeatedFieldsComparableRs2

z(MessageTest.testRepeatedFieldsComparablecCs,|j�}|j|jtj�|j|jtj�dS)N)r!�assertIsInstancer��collections�MutableSequencer�)r&r'r~rrr�testRepeatedFieldsAreSequencesusz*MessageTest.testRepeatedFieldsAreSequencescCsL|j�}|jt��t|j�WdQRX|jt��t|j�WdQRXdS)N)r!rr=�hashr�r�)r&r'r~rrr�testRepeatedFieldsNotHashable{s
z)MessageTest.testRepeatedFieldsNotHashablecCs*|j�}|jjjg�|j|jd��dS)N�payload)�NestedTestAllTypesr�r�rSr\�HasField)r&r'r~rrr�$testRepeatedFieldInsideNestedMessage�sz0MessageTest.testRepeatedFieldInsideNestedMessagecCst||�|j|j|��dS)z�Make sure that a nested message object exists.

    As soon as a nested message attribute is accessed, it will be present in the
    _fields dict, without being marked as actually being set.
    N)�getattr�assertFalser�)r&rHZ	attributerrr�ensureNestedMessageExists�s
z%MessageTest.ensureNestedMessageExistscCs,|j�}|jt|jd�|jt|jd�dS)NZno_such_oneof_fieldr)r!r�
ValueError�
WhichOneofr>)r&r'r~rrr� testOneofGetCaseNonexistingField�sz,MessageTest.testOneofGetCaseNonexistingFieldcCs�|j�}|jd|jd��|j|jd��d|_|jd|jd��|j|jd��|j|jd��d|_|jd|jd��|j|jd��|j|jd��dS)N�oneof_field�oneof_uint32r�oneof_stringry)	r!�assertIsr�r�r�r�r+r\r�)r&r'r~rrr�testOneofDefaultValues�sz"MessageTest.testOneofDefaultValuescCsb|j�}|jd|jd��d|_|jd|jd��|j|jd��d|_|jd|jd��|j|jd��|j|jd��|j	|jd|jd��|j|jd��|j|jd��|j	j
|jd|jd��|j|jd��|j|jd��d|j	_
|jd|jd��|j|jd��|j|jd��d|_|jd|jd��|j|jd��|j|jd��dS)	Nr�r�r��foor��oneof_nested_messagesbb�oneof_bytes)r!r�r�r�r+r\r�r�r�r�r|r�)r&r'r~rrr�testOneofSemantics�s2zMessageTest.testOneofSemanticscCs>|j�}d|_|j|d�|jd|jd��|jd|j�dS)Nr�r�r�r�)r!r�r�r+r�)r&r'r~rrr�!testOneofCompositeFieldReadAccess�s
z-MessageTest.testOneofCompositeFieldReadAccesscCs�|j�}|jd|jd��|tkr2|j|jd��d|_|jd|jd��|tkrb|j|jd��d|_	|jd|jd��|j
d�|jd|jd��|tkr�|j|jd��dS)Nr�r�r�sbbr�)r!r�r�r	r�r�r�r+r\r��
ClearField)r&r'r~rrr�testOneofWhichOneof�s
zMessageTest.testOneofWhichOneofcCsV|j�}d|_|jd�|tkr0|j|jd��|j|jd��|jd|jd��dS)Nr�r�r�)r!r�r�r	r�r�r�r�)r&r'r~rrr�testOneofClearField�s
zMessageTest.testOneofClearFieldcCsV|j�}d|_|jd�|tkr0|j|jd��|j|jd��|jd|jd��dS)Nr�r�r�)r!r�r�r	r�r�r�r�)r&r'r~rrr�testOneofClearSetField�s
z"MessageTest.testOneofClearSetFieldcCsp|j�}d|_|j|d�|jd�|jd|j�|tkrJ|j|jd��|j|jd��|jd|jd��dS)Nr�r�r�r�)	r!r�r�r�r+r	r\r�r�)r&r'r~rrr�testOneofClearUnsetField�s
z$MessageTest.testOneofClearUnsetFieldcCs:|j�}d|_|j�}|j|j��|jd|jd��dS)Nr�r�r�)r!r�r*r,r+r�)r&r'r~r�rrr�testOneofDeserializes
z MessageTest.testOneofDeserializecCs6|j�}d|_|j�}|j|�|jd|jd��dS)Nr�r�r�)r!r��CopyFromr+r�)r&r'r~r�rrr�testOneofCopyFroms

zMessageTest.testOneofCopyFromcCsb|j�}d|j_|j�}d|j_d|jj_|j|�|jd|jjd��|jd|jjjd��dS)Nr�sbbr�r�r�)r�r�r�r��child�	MergeFromr+r�)r&r'r~r�rrr�testOneofNestedMergeFroms

z$MessageTest.testOneofNestedMergeFromcCsf|j�}d|jj_d|jjj_|j�}d|j_|j|�|jd|jjd��|jd|jjjd��dS)Nr��r�r�r�)	r�r�r�r|r�r�r�r+r�)r&r'r~r�rrr�testOneofMessageMergeFroms

z%MessageTest.testOneofMessageMergeFromcCs(|j|jj�d�}|jd|jd��dS)N)r�r�r�)r!�
NestedMessager+r�)r&r'r~rrr�testOneofNestedMessageInit$sz&MessageTest.testOneofNestedMessageInitcCsB|j�}d|_|j�|j|jd��d|_|jd|jd��dS)Nr�r�sbbr�)r!r�r��assertIsNoner�r�r+)r&r'r~rrr�testOneofClear)szMessageTest.testOneofClearcCs&|j�}td�|_|j|jtj�dS)zmAssigning a byte string to a string field should result
    in the value being converted to a Unicode string.ryN)r!r$�optional_stringr��six�	text_type)r&r'r~rrr�"testAssignByteStringToUnicodeField1s
z.MessageTest.testAssignByteStringToUnicodeFieldcCs�|j�}|jjd�|jtd�tt|j���}|jt|j�t|��d|jj�_|jtd�tt|j���}|jt|j�t|��dS)z|It should be possible to use long-valued indicies in slices

    This didn't used to work in the v2 C++ implementation.
    r8rruN)	r!r�r��intrCr+r�r�r|)r&r'r~Zslrrr�testLongValuedSlice8szMessageTest.testLongValuedSlicecCsl|j�}|jt�� }|jjdd�td�D��WdQRX|jt�� }|jjdd�td�D��WdQRXdS)z5This didn't use to work in the v2 C++ implementation.css|]
}tVqdS)N)r�)r}�irrr�	<genexpr>MszCMessageTest.testExtendShouldNotSwallowExceptions.<locals>.<genexpr>r�Ncss|]
}tVqdS)N)r�)r}r�rrrr�Ps)r!r�	NameErrorr�rS�range�repeated_nested_enum)r&r'r~r�rrr�$testExtendShouldNotSwallowExceptionsIs$z0MessageTest.testExtendShouldNotSwallowExceptionsNFrg�rycCs^|j�}|jg|j�x(tjD]}|jj|�|jg|j�qW|jjg�|jg|j�dS)z,Test no-ops extending repeated int32 fields.N)r!�assertSequenceEqualr�r�FALSY_VALUESrS)r&r'r~�falsy_valuerrr�testExtendInt32WithNothingTsz&MessageTest.testExtendInt32WithNothingcCs^|j�}|jg|j�x(tjD]}|jj|�|jg|j�qW|jjg�|jg|j�dS)z,Test no-ops extending repeated float fields.N)r!r�r_rr�rS)r&r'r~r�rrr�testExtendFloatWithNothingasz&MessageTest.testExtendFloatWithNothingcCs^|j�}|jg|j�x(tjD]}|jj|�|jg|j�qW|jjg�|jg|j�dS)z-Test no-ops extending repeated string fields.N)r!r�rRrr�rS)r&r'r~r�rrr�testExtendStringWithNothingnsz'MessageTest.testExtendStringWithNothingcCs�|j�}|jg|j�|jjdg�|jdg|j�|jjddg�|jdddg|j�|jjddg�|jdddddg|j�dS)z7Test extending repeated int32 fields with python lists.rr8rjrur9N)r!r�r�rS)r&r'r~rrr�testExtendInt32WithPythonList{sz)MessageTest.testExtendInt32WithPythonListcCs�|j�}|jg|j�|jjdg�|jdg|j�|jjddg�|jdddg|j�|jjddg�|jdddddg|j�dS)z7Test extending repeated float fields with python lists.gg�?g@g@g@N)r!r�r_rS)r&r'r~rrr�testExtendFloatWithPythonList�sz)MessageTest.testExtendFloatWithPythonListcCs�|j�}|jg|j�|jjdg�|jdg|j�|jjddg�|jdddg|j�|jjddg�|jdddddg|j�dS)z8Test extending repeated string fields with python lists.ryZ11Z22Z33Z44N)r!r�rRrS)r&r'r~rrr�testExtendStringWithPythonList�sz*MessageTest.testExtendStringWithPythonListcCs:|j�}|jg|j�|jjd�|jdddg|j�dS)zDTest extending repeated string fields with characters from a string.�abcr�r�r�N)r!r�rRrS)r&r'r~rrr�testExtendStringWithString�sz&MessageTest.testExtendStringWithStringc@s2eZdZdZddd�Zdd�Zdd�Zd	d
�ZdS)zMessageTest.TestIterablez�This iterable object mimics the behavior of numpy.array.

    __nonzero__ fails for length > 1, and returns bool(item[0]) for length == 1.

    NcCs|pg|_dS)N)�_list)r&�valuesrrr�__init__�sz!MessageTest.TestIterable.__init__cCs8t|j�}|dkrdS|dkr,t|jd�Std��dS)NrFr8zTruth value is ambiguous.)rCr��boolr�)r&�sizerrrrP�s
z!MessageTest.TestIterable.__bool__cCs
t|j�S)N)rCr�)r&rrr�__len__�sz MessageTest.TestIterable.__len__cCs
|jj�S)N)r��__iter__)r&rrrr��sz!MessageTest.TestIterable.__iter__)N)rLrMrN�__doc__r�rPr�r�rrrr�TestIterable�s

r�cCs�|j�}|jg|j�|jjtjg��|jg|j�|jjtjdg��|jdg|j�|jjtjddg��|jdddg|j�|jjtjddg��|jdddddg|j�dS)z3Test extending repeated int32 fields with iterable.rr8rjrur9N)r!r�r�rSrr�)r&r'r~rrr�testExtendInt32WithIterable�sz'MessageTest.testExtendInt32WithIterablecCs�|j�}|jg|j�|jjtjg��|jg|j�|jjtjdg��|jdg|j�|jjtjddg��|jdddg|j�|jjtjddg��|jdddddg|j�dS)z3Test extending repeated float fields with iterable.gg�?g@g@g@N)r!r�r_rSrr�)r&r'r~rrr�testExtendFloatWithIterable�sz'MessageTest.testExtendFloatWithIterablecCs�|j�}|jg|j�|jjtjg��|jg|j�|jjtjdg��|jdg|j�|jjtjddg��|jdddg|j�|jjtjddg��|jdddddg|j�dS)z4Test extending repeated string fields with iterable.ry�1�2�3�4N)r!r�rRrSrr�)r&r'r~rrr�testExtendStringWithIterable�sz(MessageTest.testExtendStringWithIterablec
CsPtj�dkstj�dkrdS|j�}|jtj��}tj|jtj	�WdQRXdS)N�cpprj)
rrZVersionr!rrVZPickleErrorrWr�ZHIGHEST_PROTOCOL)r&r'r~r�rrr�!testPickleRepeatedScalarContainer�sz-MessageTest.testPickleRepeatedScalarContainercCs|j�}|jj�dS)z?Exercise a scenario that has led to segfaults in the past.
    N)r!r�r�)r&r'r~rrr�'testSortEmptyRepeatedCompositeContainer�sz3MessageTest.testSortEmptyRepeatedCompositeContainerc	Cs,|j�}|jt��}|jd�WdQRXdS)zBUsing HasField on a repeated field should raise an exception.
    r�N)r!rr�r�)r&r'r~r�rrr�testHasFieldOnRepeatedField�sz'MessageTest.testHasFieldOnRepeatedFieldcCs�|j�}|jt��}|jj�WdQRX|jjttd���|jd|jj��|jd|jjd��|jd|jjd��|jddg|j�dS)Nr�r9rrjr8ru)	r!r�
IndexErrorr��poprSr�r�r+)r&r'r~r�rrr�testRepeatedScalarFieldPop�sz&MessageTest.testRepeatedScalarFieldPopcCs�|j�}|jt��}|jj�WdQRX|jt��}|jjd�WdQRXx td�D]}|jj�}||_qTW|j	d|jj�j�|j	d|jjd�j�|j	d|jjd�j�|j	ddgdd	�|jD��dS)
Nr7r�r9rrjr8rucSsg|]
}|j�qSr)r|)r}r�rrrrsz=MessageTest.testRepeatedCompositeFieldPop.<locals>.<listcomp>)
r!rrr�r	r=r�r�r|r+)r&r'r~r�r�r�rrr�testRepeatedCompositeFieldPops

z)MessageTest.testRepeatedCompositeFieldPopcCs\|j�}x.td�D]"}|jj||�|jj�}||_qW|j|j|j�|j|j|j�dS)Nr�)	r!r�r��insertr�r�r|r�r+)r&r'r~r�r�rrr�testRepeatedCompareWithSelfs

z'MessageTest.testRepeatedCompareWithSelfcCs6|j�}|jj�}|j}|jj�}|j|jjd�dS)zwA case that lead to a segfault when a message detached from its parent
    container has itself a child container.
    rN)r�Zrepeated_childr�r�r+r��optional_int32)r&r'r~rrr�testReleasedNestedMessagess


z&MessageTest.testReleasedNestedMessagescCsz|j�}|jt��g|_WdQRX|jjd�tj�dkrZ|jt��g|_WdQRXn|jt��g|_WdQRXdS)Nr8r)r!r�AttributeErrorr�r�rrr=)r&r'r~rrr�testSetRepeatedComposite(sz$MessageTest.testSetRepeatedComposite)HrLrMrNr)r2r6rJrUr[rarbrdrgrhrirrrsrtrxr{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�r�r�r�r��	bytearray�setr�r�r�r�r�r�r�r�rTr�r�r�rrrrr
rr
rrrrrrres�
$			--( #	#		
	






	
rc@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�
Proto2TestcCs�tj�}|j|jd��|j|jd��|j|jd��|jt��|jd�WdQRX|jt��|jd�WdQRX|jt��|jd�WdQRX|jd|j�|jd|j�|jd|j	j
�d|_d|_d|j	_
|j|jd��|j|jd��|j|jd��d	|_d
|_d|j	_
|j|jd��|j|jd��|j|jd��|jd�|jd�|jd�|j|jd��|j|jd��|j|jd��|jd|j�|jd|j�|jd|j	j
�dS)Nr�
optional_bool�optional_nested_message�field_doesnt_existr�r�rFr�T�)
r	r!r�r�rr�r+rrrr|r\r�)r&rrrr�testFieldPresence:sD


zProto2Test.testFieldPresencecCs
tj�}|jt��}d|_WdQRX|jt|jjd�|jjd�d|jd<|jt��d|jd<WdQRXtj�}d|_|jjd�|j�}tj�}|j	|�|j
|jd��|jd|j�|jdt
|j��|j�|j	|j��|jd|j�|jd|jd�dS)	z:Assigning an invalid enum number is not allowed in proto2.i��Nrjri@�i��t�optional_nested_enumr8)r	r!rr�rr�r�r
r,r*r�r�r+rCr�)r&r~r�r�rcZm3rrr�testAssignInvalidEnumjs*

z Proto2Test.testAssignInvalidEnumc
Cs6tj�}d|jd<|jt��d|jd<WdQRXdS)Nr�{r8)rZTestEnumMapZknown_map_fieldrr�Zunknown_map_field)r&r~rrr�testUnknownEnumMap�s
zProto2Test.testUnknownEnumMapcCstj�}|jtt|d�dS)N�
Extensions)r	r!rrr�)r&rHrrr�testExtensionsErrors�szProto2Test.testExtensionsErrorscCshtjd�}tj�}|j|�tj�}tj|�|j||�|j||j��tj	|�}|j||j��dS)Nr0)
rrr	ZTestAllExtensionsr*ZSetAllExtensionsr+r,r-r.)r&r/r0r5r1rrr�testGoldenExtensions�s



zProto2Test.testGoldenExtensionscCshtjd�}tj�}|j|�tj�}tj|�|j||�|j||j��tj	|�}|j||j��dS)Nr3)
rrr	ZTestPackedExtensionsr*ZSetAllPackedExtensionsr+r,r-r.)r&r/r0r5r1rrr�testGoldenPackedExtensions�s



z%Proto2Test.testGoldenPackedExtensionscCsNtjdd�}tj|�}tj|�}|j||�|j|jd�|jtj	|j
�dS)Nr8)r�)r	ZTestRequiredrVrWrXr+r�rrZEncodeErrorr,)r&r0rYrZrrr�testPickleIncompleteProto�s

z$Proto2Test.testPickleIncompleteProtocCs�tj�tj�tj�g}d|d_d|d_d|d_d|d_tj�}d|_d|_d|_tjj�}|jj|�|j	j|�|j
j|�|jj|�|jj|�|j
j�jj|d�|j
j�jj|d�|j
j�jj|d�|jj�jj|d�|jj�jj|d�|jj�jj|d�|j�}tj�}|j|�|j|j|�|j|j|�|j|jj|�|j|jtjj|�|jt|j�d�|jt|j�d�|jt|jtjj�d�dS)zcCheck the merge behavior when a required or optional field appears
    multiple times in the input.r8rrjruZhelloN)r	r!r�optional_int64r�ZTestParsingMergeZRepeatedFieldsGeneratorZfield1rSZfield2Zfield3Zext1Zext2Zgroup1r�r�Zgroup2r,r*r+Zrequired_all_typesZoptional_all_types�
optionalgroupZoptional_group_all_typesrZoptional_extrCZrepeated_all_types�
repeatedgroupZrepeated_ext)r&ZmessagesZmerged_message�	generator�dataZ
parsing_mergerrr�testParsingMerge�sJ








zProto2Test.testParsingMergecCs`tjddddddiddiid	dd
iddigdtjjgd
dd�}|j|tj�|jd|j�|jd|j�|jd|j�|jd|j�|jd|j	j
�|j|jtjj�|jd|jj
�|j|jd��|j|jtj��|jtjj|j�|jdt|j��|jd
|jdj
�|jd|jdj
�|jdt|j��|jtjj|jd�|jtjj|jd�|jd
|j�|jd|j�|j|jd��|jdt|j��|jd|j�tjd	d�}|jtjj|j�|jt��tjddid�WdQRX|jt��tjddid�WdQRX|jt��tjdd�WdQRX|jt��tjdd�WdQRXdS)N�d��g�r@�xr�i�r|i��BAZiXi��FOOi r)r�optional_fixed32r]�optional_bytesr$r�optional_foreign_messagerr%r��
default_int32r�r0rjrr8r#�*)rZINVALID_NESTED_FIELD�)rZINVALID_VALUE_TYPEZ
INVALID_LABEL)r�) r	r!ZBARr�r+rr.r]r/r$r�rr�r|r\r�r0�ForeignMessager,rrCr%r�r-r1r�r�r_Z
default_int64rr�r=)r&rrrr�testPythonicInit�sl






zProto2Test.testPythonicInitN)rLrMrNrrrrr r!r"r(r5rrrrr8s01rc@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"dAS)B�
Proto3TestcCs@t|�}x&|D]\}}|j|||�||=qW|ji|�dS)N)�dictr+)r&Zmap_iterZ
dict_valuer��vrrr�assertMapIterEquals+s

zProto3Test.assertMapIterEqualsc4Cs�tj�}|jt��|jd�WdQRX|jt��|jd�WdQRX|jt��|jd�WdQRX|jt��|jd�WdQRX|j|jd��|jt��|jd�WdQRX|jt��|jd�WdQRX|jt��|jd�WdQRX|jd	|j�|jd	|j�|jd
|j	�|jd|j
�|jd	|jj�d	|j_|j
|jd��d|_d
|_d|_	d|_
d|j_|jd�|jd�|jd�|jd�|jd�|jd	|j�|jd	|j�|jd
|j	�|jd|j
�|jd	|jj�dS)Nrr]r�rrrr�r�rryFr�g�������?r�Tr)r
r!rr�r�r�r+rr]r�rrr|r\r�)r&rrrrr5sL




zProto3Test.testFieldPresencecCs�tj�}d|_|jd|j�|jjd�|jd|jd�d|jd<|jd|jd�|j�}tj�}|j|�|jd|j�|jd|jd�dS)zCAssigning an unknown enum value is allowed and preserves the value.i��i��Tri��tN)r
r!rr+r�r�r,r*)r&r~rcr�rrr�testAssignUnknownEnumns

z Proto3Test.testAssignUnknownEnumcCsNtj�}|jd|jk�|jd|jk�|jd|jk�|jd|jk�|jd|jk�|jd|jk�|jd|j	k�|jd|j
k�|jd|jk�|jd|jd�|jd|jd�|jd|jd�|jd|jd�|jd	|jd�|j
t|jdt��|jd|jd�|j
t|jdt��|jd
|j	d�|jd|j
d�|jd|jd�|j
d|jk�|j
d|jk�|j
d|jk�|j
d|jk�|j
d|jk�|j
d|jk�|j
d|j	k�|j
d|j
k�|j
d|jk�|j|j	dtj�|jt��|j	dWdQRX|jt��d|j	kWdQRXdS)Nrrjr�Fr��oixrgryr�i����ll����li����ll����li����ll����l)r�TestMapr��map_int32_int32�map_int64_int64�map_uint32_uint32�map_uint64_uint64�map_int32_double�
map_bool_bool�map_string_stringZmap_int32_bytes�map_int32_enumr+r\�
isinstance�floatr�r�r�r�rr=)r&rHrrr�testScalarMapDefaults�sFz Proto3Test.testScalarMapDefaultscCs&tj�}|j|jjd��|jd|jjdd��|j|jjd��d|jd<|jd|jjd��|jd|jjd��|jt��|jjd�WdQRX|j|jjd��|jd|jjdd��|jd}|j	||jjd��t
j�dk�r|jt��|jjd�WdQRXn|jd|jjd��dS)Nr�r�rryr)rr<r�r=�getr+rr=�map_int32_foreign_messager�rr)r&rH�submsgrrr�
testMapGet�s"

zProto3Test.testMapGetc!Cs4tj�}|jdt|j��|jd|jk�d|jd<d|jd<d|jd<d|jd<d|j	d<d	|j
d
<d|jd<d
|jd
<d|j
d<d|j
d<|jg|j��|jd
t|j��|jt��d|jd<WdQRX|jd
t|j��|jt��d|jd<WdQRX|j�}tj�}|j|�|jt��d|jd<WdQRX|jt��d|jd<WdQRX|jd|jd�|jd|jd�|jd|jd�|jd|jd �|jd|j	d�|jd	|j
d
�|jd|jd�|jd
|jd
�|jd|j
d�|jd|j
d�tj�dk�r0|jdt|j��dS)!Nrr�i�rrj�"r�g333333�?gffffff
@r8�123r�Tixrz{-123: -456}i8���i����ll����ll����lli8���i����ll����ll����ll)rr<r+rCr=r�r>r?r@Zmap_int32_floatrArCrBrD�FindInitializationErrorsrr=r,r*r�rrr$)r&rHrc�msg2rrr�
testScalarMap�sP










zProto3Test.testScalarMapcCs@tj�}d|jd<d|jd<|j|j�d�|jd|j��dS)Nrryr�s
r
)rr<r=rCr+�ByteSizer,)r&rHrrr�testMapEntryAlwaysSerializeds

z'Proto3Test.testMapEntryAlwaysSerializedcCsntj�}d}|jd�}||j|<t|jj��d\}}|j||�|j||�|j|tj	�|j|tj	�dS)Nuሴ�utf8r)
rr<�encoderCr��itemsr+r�r�r�)r&rHZunicode_objZ	bytes_objr��valuerrr� testStringUnicodeConversionInMaps

z+Proto3Test.testStringUnicodeConversionInMapcCsZtj�}|jdt|j��|jd|jk�|jd|jjd
�|jdt|j��|jd|j�|jd|j�|jdt|j��|jt	��|jdWdQRX|jt
��|jd|jd<WdQRX|jdt|j��|j�}tj�}|j|�|jdt|j��|jd|j�|jd|j�|jdt|j��t
j�dk�rV|jd	tt|j���dS)
Nrr�ri�rjrMi�rri8���i8���i8���)rr<r+rCrIr�Z
get_or_creater#rr=r�r,r*rrr$)r&rHrcrOrrr�testMessageMap&s0

zProto3Test.testMessageMapcCs�tj�}d|jdj_|jd=d|jdj_|jdt|j��d|jdj_|jdt|j��|j�}tj�}|j|�ddg}x|D]}|j|=q�WdS)Nr8rj)	rr<�map_int32_all_typesrr|r+rCr,r*)r&rHrcrO�keysr�rrr�testNestedMessageMapItemDeleteOs

z)Proto3Test.testNestedMessageMapItemDeletecCsptj�}d|jd<|j�}d|jd<|j|j�|d�d|jd_|j�}d|jd_|j|j�|d�dS)Nr8��)rr<r=rQr+rIr�)r&rHr�rrr�testMapByteSize`s

zProto3Test.testMapByteSizec	Cs�tj�}d|jd<d|jd<d|jd<d|jd_d	|jd
_tj�}d|jd<d|jd
<d|jd
_d|jd
_|jd
}|j|�|jd|jd�|jd|jd�|jd|jd�|jd|jd
�|jd|jdj�|jd	|jd
j�|j	|jd
j
d��tj�dk�r(|jd|j�i}x.|jD]$}|j	||k�|j|j||<�q4W|jdd	d�|�|jd=|j	d|jk�|jd
=|j	d
|jk�tj�dk�r�|j
t��|jd=WdQRXn|j
t��|jd=WdQRXdS)NrLr��N�8r��r�r;r����7�c�Xrr��dr)r;rbry)rr<r=r>rIr�rfr�r+r�r�rrrr=�KeyError)r&rHrOZ
old_map_valueZas_dictr�rrr�
testMergeFromlsH






zProto3Test.testMergeFromc	Cs.tj�}|jtd��|jd�WdQRXdS)NzWParameter to MergeFrom\(\) must be instance of same class: expected .*TestMap got int\.r8)rr<�assertRaisesRegexr=r�)r&rHrrr�testMergeFromBadType�s
zProto3Test.testMergeFromBadTypec	Cs.tj�}|jtd��|jd�WdQRXdS)Nz[Parameter to [A-Za-z]*From\(\) must be instance of same class: expected .*TestMap got int\.r8)rr<rir=r�)r&rHrrr�testCopyFromBadType�s
zProto3Test.testCopyFromBadTypecCs�tj�}td�|jtd�<td	�|jtd�<td�|jtd�<td�|jtd
�<|j�}tj�}|j|�|j	d|jd�|j	d|jd�|j	d|jd�|j	d|jd�dS)Ni�rrjrLr�i8���i����ll����ll����lli8���i����ll����ll����ll)
rr<r�r=r>r?r@r,r*r+)r&rHrcrOrrr�testIntegerMapWithLongs�s
z"Proto3Test.testIntegerMapWithLongscCs�tj�}d|jjd<|j�}tj�}|j|�|j||�d|jjd<|j�}|j|�|j||�|jjj�|j�}|j|�|j||�dS)Ni�ri�ix)r�TestMapSubmessage�test_mapr=r,r*r+�clear)r&rHrcrOrrr�testMapAssignmentCausesPresence�s


z*Proto3Test.testMapAssignmentCausesPresencecCs�tj�}d|jjd_|j�}tj�}|j|�|j||�d|jjd_|j�}|j|�|j||�|jjdj|jjd�|j�}|j|�|j||�|jjj	�|j�}|j|�|j||�dS)Nr�r�ix)
rrmrnrIr�r,r*r+r�ro)r&rHrcrOrrr�-testMapAssignmentCausesPresenceForSubmessages�s&



z8Proto3Test.testMapAssignmentCausesPresenceForSubmessagescCs~tj�}t|j�}t|j�}d|jd<d|jd_|jt��x|D]}qDWWdQRX|jt��x|D]}qhWWdQRXdS)NrMr�r�)rr<�iterrCrIr�r�RuntimeError)r&rHZstring_string_iterZint32_foreign_iterr�rrr�testModifyMapWhileIterating�s




z&Proto3Test.testModifyMapWhileIteratingc
Cs�tj�}|jd}|j||jd�|j|tj�d|_|j�}tj�}|j	|�|j
d|jdj�|jt��tj�|jd<WdQRXdS)Nr;r�re)
rr<rIr�r�r	r4r�r,r*r+rr�)r&rHrJrcrOrrr�testSubmessageMaps

zProto3Test.testSubmessageMapcCs�tj�}x$t|jj��D]\}}|jd�qWd|jd<d|jd<d|jd<|jdt|j��dddd�}|jt|jj��|�dS)NFr9rjr�ru�)rjrur9)	rr<r�r=rUr\r+rCr9)r&rHr�r8�
matching_dictrrr�testMapIterations


zProto3Test.testMapIterationcs&tjdk�r"tj�}d|jd<d|jd<d|jd<d|jd<|j}�jdt|��tj�}|j|j���fdd	�}|t	|j
��t|j
���|t	|j��t|j���|t	|j
��t|j
����jd|jd���jd|jd
���jd|jd���jd|jd���jdt|��|j�\}}�jd||��jdt|��|j��jdt|���jt��|j�WdQRX�jd|jd���jdt|��|j|j��jdt|���jt��|j|j|j�WdQRX�jt��|jd�WdQRX�jt��|jd
d�WdQRXdS)Nrur9rjr�rwr�r�cs0�jt|�|d��jt|�|dd��dS)Nrr8)r+�nextr�)�seq�iterator)r&rr�
CheckItems9sz-Proto3Test.testPython2Map.<locals>.CheckItemsi�rr8r�)rV)ru)rvrwrr<r=r+rCr*r,r�rUrsrZr�rHr	�popitemrorrg�
setdefault�updater=)r&rHZ	map_int32rOr}r�rVr)r&r�testPython2Map-sJ



zProto3Test.testPython2MapcCsftj�}d|jd<d|jd<d|jd<d|jd<d|jd<t|jj��}t|jj��}|j||�dS)Nry�
local_init_op�trainable_variables�	variables�init_op�	summaries)rr<rCr�rUr+)r&rHZitems1Zitems2rrr�testMapItems]s




zProto3Test.testMapItemscCs~d}tj�}d|jd<d|jd<d|jd<d|jd	<d
|jd<d
|jd<d
|jd<d|jd<d|jd<|j||jdd��dS)Ns�r
init_opdr

item1er

item2fr

item3gr
item4QQr

local_init_opar
	summarieser
trainable_variablesbr
	variablescr�r�r�r�r�r�rfr��er�Zitem1�fZitem2�gZitem3ZQQZitem4T)rK)rr<rCr+r,)r&r/rHrrr�!testMapDeterministicSerializationls	








z,Proto3Test.testMapDeterministicSerializationcCsRtj�}d|jd<d|jd<d|jd<t|jj��}~dddd�}|j||�dS)Nr9rjr�rurw)rjrur9)rr<r=r�rUr9)r&rH�itrxrrr�testMapIterationClearMessage�s


z'Proto3Test.testMapIterationClearMessagecCsftjddd�d�}|jd|jd�|jd|jd�tjdtjdd�id	�}|jd|jdj�dS)
Nrjr9)r8ru)r=r8rur�)r�)rI)rr<r+r=r	r4rIr�)r&rHrrr�testMapConstruction�szProto3Test.testMapConstructioncCsdtj�}|j}d|d<d|d<d|d<|jd�|jd|j��dddd�}|jt|j��|�dS)	Nr9rjr�rurwr=r�)rjrur9)	rr<r=r�r+r,r9r�rU)r&rHZ	int32_maprxrrr�testMapValidAfterFieldCleared�s
z(Proto3Test.testMapValidAfterFieldClearedcCsLtj�}|j}d|d_|jd�|jd|j��|jdt|j	��k�dS)Nr�rjrIr�)
rr<rIr�r�r+r,r\r�rZ)r&rHZint32_foreign_messagerrr�$testMessageMapValidAfterFieldCleared�s

z/Proto3Test.testMessageMapValidAfterFieldClearedcCs|tj�}t|j�}|jd�|jt��x|D]}q.WWdQRXt|j�}|jd�|jt��x|D]}qfWWdQRXdS)Nr=rI)rr<rsr=r�rrtrI)r&rHr�r�rrr�"testMapIterInvalidatedByClearField�s





z-Proto3Test.testMapIterInvalidatedByClearFieldcCs�tj�}|jdt|j��d|jd<|jdt|j��|jt��|jd=WdQRX|jd=|jdt|j��|jt��|jd=WdQRXdS)Nrr�r9r8re� )rr<r+rCr=rrgrY)r&rHrrr�
testMapDelete�s
zProto3Test.testMapDeletecCsLtj�}|j|jtj�|j|jtj�|j|jtj�|j|jtj�dS)N)rr<r�r=r��Mapping�MutableMappingrI)r&rHrrr�testMapsAreMapping�szProto3Test.testMapsAreMappingcCsDtj�}d|jd<|j|j|j�|j|j|j�|j|jd�dS)Ni�rri8���i����)rr<r=r+rIZassertNotEqual)r&rHrrr�testMapsCompare�s
zProto3Test.testMapsComparecCs@tj�}d|jd<d|jd<d|jd_|jdt|j���dS)NrMr��@�#r�r�r)	rr<rCr=Zmap_string_foreign_messager�r+rCrN)r&rHrrr�(testMapFindInitializationErrorsSmokeTest�s


z3Proto3Test.testMapFindInitializationErrorsSmokeTestN)#rLrMrNr9rr:rGrKrPrRrWrXr[r^rhrjrkrlrprrrurvryr�r�r�r�r�r�r�r�r�r�r�r�rrrrr6(s@
90=)<0	
r6c@seZdZdd�Zdd�ZdS)�ValidTypeNamesTestcs�tt|��jd�d�d|d|f}|jt�fdd�|D��d�|f��jd�}|d
}dj|dd��}t||gd	�dS)N�'r8zRepeated%sContainerzRepeated%sFieldContainerc3s|]}�j|�VqdS)N)�endswith)r}r8)�tp_namerrr�sz:ValidTypeNamesTest.assertImportFromName.<locals>.<genexpr>z%r does end with any of %r�.)�fromlistr<r<)r$�type�splitr\�any�join�
__import__)r&rHZ	base_nameZvalid_names�parts�
class_nameZmodule_namer)r�r�assertImportFromName�s

z'ValidTypeNamesTest.assertImportFromNamecCs(tj�}|j|jd�|j|jd�dS)NZScalarZ	Composite)r	r!r�r�r�)r&r�rrr�testTypeNamesCanBeImported
sz-ValidTypeNamesTest.testTypeNamesCanBeImportedN)rLrMrNr�r�rrrrr��s
r�c@s$eZdZdd�Zdd�Zdd�ZdS)�PackedFieldTestcCs�|jjd�|jjd�|jjd�|jjd�|jjd�|jjd�|jjd�|jjd�|j	jd�|j
jd�|jjd�|jjd�|j
jd�|jjd�dS)Nr8g�?T)r�r�Zrepeated_int64Zrepeated_uint32Zrepeated_uint64Zrepeated_sint32Zrepeated_sint64Zrepeated_fixed32Zrepeated_fixed64Zrepeated_sfixed32Zrepeated_sfixed64r_r`Z
repeated_boolr�)r&rrrr�
setMessageszPackedFieldTest.setMessagecCs*tj�}|j|�d}|j||j��dS)NsH
"*2:BJRZ�?b�?jr)rr4r�r+r,)r&rr/rrr�testPackedFields"s
z PackedFieldTest.testPackedFieldscCs*tj�}|j|�d}|j||j��dS)Ns: (0=AMQ]�?a�?hp)rZTestUnpackedTypesr�r+r,)r&rr/rrr�testUnpackedFields5s
z"PackedFieldTest.testUnpackedFieldsN)rLrMrNr�r�r�rrrrr�sr�rrjrqz;explicit tests of the C++ implementation for PY27 and abovec@s0eZdZedd��Zdd�Zdd�Zdd�Zd	S)
�OversizeProtosTestcCsFd}tj�}tj�}tj||�|j|�tj|�j	|j
d��|_dS)Na�
      name: "f/f.msg2"
      package: "f"
      message_type {
        name: "msg1"
        field {
          name: "payload"
          number: 1
          label: LABEL_OPTIONAL
          type: TYPE_STRING
        }
      }
      message_type {
        name: "msg2"
        field {
          name: "field"
          number: 1
          label: LABEL_OPTIONAL
          type: TYPE_MESSAGE
          type_name: "msg1"
        }
      }
    zf.msg2)rZDescriptorPoolrZFileDescriptorProtorZParseZAddr
ZMessageFactoryZGetPrototypeZFindMessageTypeByName�	proto_cls)�clsZ	file_descZpoolZdescrrr�
setUpClassNs

zOversizeProtosTest.setUpClasscCs(|j�|_dd|jj_|jj�|_dS)Nr�ir�r8iii)r��p�fieldr�r,�p_serialized)r&rrr�setUpqs
zOversizeProtosTest.setUpcCsfddlm}|d�|j�}y|j|j�Wn4tjk
r`}z|jt|�d�WYdd}~XnXdS)Nr)�SetAllowOversizeProtosFzError parsing message)	�google.protobuf.pyext._messager�r�r*r�rr?r+r$)r&r��qr�rrr�testAssertOversizeProtovsz*OversizeProtosTest.testAssertOversizeProtocCsBddlm}|d�|j�}|j|j�|j|jjj|jj�dS)Nr)r�T)	r�r�r�r*r�r+r�r�r�)r&r�r�rrr�testSucceedOversizeProtos
z+OversizeProtosTest.testSucceedOversizeProtoN)rLrMrN�classmethodr�r�r�r�rrrrr�Is#	r��__main__)rjrq)4r��
__author__r�r-rlr�rVr�rvr@Z	unittest2Zunittest�ImportErrorr�r�Zgoogle.protobufrrr	r
rrr
rZgoogle.protobuf.internalrrrrrrrZPY3r�ZlongrrrrZBaseTestCaseZNamedParametersrrr6r�r�ZskipIfrrwr�rL�mainrrrr�<module>)s�WqX9: