3 SÉLjÙ¡ã @sdZdZddlZddlZddlZy ddlZWnek rHddlZYnXddlm Z ddlm Z ddlm Z ddlm Z ddlm Z dd lmZdd lmZdd lmZdd lmZdd lmZddlmZGdd„dejƒZGdd„deƒZedk�rejƒdS)z%Test for google.protobuf.json_format.zjieluo@google.com (Jie Luo)éN)Úany_pb2)Ú duration_pb2)Úfield_mask_pb2)Ú struct_pb2)Ú timestamp_pb2)Ú wrappers_pb2)Úunittest_mset_pb2)Ú unittest_pb2)Úwell_known_types)Ú json_format)Újson_format_proto3_pb2c@s$eZdZdd„Zdd„Zdd„ZdS)ÚJsonFormatBasecCsXd|_d|_d|_d|_tdƒ|_d|_d|_d|_d|_ d |j _ t j |_|jjd ƒ|jjdƒ|jjd ƒ|jjdƒ|jjd ƒ|jjdƒ|jjd ƒ|jjdƒ|jjdƒ|jjdƒ|jjtdƒƒ|jjdƒ|jjdƒ|jjdƒ|jjdƒ|jjdƒ|jjdƒd |jjƒ_ d|jjƒ_ |jjt jƒ|jjt j ƒ||_dS)Nél~ tl4¸? z-infgoƒÀÊ! @TÚfoosbaré iÿÿÿlliÿÿÿiÿÿÿlÿÿÿÿrgV瞯Ò<ÚinfFzFew symbols!#$,;Úbarsfooé iìÿÿÿi€lüÿÿÿ)Ú int32_valueÚ int64_valueÚ uint32_valueÚ uint64_valueÚfloatÚ float_valueÚ double_valueÚ bool_valueÚ string_valueÚ bytes_valueÚ message_valueÚvaluer ZBARÚ enum_valueÚrepeated_int32_valueÚappendZrepeated_int64_valueZrepeated_uint32_valueZrepeated_uint64_valueZrepeated_float_valueZrepeated_double_valueÚrepeated_bool_valueZrepeated_string_valueZrepeated_bytes_valueZrepeated_message_valueÚaddZrepeated_enum_valueZFOOÚmessage)Úselfr%©r'ú&/usr/lib/python3.6/json_format_test.pyÚ FillAllFields<sB                   zJsonFormatBase.FillAllFieldscCs"tjtj|ƒ|ƒ|j||ƒdS)N)r ÚParseÚ MessageToJsonÚ assertEqual)r&r%Úparsed_messager'r'r(ÚCheckParseBackas zJsonFormatBase.CheckParseBackcCs"tjƒ}|jtj|tj||ƒdS)N)r Ú TestMessageÚassertRaisesRegexpr Ú ParseErrorr*)r&ÚtextZ error_messager%r'r'r(Ú CheckErrorfs zJsonFormatBase.CheckErrorN)Ú__name__Ú __module__Ú __qualname__r)r.r3r'r'r'r(r :s%r c@sŒeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„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^„Z1d_d`„Z2daS)bÚJsonFormatTestcCs2tjƒ}|jtj|ƒdƒtjƒ}|j||ƒdS)Nz{})r r/r,r r+r.)r&r%r-r'r'r(ÚtestEmptyMessageToJsonps  z%JsonFormatTest.testEmptyMessageToJsoncCsHtjdddgd�}|jtjtj|ƒƒtjdƒƒtjƒ}|j||ƒdS)NZtestéYé)rr!z6{"stringValue": "test", "repeatedInt32Value": [89, 4]})r r/r,ÚjsonÚloadsr r+r.)r&r%r-r'r'r(ÚtestPartialMessageToJsonws  z'JsonFormatTest.testPartialMessageToJsoncCsXtjƒ}d}|j|ƒ|jtjtj|ƒƒtj|ƒƒtjƒ}tj||ƒ|j||ƒdS)Na÷{"int32Value": 20, "int64Value": "-20", "uint32Value": 3120987654,"uint64Value": "12345678900","floatValue": "-Infinity","doubleValue": 3.1415,"boolValue": true,"stringValue": "foo","bytesValue": "YmFy","messageValue": {"value": 10},"enumValue": "BAR","repeatedInt32Value": [2147483647, -2147483648],"repeatedInt64Value": ["9007199254740992", "-9007199254740992"],"repeatedUint32Value": [268435455, 134217727],"repeatedUint64Value": ["9007199254740992", "9007199254740991"],"repeatedFloatValue": [0],"repeatedDoubleValue": [1e-15, "Infinity"],"repeatedBoolValue": [true, false],"repeatedStringValue": ["Few symbols!#$,;", "bar"],"repeatedBytesValue": ["Zm9v", "YmFy"],"repeatedMessageValue": [{"value": 10}, {"value": 11}],"repeatedEnumValue": ["FOO", "BAR"]}) r r/r)r,r;r<r r+r*)r&r%r2r-r'r'r(ÚtestAllFieldsToJson�s   z"JsonFormatTest.testAllFieldsToJsoncCsHd}tjƒ}d|_|jtj|ƒ|ƒtjƒ}tj||ƒ|j||ƒdS)Nz{ "enumValue": 999 }iç)r r/r r,r r+r*)r&r2r%r-r'r'r(ÚtestUnknownEnumToJsonAndBack¢s  z+JsonFormatTest.testUnknownEnumToJsonAndBackcCsbtjƒ}tjj}tjj}d|jj|_d|jj|_t j |ƒ}tjƒ}t j ||ƒ|j ||ƒdS)Nér) rÚTestMessageSetContainerÚTestMessageSetExtension1Úmessage_set_extensionÚTestMessageSetExtension2Ú message_setÚ ExtensionsÚiÚstrr r+r*r,)r&r%Úext1Úext2Ú message_textr-r'r'r(ÚtestExtensionToJsonAndBack¬s z)JsonFormatTest.testExtensionToJsonAndBackcCs|jddƒdS)Nz{"[extensionField]": {}}z8Message type proto3.TestMessage does not have extensions)r3)r&r'r'r(ÚtestExtensionErrors¹sz"JsonFormatTest.testExtensionErrorscCsbtjƒ}tjj}tjj}d|jj|_d|jj|_t j |ƒ}tjƒ}t j ||ƒ|j ||ƒdS)Nr@r) rrArBrCrDrErFrGrHr Ú MessageToDictÚ ParseDictr,)r&r%rIrJÚ message_dictr-r'r'r(ÚtestExtensionToDictAndBack½s z)JsonFormatTest.testExtensionToDictAndBackcCsdtjƒ}tjj}tjj}d|jj|_d|jj|_t j |ƒ}dddiddidœi}|j ||ƒdS)z&See go/proto3-json-spec for spec. r@rZ messageSetrGrH)z@[protobuf_unittest.TestMessageSetExtension1.messageSetExtension]z@[protobuf_unittest.TestMessageSetExtension2.messageSetExtension]N) rrArBrCrDrErFrGrHr rNr,)r&r%rIrJrPZ golden_dictr'r'r(Ú/testExtensionSerializationDictMatchesProto3SpecÊsz>JsonFormatTest.testExtensionSerializationDictMatchesProto3SpeccCsntjƒ}tjj}tjj}d|jj|_d|jj|_t j |ƒ}d}d}d||f}|j t j |ƒt j |ƒƒdS)z&See go/proto3-json-spec for spec. r@rz>protobuf_unittest.TestMessageSetExtension1.messageSetExtensionz>protobuf_unittest.TestMessageSetExtension2.messageSetExtensionzZ{"messageSet": { "[%s]": { "i": 23 }, "[%s]": { "str": "foo" }}}N)rrArBrCrDrErFrGrHr r+r,r;r<)r&r%rIrJrKZ ext1_textZ ext2_textZ golden_textr'r'r(Ú/testExtensionSerializationJsonMatchesProto3Specäs z>JsonFormatTest.testExtensionSerializationJsonMatchesProto3SpeccCs€tjƒ}tjddkrd|_nd|_|jdjdƒ7_|jtj|ƒdƒtjƒ}|j ||ƒd}tj ||ƒ|j|j d ƒdS) Nréu& <" > \/

