HEX
Server: LiteSpeed
System: Linux server334.web-hosting.com 4.18.0-553.124.4.lve.el8.x86_64 #1 SMP Fri May 15 13:02:13 UTC 2026 x86_64
User: richfield (1256)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/google/protobuf/internal/__pycache__/json_format_test.cpython-36.pyc
3

���hġ�@sdZdZddlZddlZddlZyddlZWnek
rHddlZYnXddlm	Z	ddlm
Z
ddlmZddlmZddlm
Z
dd	lmZdd
lmZddlmZdd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�assertRaisesRegexr�
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
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�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,rr+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�loadsrr+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<rr+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,rr+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�strrr+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)rrArBrCrDrErFrGrHrrNr,)r&r%rIrJrPZgolden_dictr'r'r(�/testExtensionSerializationDictMatchesProto3Spec�sz>JsonFormatTest.testExtensionSerializationDictMatchesProto3SpeccCsntj�}tjj}tjj}d|jj|_d|jj|_t	j
|�}d}d}d||f}|jt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)rrArBrCrDrErFrGrHrr+r,r;r<)r&r%rIrJrKZ	ext1_textZ	ext2_textZgolden_textr'r'r(�/testExtensionSerializationJsonMatchesProto3Spec�s
z>JsonFormatTest.testExtensionSerializationJsonMatchesProto3SpeccCs�tj�}tjddkrd|_nd|_|jdjd�7_|jtj|�d�tj�}|j	||�d}tj
||�|j|jd	�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,rr+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<rr+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/rr*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|jd<d|jd<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<rr+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,rr+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/rr*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<rr+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<rr+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,rr+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
tjt
j|d��tj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ZTestWrapperrrrrrr#r$r!r,r;r<rr+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
jtj
|d��t
jd��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<rr+r.)r&r%Zstruct_listr-r'r'r(�testStructMessage�s$




z JsonFormatTest.testStructMessagecCs�tj�}d|j_d|jj�_d|jj�_d|jj�_|j	t
jtj
|d��t
jd��tj�}|j||�|jj�|j	t
jtj
|d��t
jd��|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<rr+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�|jt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<rr+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�TestAnyZMessageTyper�Packrhr$r,r;r<rr+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<rr+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|�|jdd�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)rr*r,ZassertFalseZHasField�
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,rr+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/rr*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/rr*r�)r&r2r-r'r'r(�testIgnoreUnknownFields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assertRaisesrr1r*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ZTestMapr0rr1r*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rer0rr1r*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_r0rr1r*)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~r0rr1r*)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rvr0rr1r*)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�KeyErrorrr*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,rr+rer*)r&r%r'r'r(�testPreservingProtoFieldNames�s z,JsonFormatTest.testPreservingProtoFieldNamescCs(tj�}d|_|jdtj|dd��dS)Ni90z{
"int32Value": 12345
}r)�indent)rr/rr,rr+)r&r%r'r'r(�
testIndent�szJsonFormatTest.testIndentcCs2d}d|i}tj�}tj||�|j||j�dS)Ni90�
int32Value)rr/rrOr,r)r&�expectedZjs_dictr%r'r'r(�
testParseDict�s
zJsonFormatTest.testParseDictcCs,tj�}d|_ddi}|j|tj|��dS)Ni90r�)rr/rr,rrN)r&r%r�r'r'r(�testMessageToDict�s
z JsonFormatTest.testMessageToDictcCs8tj�}d|_|jdtj|��tj�}|j||�dS)Ni90z{
  "@value": 12345
})rZTestCustomJsonNamerr,rr+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
int64ValueZuint32ValueZstringValuer\)r�r�)rr/r,rr+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
rZgoogle.protobuf.utilrZTestCaser
r7r4�mainr'r'r'r(�<module> s<4