Duac@s\dZdZddlZddlZddlZyddlZWnek r_ddlZnXddlm Z ddlm Z ddlm Z ddlm Z ddlm Z dd lmZdd lmZdd lmZdd lmZdd lmZddlmZdejfdYZdefdYZedkrXejndS(s%Test for google.protobuf.json_format.sjieluo@google.com (Jie Luo)iN(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#eZdZdZdZRS(cCsd|_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|jjdd |jj_ d|jj_ |jjt j|jjt j||_dS(Niil~ tl4? s-infgo! @tfootbari iilliiligV瞯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/testExtensionSerializationJsonMatchesProto3Specs     cCstj}tjddkr+d|_n!d|_|jdjd7_|jtj|dtj}|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.pyttestJsonEscapeStrings     cCs`tjdd}|jtjtj|ttjdtj}|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|jdtjd||j|jdtjd||j|jddS(Ns{"int32Value": -2.147483648e9}is{"int32Value": 1e5}is{"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|ttjdd|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|jdddS(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|jdddS(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|jdddS(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 cCstj}d}|jtjdtj||d}|jtjdtj||d}|jtjdtj||tjd krdSd }|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 cCstj}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.lAsdate 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.pyttestInvalidOneofs  cCs5tj}d}|jtjdtj||dS(Ns{"value": 1234}sDFailed to parse value field: ListValue must be in \[\] which is 1234(R RR6R R7R0(R.R-R8((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestInvalidListValues  cCs5tj}d}|jtjdtj||dS(Ns{"value": 1234}sCFailed to parse value field: Struct must be in a dict which is 1234(R RR6R R7R0(R.R-R8((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestInvalidStructs  cCstj}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}(RRR6tKeyErrorR R0R7t TypeError(R.R-R8((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestInvalidAnys$ cCstj}d|_|jdtj||jdtj|tttj}|jdtj|tt|jdtj|tttj}tj d||jd|jtj d||jd|jdS( Ni90s{ "int32Value": 12345 }s{ "int32_value": 12345 }s{ "repeatedValue": [] }s{ "repeated_value": [] }s{"int32Value": 54321}i1s{"int32_value": 12345}( R R5RR2R R1R&RRsR0(R.R-((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyttestPreservingProtoFieldNamess         cCs8tj}d|_|jdtj|dddS(Ni90s{ "int32Value": 12345 }tindenti(R R5RR2R R1(R.R-((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyt testIndents   cCsFd}i|d6}tj}tj|||j||jdS(Ni90t int32Value(R R5R RSR2R(R.texpectedtjs_dictR-((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyt testParseDicts   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.pyttestMessageToDicts     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 testJsonNames     c Cstjdtdddddddd }|jtj|d ttjitd 6dd 6d d6dd6d d6ddd tdS(NRRiRiRiRtblat sort_keyst boolValueRt3t int64Valuet uint32Valuet stringValueRi(R R5RR2R R1R@tdumps(R.R-((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyt testSortKeyss (2R;R<R>RBRCRDRPRQRURXR\R`RaRbRmRpRrRwRyR|RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR(((sM/usr/lib/python2.7/site-packages/google/protobuf/internal/json_format_test.pyR=ns`  !      (   (   !   . O -                  t__main__(t__doc__t __author__R@RR]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