ó 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.sjieluo@google.com (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ÿÿÿ•