z & <" > \/s

zutf-8z;{ "stringValue": "&\n<\"\r>\b\t\f\\\u0001/\u2028\u2029" }z{"int32Value": "1"}é) r r/ÚsysÚ version_inforÚdecoder,r r+r.r*r)r&r%r-r2r'r'r(ÚtestJsonEscapeStringþs  z#JsonFormatTest.testJsonEscapeStringcCsDtjdd�}|jtjtj|dƒƒtjdƒƒtjƒ}|j||ƒdS)Nr)rTaË{"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 r/r,r;r<r r+r.)r&r%r-r'r'r(ÚtestAlwaysSeriliazes z"JsonFormatTest.testAlwaysSeriliazecCsZtjƒ}tjd|ƒ|j|jdƒtjd|ƒ|j|jdƒtjd|ƒ|j|jdƒdS)Nz{"int32Value": -2.147483648e9}lz{"int32Value": 1e5}i †z{"int32Value": 1.0}rUi€)r r/r r*r,r)r&r%r'r'r(ÚtestIntegersRepresentedAsFloat-s   z-JsonFormatTest.testIntegersRepresentedAsFloatcCsètjƒ}|jtjtj|dƒƒtjdƒƒd|jd<d|jd<d|jd<d|jd<d|j d<d|j d<d|j d<d|j d<d|j d<d|j d<d|j d<d|j d<d|j djd<|jtjtj|dƒƒtjd ƒƒtjƒ}|j||ƒdS) NTzj{"boolMap": {},"int32Map": {},"int64Map": {},"uint32Map": {},"uint64Map": {},"stringMap": {},"mapMap": {}}rUéFrTÚ1Znullzå{"boolMap": {"false": 2, "true": 1},"int32Map": {"1": 2, "2": 3},"int64Map": {"1": 2, "2": 3},"uint32Map": {"1": 2, "2": 3},"uint64Map": {"1": 2, "2": 3},"stringMap": {"1": 2, "null": 3},"mapMap": {"1": {"boolMap": {"true": 3}}}})r Z TestNestedMapr,r;r<r r+Zbool_mapZ int32_mapZ int64_mapZ uint32_mapZ uint64_mapZ string_mapZmap_mapr.)r&r%r-r'r'r(Ú testMapFields6s,             zJsonFormatTest.testMapFieldscCsNtjƒ}|jtj|dƒdƒd|_|jtj|dƒdƒtjƒ}|j||ƒdS)NTz{}rz{ "oneofInt32Value": 0 })r Ú TestOneofr,r r+Zoneof_int32_valuer.)r&r%r-r'r'r(ÚtestOneofFields^s  zJsonFormatTest.testOneofFieldscCsFtjƒ}tjd|ƒ|j|jdjddƒƒ|jddƒ|jddƒdS)Nz{"stringValue": "\uD83D\uDE01"}sðŸ˜�zutf-8Ústrictz{"stringValue": "\uD83D"}z*Invalid \\uXXXX escape|Unpaired.*surrogatez{"stringValue": "\uDE01"})r r/r r*r,rrXr3)r&r%r'r'r(ÚtestSurrogatesms zJsonFormatTest.testSurrogatescCs tjƒ}d|j_d|j_d|jjƒ_d|jd_d|jjƒ_d|jd_d|jjƒ_d|jd_d|jjƒ_d|jd _d|jjƒ_d|jd _|jtj t j |d ƒƒtj d ƒƒtjƒ}|j ||ƒd}t j ||ƒ|j|jjdƒ|j|jjdƒ|j|jdjdƒ|j|jdjdƒdS)NrrrUi'iáõr\lAèëiÿÉš;rTlw#o9r:TzÌ{"value": "1970-01-01T00:00:00Z","repeatedValue": [ "1970-01-01T00:00:20.000000001Z", "1970-01-01T00:00:00.000010Z", "1973-03-03T09:46:40Z", "9999-12-31T23:59:59.999999999Z", "0001-01-01T00:00:00Z"]}z}{"value": "1970-01-01T00:00:00.01+08:00","repeatedValue":[ "1970-01-01T00:00:00.01+08:30", "1970-01-01T00:00:00.01-01:23"]}éii€–˜g!@r@é<lýÿÿÿw#o9iøÿÿÿi€�ÿÿg!ÀgâÝÀidit)r Ú TestTimestamprÚsecondsÚnanosÚrepeated_valuer$r,r;r<r r+r.r*)r&r%r-r2r'r'r(ÚtestTimestampMessage~s0             z#JsonFormatTest.testTimestampMessagecCs¨tjƒ}d|j_d|jjƒ_d|jd_d |jjƒ_d |jd_d|jjƒ_d|jd_d |jjƒ_d|jjƒ_|jtj t j |dƒƒtj d ƒƒtjƒ}|j ||ƒdS) NrUrrièiÀاr\l—s%Tzs{"value": "1s","repeatedValue": [ "0.000000010s", "-1.000001s", "10.011s", "-315576000000s", "315576000000s"]}éÿÿÿÿiüÿÿlýÿÿÿ—s%) r Z TestDurationrrfrhr$rgr,r;r<r r+r.)r&r%r-r'r'r(ÚtestDurationMessage¦s         z"JsonFormatTest.testDurationMessagecCsPtjƒ}|jjjdƒ|jjjdƒ|jtj|dƒdƒtjƒ}|j||ƒdS)Nzfoo.barrTz{ "value": "foo.bar,bar" }) r Z TestFieldMaskrÚpathsr"r,r r+r.)r&r%r-r'r'r(ÚtestFieldMaskMessageÀs z#JsonFormatTest.testFieldMaskMessagecCs‚tjƒ}d|j_d|j_d|j_d|j_d|jjƒ_d|jjƒ_|j jƒ|j t j t j|dƒƒt j dƒƒtjƒ}|j||ƒdS)NFrÚóTaR{ "int32Value": 0, "boolValue": false, "stringValue": "", "bytesValue": "", "repeatedBoolValue": [true, false], "repeatedInt32Value": [0], "repeatedUint32Value": [], "repeatedFloatValue": [], "repeatedDoubleValue": [], "repeatedBytesValue": [], "repeatedInt64Value": [], "repeatedUint64Value": [], "repeatedStringValue": []})r Z TestWrapperrrrrrr#r$r!r,r;r<r r+r.)r&r%r-r'r'r(ÚtestWrapperMessageÌs    z!JsonFormatTest.testWrapperMessagecCsÊtjƒ}d|jd<d|jd<d|jd<d|jd<d|jjd ƒd <d |jd d <|jjd ƒ}|jdddddgƒd|jƒd<d|jjƒd<|jjƒ|j t j t j |dƒƒt j dƒƒtjƒ}|j||ƒdS)NÚJimÚnamerZageTZattendZemailZSFOZaddressZcityiZ house_numberÚlistéZsevenFé Zsubkey2ra{ "value": { "address": { "city": "SFO", "house_number": 1024 }, "age": 10, "name": "Jim", "attend": true, "email": null, "list": [6, "seven", true, false, null, {"subkey2": 9}] }, "repeatedValue": [{"age": 11}, {}]})r Ú TestStructrZget_or_create_structZget_or_create_listÚextendZ add_structrhr$r,r;r<r r+r.)r&r%Z struct_listr-r'r'r(ÚtestStructMessageés$       z JsonFormatTest.testStructMessagecCs¾tjƒ}d|j_d|jjƒ_d|jjƒ_d|jjƒ_|j t j t j |dƒƒt j dƒƒtjƒ}|j||ƒ|jjƒ|j t j t j |dƒƒt j dƒƒ|jƒt jd|ƒ|j |jjdƒd ƒdS) NÚhellog333333&@Frz;{ "value": "hello", "repeatedValue": [11.1, false, null]}zA{ "value": "hello", "repeatedValue": [11.1, false, null, null]}z{"value": null}ZkindÚ null_value)r Z TestValuerrrhr$Ú number_valuerrzr,r;r<r r+r.ÚClearr*Z WhichOneof)r&r%r-r'r'r(ÚtestValueMessage s&      zJsonFormatTest.testValueMessagecCs¦tjƒ}d|jjjƒ_d|jjjƒ_d|jjjƒ_d|jjjƒ_d|jjjƒj d<d|j jƒjjƒ_|j jƒ|j t j tj|dƒƒt j d ƒƒtjƒ}|j||ƒdS) Ng333333&@rTryrqrrrUFzS{"value": [11.1, null, true, "hello", {"name": "Jim"}] ,"repeatedValue": [[1], []]})r Ú TestListValuerÚvaluesr$r{rzrrZ struct_valuerhr,r;r<r r+r.)r&r%r-r'r'r(ÚtestListValueMessage&s z#JsonFormatTest.testListValueMessagec CsÚtjƒ}tjƒ}tjƒ}d|_d|_|jj|ƒ|jjƒj|ƒ|jjƒj|ƒ|jjƒ|jtj t j |dƒƒtj dƒƒtjƒ}|j ||ƒtj ddd ddddd�}|jƒ|jj|ƒ|jt j |d ƒd d …d ƒdS)NiÒi.Ta{ "repeatedValue": [ { "@type": "type.googleapis.com/proto3.MessageType", "value": 1234 }, { "@type": "type.googleapis.com/proto3.MessageType", "value": 5678 }, {}], "value": { "@type": "type.googleapis.com/proto3.MessageType", "value": 1234 } } rg…ëQ¸ @r)rrrrrrrFréDzD{ "value": { "@type": "type.googleapis.com/proto3.TestMessage"iìÿÿÿ)r ÚTestAnyZ MessageTyperÚPackrhr$r,r;r<r r+r.r/r|)r&r%Zvalue1Zvalue2r-Z test_messager'r'r(ÚtestAnyMessage7s8    zJsonFormatTest.testAnyMessagec CsÄtjƒ}tjƒ}d|_|j|ƒ|jtjt j |dƒƒtjdƒƒtjƒ}|j ||ƒt j ƒ}|j|ƒ|jtjt j |dƒƒtjdƒƒ|j ||ƒtjƒ}d|_|j|ƒ|jtjt j |dƒƒtjdƒƒ|j ||ƒtjƒ}|jjdƒ|jjdƒ|j|ƒ|jtjt j |dƒƒtjd ƒƒ|j ||ƒtjƒ}d |d <|j|ƒ|jtjt j |dƒƒtjd ƒƒ|j ||ƒtjƒ}d |_|j|ƒ|j|ƒ|jtjt j |dƒƒtjdƒƒ|j ||ƒdS)NiÒTzQ{ "@type": "type.googleapis.com/google.protobuf.Int32Value", "value": 1234 } zb{ "@type": "type.googleapis.com/google.protobuf.Timestamp", "value": "1970-01-01T00:00:00Z" } rUzO{ "@type": "type.googleapis.com/google.protobuf.Duration", "value": "1s" } zfoo.barrzY{ "@type": "type.googleapis.com/google.protobuf.FieldMask", "value": "foo.bar,bar" } rqrrzX{ "@type": "type.googleapis.com/google.protobuf.Struct", "value": {"name": "Jim"} } i.zœ{ "@type": "type.googleapis.com/google.protobuf.Any", "value": { "@type": "type.googleapis.com/google.protobuf.Int32Value", "value": 5678 } } )rÚAnyrZ Int32Valuerrƒr,r;r<r r+r.rZ TimestamprZDurationrfrZ FieldMaskrlr"rÚStruct) r&r%rr-Z timestampZdurationZ field_maskZstruct_messageZ nested_anyr'r'r(ÚtestWellKnownInAnyMessageesf              z(JsonFormatTest.testWellKnownInAnyMessagecCs„tjƒ}tjƒ}|j|ƒtjd|ƒ|j||ƒ|j|jdƒƒtjd|ƒ|j|jdƒƒ|j tj dtjd|ƒ|j ddƒdS)Na{"int32Value": null, "int64Value": null, "uint32Value": null,"uint64Value": null,"floatValue": null,"doubleValue": null,"boolValue": null,"stringValue": null,"bytesValue": null,"messageValue": null,"enumValue": null,"repeatedInt32Value": null,"repeatedInt64Value": null,"repeatedUint32Value": null,"repeatedUint64Value": null,"repeatedFloatValue": null,"repeatedDoubleValue": null,"repeatedBoolValue": null,"repeatedStringValue": null,"repeatedBytesValue": null,"repeatedMessageValue": null,"repeatedEnumValue": null}rz{"messageValue": {}}zkFailed to parse repeatedInt32Value field: null is not allowed to be used as an element in a repeated field.z {"repeatedInt32Value":[1, null]}z{"repeatedMessageValue":[null]}zmFailed to parse repeatedMessageValue field: null is not allowed to be used as an element in a repeated field.) r r/r)r r*r,Z assertFalseZHasFieldÚ assertTruer0r1r3)r&r%r-r'r'r(Ú testParseNull´s"   zJsonFormatTest.testParseNullcCsRtjƒ}tdƒ|_d}|jtj|ƒ|ƒtjƒ}tj||ƒ|jt j |jƒƒdS)NÚnanz{ "floatValue": "NaN" }) r r/rrr,r r+r*rˆÚmathZisnan)r&r%r2r-r'r'r(Ú testNanFloatás  zJsonFormatTest.testNanFloatcCs|jddƒdS)Nrnz1Failed to load JSON: (Expecting value)|(No JSON).)r3)r&r'r'r(ÚtestParseEmptyTextêsz!JsonFormatTest.testParseEmptyTextcCsftjƒ}d}tj||ƒd}tj||ƒ|jddƒd}tj||ƒtjƒ}|jtjdtjd|ƒdS)Nz{"enumValue": 0}z{"enumValue": 1}z{"enumValue": "baz"}zVFailed to parse enumValue field: Invalid enum value baz for enum type proto3.EnumType.z{"enumValue": 12345}z{Failed to parse optionalNestedEnum field: Invalid enum value 12345 for enum type protobuf_unittest.TestAllTypes.NestedEnum.z{"optionalNestedEnum": 12345}) r r/r r*r3r Z TestAllTypesr0r1)r&r%r2r'r'r(ÚtestParseEnumValueîs   z!JsonFormatTest.testParseEnumValuecCs|jddƒ|jddƒdS)Nz{int32Value: 1}zQFailed to load JSON: Expecting property name( enclosed in double quotes)?: line 1z{"unknownName": 1}zCMessage type "proto3.TestMessage" has no field named "unknownName".)r3)r&r'r'r(ÚtestParseBadIdentifersz$JsonFormatTest.testParseBadIdentifercCs<d}tjƒ}tj||dd�d}tjƒ}tj||dd�dS)Nz{"unknownName": 1}T)Zignore_unknown_fieldszl{ "repeatedValue": [ { "@type": "type.googleapis.com/proto3.MessageType", "unknownName": 1 }] } )r r/r r*r‚)r&r2r-r'r'r(ÚtestIgnoreUnknownField s z%JsonFormatTest.testIgnoreUnknownFieldcCstjdkrdS|jddƒdS)Nr\éz!{"int32Value": 1, "int32Value":2}z.Failed to load JSON: duplicate key int32Value.)r\r‘)rVrWr3)r&r'r'r(ÚtestDuplicateFields z!JsonFormatTest.testDuplicateFieldcCs|jddƒ|jddƒdS)Nz{"boolValue": 1}zGFailed to parse boolValue field: Expected true or false without quotes.z{"boolValue": "true"})r3)r&r'r'r(ÚtestInvalidBoolValuesz#JsonFormatTest.testInvalidBoolValuecCsltjƒ}d}|jtjtj||ƒ|jddƒ|jddƒ|jddƒ|jdd ƒ|jd d ƒ|jd d ƒdS)Nz{"int32Value": 0x12345}z{"int32Value": 1.5}z>Failed to parse int32Value field: Couldn't parse integer: 1.5.z{"int32Value": 012345}z9Failed to load JSON: Expecting \'?,\'? delimiter: line 1.z{"int32Value": " 1 "}z@Failed to parse int32Value field: Couldn't parse integer: " 1 ".z{"int32Value": "1 "}z?Failed to parse int32Value field: Couldn't parse integer: "1 ".z${"int32Value": 12345678901234567890}zKFailed to parse int32Value field: Value out of range: 12345678901234567890.z{"uint32Value": -1}z:Failed to parse uint32Value field: Value out of range: -1.)r r/Z assertRaisesr r1r*r3)r&r%r2r'r'r(ÚtestInvalidIntegerValue's  z&JsonFormatTest.testInvalidIntegerValuecCs|jddƒdS)Nz{"floatValue": "nan"}zPFailed to parse floatValue field: Couldn't parse float "nan", use "NaN" instead.)r3)r&r'r'r(ÚtestInvalidFloatValue?sz$JsonFormatTest.testInvalidFloatValuecCs|jddƒ|jddƒdS)Nz{"bytesValue": "AQI"}z4Failed to parse bytesValue field: Incorrect padding.z{"bytesValue": "AQI*"})r3)r&r'r'r(ÚtestInvalidBytesValueDsz$JsonFormatTest.testInvalidBytesValuecCs|jddƒdS)Nz{"repeatedInt32Value": 12345}zkFailed to parse repeatedInt32Value field: repeated field repeatedInt32Value must be in \[\] which is 12345.)r3)r&r'r'r(ÚtestInvalidRepeatedJsz"JsonFormatTest.testInvalidRepeatedcCsœtjƒ}d}|jtjdtj||ƒd}|jtjdtj||ƒd}|jtjdtj||ƒtjd krddSd }|jtjd tj||ƒd }|jtjd tj||ƒdS)Nz!{"int32Map": {"null": 2, "2": 3}}z/Failed to parse int32Map field: invalid literalz{"int32Map": {1: 2, "2": 3}}zQFailed to load JSON: Expecting property name( enclosed in double quotes)?: line 1z{"boolMap": {"null": 1}}zDFailed to parse boolMap field: Expected "true" or "false", not null.r\r‘z${"stringMap": {"a": 3, "\u0061": 2}}z$Failed to load JSON: duplicate key az{"stringMap": 0}zSFailed to parse stringMap field: Map field string_map must be in a dict which is 0.)r\r‘)r ZTestMapr0r r1r*rVrW)r&r%r2r'r'r(ÚtestInvalidMapOs8     zJsonFormatTest.testInvalidMapcCsŽtjƒ}d}|jtjdtj||ƒd}|jtjdtj||ƒd}|jtjdtj||ƒd}|jtjdtj||ƒd |j_|jt d tj |ƒdS) Nz%{"value": "10000-01-01T00:00:00.00Z"}zKtime data '10000-01-01T00:00:00' does not match format '%Y-%m-%dT%H:%M:%S'.z/{"value": "1970-01-01T00:00:00.0123456789012Z"}z2nanos 0123456789012 more than 9 fractional digits.z&{"value": "1972-01-01T01:00:00.01+08"}z$Invalid timezone offset value: \+08.z!{"value": "0000-01-01T00:00:00Z"}z7Failed to parse value field: year (0 )?is out of range.l€Aèëzdate value out of range) r rer0r r1r*r rrfÚ OverflowErrorr+)r&r%r2r'r'r(ÚtestInvalidTimestampos4    z#JsonFormatTest.testInvalidTimestampcCs&tjƒ}d}|jtjdtj||ƒdS)Nz/{"oneofInt32Value": 1, "oneofStringValue": "2"}zTMessage type "proto3.TestOneof" should not have multiple "oneof_value" oneof fields.)r r_r0r r1r*)r&r%r2r'r'r(ÚtestInvalidOneofŽs zJsonFormatTest.testInvalidOneofcCs&tjƒ}d}|jtjdtj||ƒdS)Nz{"value": 1234}zDFailed to parse value field: ListValue must be in \[\] which is 1234)r r~r0r r1r*)r&r%r2r'r'r(ÚtestInvalidListValue—s z#JsonFormatTest.testInvalidListValuecCs&tjƒ}d}|jtjdtj||ƒdS)Nz{"value": 1234}zCFailed to parse value field: Struct must be in a dict which is 1234)r rvr0r r1r*)r&r%r2r'r'r(ÚtestInvalidStructŸs z JsonFormatTest.testInvalidStructcCsftjƒ}d}|jtdtj||ƒd}|jtjdtj||ƒd}|jtdtj||ƒd}tj||ƒdS)Nz;{"@type": "type.googleapis.com/google.protobuf.Int32Value"}rz{"value": 1234}z*@type is missing when parsing any message.z?{"@type": "type.googleapis.com/MessageNotExist", "value": 1234}zQCan not find message descriptor by type_url: type.googleapis.com/MessageNotExist.zN{"@type": "incorrect.googleapis.com/google.protobuf.Int32Value","value": 1234})rr…r0ÚKeyErrorr r*r1Ú TypeError)r&r%r2r'r'r(ÚtestInvalidAny§s$   zJsonFormatTest.testInvalidAnycCsªtjƒ}d|_|jdtj|ƒƒ|jdtj|ddƒƒtjƒ}|jdtj|ddƒƒ|jdtj|ddƒƒtjƒ}tjd|ƒ|jd |jƒtjd |ƒ|jd|jƒdS) Ni90z{ "int32Value": 12345 }z{ "int32_value": 12345 }FTz{ "repeatedValue": [] }z{ "repeated_value": [] }z{"int32Value": 54321}i1Ôz{"int32_value": 12345})r r/rr,r r+rer*)r&r%r'r'r(ÚtestPreservingProtoFieldNames¾s    z,JsonFormatTest.testPreservingProtoFieldNamescCs(tjƒ}d|_|jdtj|dd�ƒdS)Ni90z{ "int32Value": 12345 }r)Úindent)r r/rr,r r+)r&r%r'r'r(Ú testIndentÓszJsonFormatTest.testIndentcCs2d}d|i}tjƒ}tj||ƒ|j||jƒdS)Ni90Ú int32Value)r r/r rOr,r)r&ÚexpectedZjs_dictr%r'r'r(Ú testParseDictÙs  zJsonFormatTest.testParseDictcCs,tjƒ}d|_ddi}|j|tj|ƒƒdS)Ni90r¤)r r/rr,r rN)r&r%r¥r'r'r(ÚtestMessageToDictàs z JsonFormatTest.testMessageToDictcCs8tjƒ}d|_|jdtj|ƒƒtjƒ}|j||ƒdS)Ni90z{ "@value": 12345 })r ZTestCustomJsonNamerr,r r+r.)r&r%r-r'r'r(Ú testJsonNameçs  zJsonFormatTest.testJsonNamec CsFtjdddddd�}|jtj|dd�tjdddddd œd dd �ƒdS) NTrUrTr:Zbla)rrrrr)Ú sort_keysÚ3)Z boolValuer¤Z int64ValueZ uint32ValueZ stringValuer\)r¢r©)r r/r,r r+r;Údumps)r&r%r'r'r(Ú testSortKeysïs  zJsonFormatTest.testSortKeysN)3r4r5r6r8r=r>r?rLrMrQrRrSrYrZr[r^r`rbrirkrmrprxr}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'r'r(r7ns` !    (( !.O-    r7Ú__main__)Ú__doc__Ú __author__r;r‹rVZ unittest2ZunittestÚ ImportErrorZgoogle.protobufrrrrrrrr Zgoogle.protobuf.internalr r Zgoogle.protobuf.utilr ZTestCaser r7r4Úmainr'r'r'r(Ú s<            4