� S�Ljc@s\dZdZddlZddlZddlZyddlZWnek r_ddlZnXddlm Z ddlm Z ddlm Z ddlm Z ddlm Z dd lmZdd lmZdd lmZdd lmZdd lmZddlmZdejfd��YZdefd��YZedkrXej�ndS(s%Test for google.protobuf.json_format.smail protected] (Jie Luo)i����N(tany_pb2(t duration_pb2(tfield_mask_pb2(t struct_pb2(t timestamp_pb2(t wrappers_pb2(tunittest_mset_pb2(t unittest_pb2(twell_known_types(t json_format(tjson_format_proto3_pb2tJsonFormatBasecBs#eZd�Zd�Zd�ZRS(cCs�d|_d|_d|_d|_td�|_d|_t|_d|_ d|_ d |j _ t j|_|jjd �|jjd �|jjd �|jjd �|jjd�|jjd�|jjd �|jjd�|jjd�|jjd�|jjtd��|jjt�|jjt�|jjd�|jjd�|jjd�|jjd�d |jj�_ d|jj�_ |jjt j�|jjt j�||_dS(Nii����l~ tl4�? s-infgo���! @tfootbari i���i�ll����i���i���l����igV瞯�protobuf_unittest.TestMessageSetExtension1.messageSetExtensions>protobuf_unittest.TestMessageSetExtension2.messageSetExtensionsZ{"messageSet": { "[%s]": { "i": 23 }, "[%s]": { "str": "foo" }}}N(RRERFRGRHRIRJRKRLR R1R2R@RA(R.R-RMRNROt ext1_textt ext2_textt golden_text((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyt/testExtensionSerializationJsonMatchesProto3Spec�s     cCs�tj�}tjddkr+d|_n!d|_|jdjd�7_|jtj|�d�tj�}|j ||�d}tj ||�|j|j d �dS( Niis& <" > \/

s & <" > \/s

sutf-8s;{ "stringValue": "&\n<\"\r>\b\t\f\\\u0001/\u2028\u2029" }u{"int32Value": "1"}i( R R5tsyst version_infoRtdecodeR2R R1R4R0R(R.R-R3R8((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestJsonEscapeString�s     cCs`tjdd�}|jtjtj|t��tjd��tj�}|j||�dS(NRR s�{"repeatedStringValue": [],"stringValue": "foo","repeatedBoolValue": [],"repeatedUint32Value": [],"repeatedInt32Value": [],"enumValue": "FOO","int32Value": 0,"floatValue": 0,"int64Value": "0","uint32Value": 0,"repeatedBytesValue": [],"repeatedUint64Value": [],"repeatedDoubleValue": [],"bytesValue": "","boolValue": false,"repeatedEnumValue": [],"uint64Value": "0","doubleValue": 0,"repeatedFloatValue": [],"repeatedInt64Value": [],"repeatedMessageValue": []}( R R5R2R@RAR R1RR4(R.R-R3((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestAlwaysSeriliazes   cCsytj�}tjd|�|j|jd�tjd|�|j|jd�tjd|�|j|jd�dS(Ns{"int32Value": -2.147483648e9}i�s{"int32Value": 1e5}i��s{"int32Value": 1.0}i(R R5R R0R2R(R.R-((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestIntegersRepresentedAsFloat-s cCs8tj�}|jtjtj|t��tjd��d|jtFailed to parse int32Value field: Couldn't parse integer: 1.5.s{"int32Value": 012345}s9Failed to load JSON: Expecting \'?,\'? delimiter: line 1.s{"int32Value": " 1 "}s@Failed to parse int32Value field: Couldn't parse integer: " 1 ".s{"int32Value": "1 "}s?Failed to parse int32Value field: Couldn't parse integer: "1 ".s${"int32Value": 12345678901234567890}sKFailed to parse int32Value field: Value out of range: 12345678901234567890.s{"uint32Value": -1}s:Failed to parse uint32Value field: Value out of range: -1.(R R5t assertRaisesR R7R0R:(R.R-R8((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestInvalidIntegerValue's         cCs|jdd�dS(Ns{"floatValue": "nan"}sPFailed to parse floatValue field: Couldn't parse float "nan", use "NaN" instead.(R:(R.((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestInvalidFloatValue?s cCs$|jdd�|jdd�dS(Ns{"bytesValue": "AQI"}s4Failed to parse bytesValue field: Incorrect padding.s{"bytesValue": "AQI*"}(R:(R.((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestInvalidBytesValueDs  cCs|jdd�dS(Ns{"repeatedInt32Value": 12345}skFailed to parse repeatedInt32Value field: repeated field repeatedInt32Value must be in \[\] which is 12345.(R:(R.((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestInvalidRepeatedJs cCs�tj�}d}|jtjdtj||�d}|jtjdtj||�d}|jtjdtj||�tjd kr�dSd }|jtjd tj||�d }|jtjd tj||�dS(Ns!{"int32Map": {"null": 2, "2": 3}}s/Failed to parse int32Map field: invalid literals{"int32Map": {1: 2, "2": 3}}sQFailed to load JSON: Expecting property name( enclosed in double quotes)?: line 1s{"boolMap": {"null": 1}}sDFailed to parse boolMap field: Expected "true" or "false", not null.iis${"stringMap": {"a": 3, "\u0061": 2}}s$Failed to load JSON: duplicate key as{"stringMap": 0}sSFailed to parse stringMap field: Map field string_map must be in a dict which is 0.(ii(R tTestMapR6R R7R0R]R^(R.R-R8((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestInvalidMapOs8 cCs�tj�}d}|jtjdtj||�d}|jtjdtj||�d}|jtjdtj||�d}|jtjdtj||�d |j_|jt d tj |�dS( Ns%{"value": "10000-01-01T00:00:00.00Z"}sKtime data '10000-01-01T00:00:00' does not match format '%Y-%m-%dT%H:%M:%S'.s/{"value": "1970-01-01T00:00:00.0123456789012Z"}s2nanos 0123456789012 more than 9 fractional digits.s&{"value": "1972-01-01T01:00:00.01+08"}s$Invalid timezone offset value: \+08.s!{"value": "0000-01-01T00:00:00Z"}s7Failed to parse value field: year (0 )?is out of range.l�A��sdate value out of range( R RsR6R R7R0RRRtt OverflowErrorR1(R.R-R8((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestInvalidTimestampos4  cCs5tj�}d}|jtjdtj||�dS(Ns/{"oneofInt32Value": 1, "oneofStringValue": "2"}sTMessage type "proto3.TestOneof" should not have multiple "oneof_value" oneof fields.(R RnR6R R7R0(R.R-R8((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestInvalidOneof�s  cCs5tj�}d}|jtjdtj||�dS(Ns{"value": 1234}sDFailed to parse value field: ListValue must be in \[\] which is 1234(R R�R6R R7R0(R.R-R8((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestInvalidListValue�s  cCs5tj�}d}|jtjdtj||�dS(Ns{"value": 1234}sCFailed to parse value field: Struct must be in a dict which is 1234(R R�R6R R7R0(R.R-R8((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestInvalidStruct�s  cCs�tj�}d}|jtdtj||�d}|jtjdtj||�d}|jtdtj||�d}tj||�dS(Ns;{"@type": "type.googleapis.com/google.protobuf.Int32Value"}Rs{"value": 1234}s*@type is missing when parsing any message.s?{"@type": "type.googleapis.com/MessageNotExist", "value": 1234}sQCan not find message descriptor by type_url: type.googleapis.com/MessageNotExist.sN{"@type": "incorrect.googleapis.com/google.protobuf.Int32Value","value": 1234}(RR�R6tKeyErrorR R0R7t TypeError(R.R-R8((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestInvalidAny�s$ cCs�tj�}d|_|jdtj|��|jdtj|tt��tj�}|jdtj|tt��|jdtj|tt��tj�}tj d|�|jd|j�tj d|�|jd|j�dS( Ni90s{ "int32Value": 12345 }s{ "int32_value": 12345 }s{ "repeatedValue": [] }s{ "repeated_value": [] }s{"int32Value": 54321}i1�s{"int32_value": 12345}( R R5RR2R R1R&RRsR0(R.R-((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestPreservingProtoFieldNames�s         cCs8tj�}d|_|jdtj|dd��dS(Ni90s{ "int32Value": 12345 }tindenti(R R5RR2R R1(R.R-((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyt testIndent�s   cCsFd}i|d6}tj�}tj||�|j||j�dS(Ni90t int32Value(R R5R RSR2R(R.texpectedtjs_dictR-((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyt testParseDict�s   cCs?tj�}d|_idd6}|j|tj|��dS(Ni90R�(R R5RR2R RR(R.R-R�((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestMessageToDict�s     cCsNtj�}d|_|jdtj|��tj�}|j||�dS(Ni90s{ "@value": 12345 }(R tTestCustomJsonNameRR2R R1R4(R.R-R3((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyt testJsonName�s     c Cs�tjdtdddddddd �}|jtj|d t�tjitd 6dd 6d d6dd6d d6ddd t��dS(NRRiRiRiRtblat sort_keyst boolValueR�t3t int64Valuet uint32Valuet stringValueR�i(R R5RR2R R1R@tdumps(R.R-((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyt testSortKeys�s (2R;R<R>RBRCRDRPRQRURXR\R`RaRbRmRpRrRwRyR|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�R�R�R�(((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyR=ns`  !      (   (   !   . O -                  t__main__(t__doc__t __author__R@R�R]t unittest2tunittestt ImportErrortgoogle.protobufRRRRRRRRtgoogle.protobuf.internalRR tgoogle.protobuf.utilR tTestCaseR R=R;tmain(((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyt s4    4����