3 SLj١ @sdZdZddlZddlZddlZy ddlZWnek rHddlZYnXddlm Z ddlm Z ddlm Z ddlm Z ddlm Z dd lmZdd lmZdd lmZdd lmZdd lmZddlmZGdddejZGdddeZedkrejdS)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$eZdZddZddZddZdS)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|jjdd |jj_ d|jj_ |jjt j|jjt j ||_dS)Nl~ tl4? z-infgo! @Tfoosbar illiilrgV瞯<infFzFew symbols!#$,;barsfoo iil) int32_value int64_value uint32_value uint64_valuefloat float_value double_value bool_value string_value bytes_value message_valuevaluer ZBAR enum_valuerepeated_int32_valueappendZrepeated_int64_valueZrepeated_uint32_valueZrepeated_uint64_valueZrepeated_float_valueZrepeated_double_valuerepeated_bool_valueZrepeated_string_valueZrepeated_bytes_valueZrepeated_message_valueaddZrepeated_enum_valueZFOOmessage)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 TestMessageassertRaisesRegexpr ParseErrorr*)r&textZ error_messager%r'r'r( CheckErrorfs zJsonFormatBase.CheckErrorN)__name__ __module__ __qualname__r)r.r3r'r'r'r(r :s%r c@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Z d=d>Z!d?d@Z"dAdBZ#dCdDZ$dEdFZ%dGdHZ&dIdJZ'dKdLZ(dMdNZ)dOdPZ*dQdRZ+dSdTZ,dUdVZ-dWdXZ.dYdZZ/d[d\Z0d]d^Z1d_d`Z2daS)bJsonFormatTestcCs2tj}|jtj|dtj}|j||dS)Nz{})r r/r,r r+r.)r&r%r-r'r'r(testEmptyMessageToJsonps  z%JsonFormatTest.testEmptyMessageToJsoncCsHtjdddgd}|jtjtj|tjdtj}|j||dS)NZtestY)rr!z6{"stringValue": "test", "repeatedInt32Value": [89, 4]})r r/r,jsonloadsr 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(testAllFieldsToJsons   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(testUnknownEnumToJsonAndBacks  z+JsonFormatTest.testUnknownEnumToJsonAndBackcCsbtj}tjj}tjj}d|jj|_d|jj|_t j |}tj}t j |||j ||dS)Nr) rTestMessageSetContainerTestMessageSetExtension1message_set_extensionTestMessageSetExtension2 message_set Extensionsistrr r+r*r,)r&r%ext1ext2 message_textr-r'r'r(testExtensionToJsonAndBacks z)JsonFormatTest.testExtensionToJsonAndBackcCs|jdddS)Nz{"[extensionField]": {}}z8Message type proto3.TestMessage does not have extensions)r3)r&r'r'r(testExtensionErrorssz"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(testExtensionToDictAndBacks z)JsonFormatTest.testExtensionToDictAndBackcCsdtj}tjj}tjj}d|jj|_d|jj|_t j |}dddiddidi}|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(/testExtensionSerializationDictMatchesProto3Specsz>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(/testExtensionSerializationJsonMatchesProto3Specs z>JsonFormatTest.testExtensionSerializationJsonMatchesProto3SpeccCstj}tjddkrd|_nd|_|jdjd7_|jtj|dtj}|j ||d}tj |||j|j d dS) Nru& <" > \/

z & <" > \/s

