� S�Ljc@s�dZdZddlZddlZddlZddlZddlZddlZddlZddl Z yddl Z Wne k r�ddl Z nXye Wnek r�d�Z nXddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZej r�e!Z"nd�Z#d�Z$d�Z%d�Z&ej'Z'ej(defdef�de'fd��Y�Z)de'fd��YZ*de'fd��YZ+d e'fd!��YZ,d"e'fd#��YZ-e j.ej/�d$kp�ej0d%d&fkd'�d(e'fd)��Y�Z1e2d*kr�e j3�ndS(+s�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. s![email protected] (Gregory P. Smith)i����NcCs||k||kS(N((txty((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt>t(tmap_proto2_unittest_pb2(tmap_unittest_pb2(t unittest_pb2(tunittest_proto3_arena_pb2(tdescriptor_pb2(tdescriptor_pool(tmessage_factory(t text_format(tapi_implementation(tencoder(tpacked_field_test_pb2(t test_util(ttesting_refleaks(tmessage(t_parameterizedcCs ||kS(N((tval((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pytisnanVscCst|� ot|d�S(Ni(R(R((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pytisinfYscCst|�o|dkS(Ni(R(R((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pytIsPosInf\scCst|�o|dkS(Ni(R(R((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pytIsNegInf^st_proto2t_proto3t MessageTestc Bs�eZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z d �Z d �Z d �Z d �Zd �Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d �Z"d!�Z#d"�Z$d#�Z%d$�Z&d%�Z'd&�Z(d'�Z)d(�Z*d)�Z+d*�Z,d+�Z-d,�Z.d-�Z/dFe1d.d/d0d1e2�gie3�g Z4d2�Z5d3�Z6d4�Z7d5�Z8d6�Z9d7�Z:d8�Z;d9e<fd:��YZ=d;�Z>d<�Z?d=�Z@d>�ZAd?�ZBd@�ZCdA�ZDdB�ZEdC�ZFdD�ZGdE�ZHRS(GcCsvtj�dkr"|jd�ntjd�}|jt��}|jj|�WdQX|j dt |j ��dS(Ntpythons�Skipping testBadUtf8String, currently only the python api implementation raises UnicodeDecodeError when a string field contains bad utf-8.tbad_utf8_stringsTestAllTypes.optional_string( R tTypetskipTestRtGoldenFileDatat assertRaisestUnicodeDecodeErrort TestAllTypest FromStringtassertIntstrt exception(tselftmessage_modulet bad_utf8_datatcontext((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestBadUtf8Stringjs cCs�|tkrtjd�}ntjd�}|j�}|j|�|tkretj||�n|j||j��tj |�}|j||j��dS(Nt golden_message_oneof_implementedtgolden_message_proto3( RRRR"tParseFromStringtExpectAllFieldsSett assertEqualtSerializeToStringtcopytdeepcopy(R'R(t golden_datatgolden_messaget golden_copy((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestGoldenMessagets     cCs�tjd�}|j�}|j|�|j�}tj|�|j||�|j||j��tj|�}|j||j��dS(Ntgolden_packed_fields_message( RRtTestPackedTypesR.tSetAllPackedFieldsR0R1R2R3(R'R(R4R5tall_setR6((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestGoldenPackedMessage�s    c Cs�|j�}|jt|jd�|jt|jd�tjdd�}tj�dkr�|jt j ��}|j|�WdQX|j dt |j ��nRtjdt��>}tjd�|j|�|j d t |d j ��WdQXdS( Nit0iiRsUnexpected end-group tag.trecordtalwayss4Unexpected end-group tag: Not all data was convertedi����(R"R t TypeErrorR#t ExceptionR tTagBytesR RRt DecodeErrorR0R%R&twarningstcatch_warningstTruet simplefilter(R'R(tmsgtend_tagR*tw((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestParseErrors�s    cs�d}|j�}|jjddddg�|j||jdd��|j||jdt��|j||jdt��dtfd��Y�d t f�fd ��Y}|j ���|jd|��WdQXdS( Ns5� One string� Two string� Red string� Blue strings One strings Two strings Red strings Blue stringt deterministict BadArgErrorcBseZRS((t__name__t __module__(((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyRM�stBadArgcs&eZ�fd�Z�fd�ZRS(cs ���dS(N((R'(RM(sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt __nonzero__�scs ���dS(N((R'(RM(sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt__bool__�s(RNRORQRR((RM(sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyRP�s( R"trepeated_stringtextendR0R1tNonetFalseRFRAtobjectR (R'R(R4R5RP((RMsI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestDeterminismParameters�s"      cCsZtjd�}|j�}|j|�tj|�}tj|�}|j||�dS(NR5(RRR"R.tpickletdumpstloadsR0(R'R(R4R5tpickled_messagetunpickled_message((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestPickleSupport�s   cCs�|tkrd}nd}|j�}|j|�|jt|j��|jt|j��|jt|jd��|jt|jd��|j ||j ��dS(Ns]�a�����s ]�a�����i( RR"R.t assertTrueRtoptional_floattoptional_doubletrepeated_floattrepeated_doubleR0R1(R'R(R4R5((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestPositiveInfinity�s    cCs�|tkrd}nd}|j�}|j|�|jt|j��|jt|j��|jt|jd��|jt|jd��|j ||j ��dS(Ns]��a��������s ]��a��������i( RR"R.R_RR`RaRbRcR0R1(R'R(R4R5((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestNegativeInfinity�s    cCsd}|j�}|j|�|jt|j��|jt|j��|jt|jd��|jt|jd��|j�}|j�}|j|�|jt|j��|jt|j��|jt|jd��|jt|jd��dS(Ns]�a�����i( R"R.R_RR`RaRbRcR1(R'R(R4R5t serializedR((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestNotANumber�s     cCsmd}|j�}|j|�|jt|jd��|jt|jd��|j||j��dS(Ns����i(R9R.R_Rt packed_floatt packed_doubleR0R1(R'R(R4R5((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestPositiveInfinityPackeds   cCsmd}|j�}|j|�|jt|jd��|jt|jd��|j||j��dS(Ns������i(R9R.R_RRhRiR0R1(R'R(R4R5((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestNegativeInfinityPackeds   cCs�d}|j�}|j|�|jt|jd��|jt|jd��|j�}|j�}|j|�|jt|jd��|jt|jd��dS(Ns����i(R9R.R_RRhRiR1(R'R(R4R5RfR((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestNotANumberPacked%s     cCs�|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(Niig�?i����(R"tmathtpowR`R.R1R_(R'R(RtkMostPosExponentNoSigBitstkMostPosExponentOneSigBittkMostNegExponentNoSigBitstkMostNegExponentOneSigBit((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestExtremeFloatValues3s:         cCs�|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(Nii�g�?i���(R"RmRnRaR.R1R_(R'R(RRoRpRqRr((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestExtremeDoubleValues`s:         cCs/|j�}d|_|jt|�d�dS(Ng@soptional_float: 2.0 (R"R`R0R%(R'R(R((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestFloatPrinting�s  cCsW|j�}d|_tjdkr=|jt|�d�n|jt|�d�dS(Ng^!�7ݚ�?is%optional_double: 0.12345678912345678 s optional_double: 0.123456789123 (i(R"Ratsyst version_infoR0R%(R'R(R((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestHighPrecisionFloatPrinting�s   cCsR|j�}tj|�|j�}|j|j��|jt|�d�dS(NR(R"RtSetAllNonLazyFieldstTestEmptyMessageR.R1R0R%(R'R(t populatedtempty((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestUnknownFieldPrinting�s    cCs|j�}|jjdd�|jjdd�|jjdd�|jjdd�|jddddgg|jD]}|j^qw�|jddddggt|j�D]}|j^q��|jddddgg|jddd�D]}|j^q��dS(Ntbbiiiii����(R"trepeated_nested_messagetaddR0R~treversed(R'R(RHtm((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt testRepeatedNestedFieldIteration�s  &cCs�|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�td d 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(s7Check some different types with the default comparator.iiiig�������?g�������?g333333�?tatctbuaubucN( R"trepeated_int32tappendtsortR0R%RbtassertAlmostEqualRStrepeated_bytes(R'R(R((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt0testSortingRepeatedScalarFieldsDefaultComparator�s@  (  ( cCs |j�}|jjd�|jjd�|jjd�|jjdt�|j|jdd�|j|jdd�|j|jdd�|jjd�|jjd �|jjd �|jjdt�|j|jdd �|j|jdd �|j|jdd�d S( s2Check some different types with custom comparator.i����i����i����tkeyiiitaaaR~R�N(R"R�R�R�tabsR0RStlen(R'R(R((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt/testSortingRepeatedScalarFieldsCustomComparator�s cCsM|j�}d|jj�_d|jj�_d|jj�_d|jj�_d|jj�_d|jj�_|jjdtjd��|j|jd jd�|j|jdjd�|j|jdjd�|j|jdjd�|j|jdjd�|j|jdjd�|jt|j�d �d S( sECheck passing a custom comparator to sort a repeated composite field.iiiiiiR�R~is0[bb: 1 , bb: 2 , bb: 3 , bb: 4 , bb: 5 , bb: 6 ]N( R"RR�R~R�toperatort attrgetterR0R%(R'R(R((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt2testSortingRepeatedCompositeFieldsCustomComparator�s  cCsC|j�}d|jj�_d|jj�_d|jj�_d|jj�_d|jj�_d|jj�_d|jj�_|jjdd ��|jdddddddgg|jD]}|j^q��|j�}|j�|j|�|jdddddddgg|jD]}|j^q)�d S( sECheck passing a custom comparator to sort a repeated composite field.iii i!i ii R�cSs |jdS(Ni (R~(tz((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyR RN( R"RR�R~R�R0R1tCleartMergeFromString(R'R(Rtntpb((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt(testSortingRepeatedCompositeFieldsStable�s$     cCs�|j�}tjd�}d�}d|jj�_d|jj�_d|jj�_d|jj�_d|jj�_d|jj�_|jjd |�|jg|jD]}|j^q�ddddddg�|jjd |d t�|jg|jD]}|j^qddddddg�t j dkrEd S|jjd |�|jg|jD]}|j^qhddddddg�|jjd |d t�|jg|jD]}|j^q�ddddddg�d S(sECheck sorting a repeated composite field using list.sort() arguments.R~cSst|j|j�S(N(tcmpR~(R�R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyRRiiiiiiR�treverseNt sort_functionR�(i( R"R�R�RR�R~R�R0RFRvRw(R'R(Rtget_bbtcmp_bbtk((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt'testRepeatedCompositeFieldSortArgumentss.  """"cCsf|j�}|jjd�|jjd�|jjd�|jjdt�|jt|j�dddg�|jjdtdt�|jt|j�dddg�tj dkr7d�}|jjd|�|jt|j�dddg�|jjd |dt�|jt|j�dddg�n|j jd �|j jd �|j jd �|j jdt �|jt|j �d d d g�|j jdt dt�|jt|j �d d d g�tj dkrbd �}|j jd|�|jt|j �d d d g�|j jd |dt�|jt|j �d d d g�ndS(s9Check sorting a scalar field using list.sort() arguments.i����i����i����R�R�icSstt|�t|��S(N(R�R�(R�R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyR>RR�R�R�R~R�cSstt|�t|��S(N(R�R�(R�R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyRLRN(i(i( R"R�R�R�R�R0tlistRFRvRwRSR�(R'R(Rtabs_cmptlen_cmp((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt$testRepeatedScalarFieldSortArguments2s6 "" "%"" "cCs�|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|j�WdQXdS(Niiii(i( R"R�R�RR�R~RvRwR0R�R R@(R'R(tm1tm2t_((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestRepeatedFieldsComparableRs2   %cCs<|j�}|j|jtj�|j|jtj�dS(N(R"tassertIsInstanceR�t collectionstMutableSequenceR(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestRepeatedFieldsAreSequencesus  cCsV|j�}|jt��t|j�WdQX|jt��t|j�WdQXdS(N(R"R R@thashR�R(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestRepeatedFieldsNotHashable{s  cCs9|j�}|jjjg�|j|jd��dS(Ntpayload(tNestedTestAllTypesR�R�RTR_tHasField(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt$testRepeatedFieldInsideNestedMessage�s cCs't||�|j|j|��dS(s�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(tgetattrt assertFalseR�(R'RHt attribute((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pytensureNestedMessageExists�s cCs<|j�}|jt|jd�|jt|jd�dS(Ntno_such_oneof_fieldi(R"R t ValueErrort WhichOneofRA(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt testOneofGetCaseNonexistingField�s cCs�|j�}|jd|jd��|j|jd��d|_|jd|jd��|j|jd��|j|jd��d|_ |jd|jd��|j|jd��|j|jd��dS(Nt oneof_fieldt oneof_uint32it oneof_stringR( R"tassertIsRUR�R�R�R�R0R_R�(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestOneofDefaultValues�s   cCs�|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�i R�ufooR�toneof_nested_messageR~t oneof_bytes( R"R�RUR�R�R0R_R�R�R�R�R~R�(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestOneofSemantics�s2      cCsU|j�}d|_|j|d�|jd|jd��|jd|j�dS(Ni R�R�R�(R"R�R�R0R�(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt!testOneofCompositeFieldReadAccess�s   cCs|j�}|jd|jd��|tkrJ|j|jd��nd|_|jd|jd��|tkr�|j |jd��nd|_ |jd|jd��|j d�|jd|jd��|tkr�|j|jd��ndS(NR�i R�R~R�( R"R�RUR�RR�R�R�R0R_R�t ClearField(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestOneofWhichOneof�s       cCsz|j�}d|_|jd�|tkrG|j|jd��n|j|jd��|jd|jd��dS(Ni R�R�( R"R�R�RR�R�R�RUR�(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestOneofClearField�s    cCsz|j�}d|_|jd�|tkrG|j|jd��n|j|jd��|jd|jd��dS(Ni R�R�( R"R�R�RR�R�R�RUR�(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestOneofClearSetField�s    cCs�|j�}d|_|j|d�|jd�|jd|j�|tkrj|j|jd��n|j|jd��|jd|jd��dS(Ni R�R�R�( R"R�R�R�R0RR_R�R�(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestOneofClearUnsetField�s    cCsQ|j�}d|_|j�}|j|j��|jd|jd��dS(Ni R�R�(R"R�R.R1R0R�(R'R(R�R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestOneofDeserializes    cCsK|j�}d|_|j�}|j|�|jd|jd��dS(Ni R�R�(R"R�tCopyFromR0R�(R'R(R�R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestOneofCopyFroms     cCs�|j�}d|j_|j�}d|j_d|jj_|j|�|jd|jjd��|jd|jjjd��dS(Ni R~R�R�R�(R�R�R�R�tchildt MergeFromR0R�(R'R(R�R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestOneofNestedMergeFroms     cCs�|j�}d|jj_d|jjj_|j�}d|j_|j|�|jd|jjd��|jd|jjjd��dS(Ni i i R�R�( R�R�R�R~R�R�R�R0R�(R'R(R�R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestOneofMessageMergeFroms      cCs8|jd|jj��}|jd|jd��dS(NR�R�(R"t NestedMessageR0R�(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestOneofNestedMessageInit$s cCs[|j�}d|_|j�|j|jd��d|_|jd|jd��dS(Ni R�R~R�(R"R�R�t assertIsNoneR�R�R0(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestOneofClear)s     cCs5|j�}td�|_|j|jtj�dS(smAssigning a byte string to a string field should result in the value being converted to a Unicode string.RN(R"R%toptional_stringR�tsixt text_type(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt"testAssignByteStringToUnicodeField1s cCs�|j�}|jjd�|jtd�tt|j��!}|jt|j�t|��d|jj�_|jtd�tt|j��!}|jt|j�t|��dS(s|It should be possible to use long-valued indicies in slices This didn't used to work in the v2 C++ implementation. iiiN( R"R�R�tlongR�R0RR�R~(R'R(R�tsl((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestLongValuedSlice8s %%c Cs�|j�}|jt��'}|jjd�td�D��WdQX|jt��'}|jjd�td�D��WdQXdS(s5This didn't use to work in the v2 C++ implementation.css|] }tVqdS(N(R�(t.0ti((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pys Msi Ncss|] }tVqdS(N(R�(R�R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pys Ps(R"R t NameErrorR�RTtrangetrepeated_nested_enum(R'R(R�R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt$testExtendShouldNotSwallowExceptionsIs  & igRucCs}|j�}|jg|j�x4tjD])}|jj|�|jg|j�q)W|jjg�|jg|j�dS(s,Test no-ops extending repeated int32 fields.N(R"tassertSequenceEqualR�Rt FALSY_VALUESRT(R'R(R�t falsy_value((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestExtendInt32WithNothingTs cCs}|j�}|jg|j�x4tjD])}|jj|�|jg|j�q)W|jjg�|jg|j�dS(s,Test no-ops extending repeated float fields.N(R"R�RbRR�RT(R'R(R�R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestExtendFloatWithNothingas cCs}|j�}|jg|j�x4tjD])}|jj|�|jg|j�q)W|jjg�|jg|j�dS(s-Test no-ops extending repeated string fields.N(R"R�RSRR�RT(R'R(R�R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestExtendStringWithNothingns cCs�|j�}|jg|j�|jjdg�|jdg|j�|jjddg�|jdddg|j�|jjddg�|jdddddg|j�dS(s7Test extending repeated int32 fields with python lists.iiiiiN(R"R�R�RT(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestExtendInt32WithPythonList{s cCs�|j�}|jg|j�|jjdg�|jdg|j�|jjddg�|jdddg|j�|jjddg�|jdddddg|j�dS(s7Test extending repeated float fields with python lists.gg�?g@g@g@N(R"R�RbRT(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestExtendFloatWithPythonList�s cCs�|j�}|jg|j�|jjdg�|jdg|j�|jjddg�|jdddg|j�|jjddg�|jdddddg|j�dS(s8Test extending repeated string fields with python lists.Rt11t22t33t44N(R"R�RSRT(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestExtendStringWithPythonList�s cCsO|j�}|jg|j�|jjd�|jdddg|j�dS(sDTest extending repeated string fields with characters from a string.tabcR�R�R�N(R"R�RSRT(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestExtendStringWithString�s t TestIterablecBs5eZdZdd�Zd�Zd�Zd�ZRS(s�This iterable object mimics the behavior of numpy.array. __nonzero__ fails for length > 1, and returns bool(item[0]) for length == 1. cCs|p g|_dS(N(t_list(R'tvalues((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt__init__�scCsLt|j�}|dkrtS|dkr<t|jd�Std��dS(NiisTruth value is ambiguous.(R�R�RVtboolR�(R'tsize((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyRQ�s   cCs t|j�S(N(R�R�(R'((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt__len__�scCs |jj�S(N(R�t__iter__(R'((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyR��sN(RNROt__doc__RUR�RQR�R�(((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyR��s    cCs�|j�}|jg|j�|jjtjg��|jg|j�|jjtjdg��|jdg|j�|jjtjddg��|jdddg|j�|jjtjddg��|jdddddg|j�dS(s3Test extending repeated int32 fields with iterable.iiiiiN(R"R�R�RTRR�(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestExtendInt32WithIterable�s cCs�|j�}|jg|j�|jjtjg��|jg|j�|jjtjdg��|jdg|j�|jjtjddg��|jdddg|j�|jjtjddg��|jdddddg|j�dS(s3Test extending repeated float fields with iterable.gg�?g@g@g@N(R"R�RbRTRR�(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestExtendFloatWithIterable�s cCs�|j�}|jg|j�|jjtjg��|jg|j�|jjtjdg��|jdg|j�|jjtjddg��|jdddg|j�|jjtjddg��|jdddddg|j�dS(s4Test extending repeated string fields with iterable.Rt1t2t3t4N(R"R�RSRTRR�(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestExtendStringWithIterable�s cCsitj�dks$tj�dkr(dS|j�}|jtj��}tj|jtj �WdQXdS(Ntcppi( R RtVersionR"R RYt PickleErrorRZR�tHIGHEST_PROTOCOL(R'R(R�R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt!testPickleRepeatedScalarContainer�s  cCs|j�}|jj�dS(s?Exercise a scenario that has led to segfaults in the past. N(R"RR�(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt'testSortEmptyRepeatedCompositeContainer�s cCs5|j�}|jt��}|jd�WdQXdS(sBUsing HasField on a repeated field should raise an exception. R�N(R"R R�R�(R'R(R�R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestHasFieldOnRepeatedField�s cCs�|j�}|jt��}|jj�WdQX|jjtd��|jd|jj��|jd|jjd��|jd|jjd��|jddg|j�dS(Niiiiii(R"R t IndexErrorR�tpopRTR�R0(R'R(R�R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestRepeatedScalarFieldPop�s cCs|j�}|jt��}|jj�WdQX|jt��}|jjd�WdQXx,td�D]}|jj�}||_qfW|j d|jj�j�|j d|jjd�j�|j d|jjd�j�|j ddgg|jD]}|j^q��dS(NR=iiiiii( R"R RRR R@R�R�R~R0(R'R(R�R�R�R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestRepeatedCompositeFieldPops  cCs~|j�}x?td�D]1}|jj||�|jj�}||_qW|j|j|j�|j|j|j�dS(Ni( R"R�R�tinsertRR�R~R�R0(R'R(R�R�R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestRepeatedCompareWithSelfs  cCsM|j�}|jj�}|j}|jj�}|j|jjd�dS(swA case that lead to a segfault when a message detached from its parent container has itself a child container. iN(R�trepeated_childR�R�R0R�toptional_int32(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestReleasedNestedMessagess   cCs�|j�}|jt��g|_WdQX|jjd�tj�dkro|jt��g|_WdQXn|jt��g|_WdQXdS(NiR(R"R tAttributeErrorR�R�R RR@(R'R(R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestSetRepeatedComposite(s N(IRNROR+R7R<RKRXR^RdReRgRjRkRlRsRtRuRxR}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�RURVt bytearraytsetR�R�R�R�R�R�R�R�RWR�R�R�RRRRR R R RR(((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyRes�   $     - -     (     #      #         *      t Proto2TestcBsYeZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z RS( cCs\tj�}|j|jd��|j|jd��|j|jd��|jt��|jd�WdQX|jt��|jd�WdQX|jt��|jd�WdQX|jd|j�|jt|j �|jd|j j �d|_t|_ d|j _ |j |jd��|j |jd��|j |jd��d|_t |_ d |j _ |j |jd��|j |jd��|j |jd��|jd�|jd�|jd�|j|jd��|j|jd��|j|jd��|jd|j�|jt|j �|jd|j j �dS( NRt optional_booltoptional_nested_messagetfield_doesnt_existR�Riii(RR"R�R�R R�R0RRVRRR~R_RFR�(R'R((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestFieldPresence:sD          cCs]tj�}|jt��}d|_WdQX|jt|jjd�|jjd�d|jd<|jt��d|jdss%r does end with any of %rt.i����tfromlist(R%ttypetsplitR_tanytjoint __import__(R'RHt base_namet valid_namestpartst class_namet module_name((R�sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pytassertImportFromName�s  cCs6tj�}|j|jd�|j|jd�dS(NtScalart Composite(RR"R�R�R(R'R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestTypeNamesCanBeImported s (RNROR�R�(((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyR��s tPackedFieldTestcBs#eZd�Zd�Zd�ZRS(cCs�|jjd�|jjd�|jjd�|jjd�|jjd�|jjd�|jjd�|jjd�|j jd�|j jd�|j jd�|j jd�|j jt�|jjd�dS(Nig�?(R�R�trepeated_int64trepeated_uint32trepeated_uint64trepeated_sint32trepeated_sint64trepeated_fixed32trepeated_fixed64trepeated_sfixed32trepeated_sfixed64RbRct repeated_boolRFR�(R'R((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt setMessagescCs9tj�}|j|�d}|j||j��dS(NsH "*2:BJRZ�?b�?jr(RR9R�R0R1(R'RR4((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestPackedFields"s  cCs9tj�}|j|�d}|j||j��dS(Ns: (0=AMQ]�?a�?hp(RtTestUnpackedTypesR�R0R1(R'RR4((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestUnpackedFields5s  (RNROR�R�R�(((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyR�s  Riis;explicit tests of the C++ implementation for PY27 and abovetOversizeProtosTestcBs2eZed��Zd�Zd�Zd�ZRS(cCscd}tj�}tj�}tj||�|j|�tj|�j |j d��|_ dS(Ns� 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" } } sf.msg2( R tDescriptorPoolRtFileDescriptorProtoR tParsetAddR tMessageFactoryt GetPrototypetFindMessageTypeByNamet proto_cls(tclst file_desctpooltdesc((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt setUpClassNs   cCs8|j�|_dd|jj_|jj�|_dS(NR�ii@iiii(R�tptfieldR�R1t p_serialized(R'((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pytsetUpqscCsmddlm}|t�|j�}y|j|j�Wn,tjk rh}|jt |�d�nXdS(Ni����(tSetAllowOversizeProtossError parsing message( tgoogle.protobuf.pyext._messageR�RVR�R.R�RRCR0R%(R'R�tqR�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestAssertOversizeProtovs  cCsYddlm}|t�|j�}|j|j�|j|jjj |jj �dS(Ni����(R�( R�R�RFR�R.R�R0R�R�R�(R'R�R�((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyttestSucceedOversizeProtos   (RNROt classmethodR�R�R�R�(((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyR�Is#  t__main__(4R�t __author__R�R2RmR�RYR�RvRDt unittest2tunittestt ImportErrorR�R�tgoogle.protobufRRRRRR R R tgoogle.protobuf.internalR R RRRRRtPY3tintR�RRRRt BaseTestCasetNamedParametersRRRRR�R�tskipIfRRwR�RNtmain(((sI/usr/lib/python2.7/site-packages/google/protobuf/internal/message_test.pyt)st                   ��������9 :