zutf-8z;{ "stringValue": "&\n<\"\r>\b\t\f\\\u0001/\u2028\u2029" }z{"int32Value": "1"}) r r/sys version_infordecoder,r r+r.r*r)r&r%r-r2r'r'r(testJsonEscapeStrings  z#JsonFormatTest.testJsonEscapeStringcCsDtjdd}|jtjtj|dtjdtj}|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|jdtjd||j|jdtjd||j|jddS)Nz{"int32Value": -2.147483648e9}lz{"int32Value": 1e5}iz{"int32Value": 1.0}rUi)r r/r r*r,r)r&r%r'r'r(testIntegersRepresentedAsFloat-s   z-JsonFormatTest.testIntegersRepresentedAsFloatcCstj}|jtjtj|dtjdd|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|dtjd tj}|j||dS) NTzj{"boolMap": {},"int32Map": {},"int64Map": {},"uint32Map": {},"uint64Map": {},"stringMap": {},"mapMap": {}}rUFrT1Znullz{"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|ddd|_|jtj|ddtj}|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|jdddS)Nz{"stringValue": "\uD83D\uDE01"}s😁zutf-8strictz{"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|jdjddS)NrrrUi'ir\lAiɚ;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"]}iig!@r@<lw#o9iig!gidit)r TestTimestamprsecondsnanosrepeated_valuer$r,r;r<r r+r.r*)r&r%r-r2r'r'r(testTimestampMessage~s0             z#JsonFormatTest.testTimestampMessagecCstj}d|j_d|jj_d|jd_d |jj_d |jd_d|jj_d|jd_d |jj_d|jj_|jtj t j |dtj d tj}|j ||dS) NrUrriiاr\ls%Tzs{"value": "1s","repeatedValue": [ "0.000000010s", "-1.000001s", "10.011s", "-315576000000s", "315576000000s"]}ils%) r Z TestDurationrrfrhr$rgr,r;r<r r+r.)r&r%r-r'r'r(testDurationMessages         z"JsonFormatTest.testDurationMessagecCsPtj}|jjjd|jjjd|jtj|ddtj}|j||dS)Nzfoo.barrTz{ "value": "foo.bar,bar" }) r Z TestFieldMaskrpathsr"r,r r+r.)r&r%r-r'r'r(testFieldMaskMessages z#JsonFormatTest.testFieldMaskMessagecCstj}d|j_d|j_d|j_d|j_d|jj_d|jj_|j j|j t j t j|dt j dtj}|j||dS)NFrTaR{ "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(testWrapperMessages    z!JsonFormatTest.testWrapperMessagecCstj}d|jd<d|jd<d|jd<d|jd<d|jjd d <d |jd d <|jjd }|jdddddgd|jd<d|jjd<|jj|j t j t j |dt j dtj}|j||dS)NJimnamerZageTZattendZemailZSFOZaddressZcityiZ house_numberlistZsevenF 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_listextendZ add_structrhr$r,r;r<r r+r.)r&r%Z struct_listr-r'r'r(testStructMessages$       z JsonFormatTest.testStructMessagecCstj}d|j_d|jj_d|jj_d|jj_|j t j t j |dt j dtj}|j|||jj|j t j t j |dt j d|jt jd||j |jjdd dS) Nhellog333333&@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.testValueMessagecCstj}d|jjj_d|jjj_d|jjj_d|jjj_d|jjjj d<d|j jjj_|j j|j t j tj|dt j d tj}|j||dS) Ng333333&@rTryrqrrrUFzS{"value": [11.1, null, true, "hello", {"name": "Jim"}] ,"repeatedValue": [[1], []]})r TestListValuervaluesr$r{rzrrZ struct_valuerhr,r;r<r r+r.)r&r%r-r'r'r(testListValueMessage&s z#JsonFormatTest.testListValueMessagec Cstj}tj}tj}d|_d|_|jj||jjj||jjj||jj|jtj t j |dtj dtj}|j ||tj ddd ddddd}|j|jj||jt j |d d d d dS)Nii.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 } } rgQ @r)rrrrrrrFrDzD{ "value": { "@type": "type.googleapis.com/proto3.TestMessage"i)r TestAnyZ MessageTyperPackrhr$r,r;r<r r+r.r/r|)r&r%Zvalue1Zvalue2r-Z test_messager'r'r(testAnyMessage7s8    zJsonFormatTest.testAnyMessagec Cstj}tj}d|_|j||jtjt j |dtjdtj}|j ||t j }|j||jtjt j |dtjd|j ||tj}d|_|j||jtjt j |dtjd|j ||tj}|jjd|jjd|j||jtjt j |dtjd |j ||tj}d |d <|j||jtjt j |dtjd |j ||tj}d |_|j||j||jtjt j |dtjd|j ||dS)NiTzQ{ "@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 } } )rAnyrZ Int32Valuerrr,r;r<r r+r.rZ TimestamprZDurationrfrZ FieldMaskrlr"rStruct) r&r%rr-Z timestampZdurationZ field_maskZstruct_messageZ nested_anyr'r'r(testWellKnownInAnyMessageesf              z(JsonFormatTest.testWellKnownInAnyMessagecCstj}tj}|j|tjd||j|||j|jdtjd||j|jd|j tj dtjd||j dddS)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( testParseNulls"   zJsonFormatTest.testParseNullcCsRtj}td|_d}|jtj||tj}tj|||jt j |jdS)Nnanz{ "floatValue": "NaN" }) r r/rrr,r r+r*rmathZisnan)r&r%r2r-r'r'r( testNanFloats  zJsonFormatTest.testNanFloatcCs|jdddS)Nrnz1Failed to load JSON: (Expecting value)|(No JSON).)r3)r&r'r'r(testParseEmptyTextsz!JsonFormatTest.testParseEmptyTextcCsftj}d}tj||d}tj|||jddd}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(testParseEnumValues   z!JsonFormatTest.testParseEnumValuecCs|jdd|jdddS)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||ddd}tj}tj||dddS)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|jdddS)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|jdddS)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|jdddS)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|jdddS)Nz{"bytesValue": "AQI"}z4Failed to parse bytesValue field: Incorrect padding.z{"bytesValue": "AQI*"})r3)r&r'r'r(testInvalidBytesValueDsz$JsonFormatTest.testInvalidBytesValuecCs|jdddS)Nz{"repeatedInt32Value": 12345}zkFailed to parse repeatedInt32Value field: repeated field repeatedInt32Value must be in \[\] which is 12345.)r3)r&r'r'r(testInvalidRepeatedJsz"JsonFormatTest.testInvalidRepeatedcCstj}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\rz${"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.testInvalidMapcCstj}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.lAzdate 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(testInvalidOneofs 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(testInvalidListValues 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(testInvalidStructs 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})rrr0KeyErrorr r*r1 TypeError)r&r%r2r'r'r(testInvalidAnys$   zJsonFormatTest.testInvalidAnycCstj}d|_|jdtj||jdtj|ddtj}|jdtj|dd|jdtj|ddtj}tjd||jd |jtjd ||jd|jdS) Ni90z{ "int32Value": 12345 }z{ "int32_value": 12345 }FTz{ "repeatedValue": [] }z{ "repeated_value": [] }z{"int32Value": 54321}i1z{"int32_value": 12345})r r/rr,r r+rer*)r&r%r'r'r(testPreservingProtoFieldNamess    z,JsonFormatTest.testPreservingProtoFieldNamescCs(tj}d|_|jdtj|dddS)Ni90z{ "int32Value": 12345 }r)indent)r r/rr,r r+)r&r%r'r'r( testIndentszJsonFormatTest.testIndentcCs2d}d|i}tj}tj|||j||jdS)Ni90 int32Value)r r/r rOr,r)r&expectedZjs_dictr%r'r'r( testParseDicts  zJsonFormatTest.testParseDictcCs,tj}d|_ddi}|j|tj|dS)Ni90r)r r/rr,r rN)r&r%rr'r'r(testMessageToDicts z JsonFormatTest.testMessageToDictcCs8tj}d|_|jdtj|tj}|j||dS)Ni90z{ "@value": 12345 })r ZTestCustomJsonNamerr,r r+r.)r&r%r-r'r'r( testJsonNames  zJsonFormatTest.testJsonNamec CsFtjdddddd}|jtj|ddtjdddddd d dd dS) NTrUrTr:Zbla)rrrrr) sort_keys3)Z boolValuerZ int64ValueZ uint32ValueZ stringValuer\)rr)r r/r,r r+r;dumps)r&r%r'r'r( testSortKeyss  zJsonFormatTest.testSortKeysN)3r4r5r6r8r=r>r?rLrMrQrRrSrYrZr[r^r`rbrirkrmrprxr}rrrrrrrrrrrrrrrrrrrrrrrrrrrr'r'r'r(r7ns` !    (( !.O-    r7__main__)__doc__ __author__r;rrVZ unittest2Zunittest ImportErrorZgoogle.protobufrrrrrrrr Zgoogle.protobuf.internalr r Zgoogle.protobuf.utilr ZTestCaser r7r4mainr'r'r'r( s<            4