o
    ØŹh¹¬  ć                   @   s  d Z dZddlZddlZddlZzddlZW n ey#   ddlZY nw ddlm	Z	 ddlm
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ G dd dejZG dd deZedkre ”  dS dS )z%Test for google.protobuf.json_format.zjieluo@google.com (Jie Luo)é    N)Śany_pb2)Śduration_pb2)Śfield_mask_pb2)Ś
struct_pb2)Śtimestamp_pb2)Śwrappers_pb2)Śany_test_pb2)Śunittest_mset_pb2)Śunittest_pb2)Śwell_known_types©Śdescriptor_pool)Śjson_format)Śjson_format_proto3_pb2c                   @   s$   e Zd Zdd Zdd Zdd ZdS )ŚJsonFormatBasec                 C   sX  d|_ d|_d|_d|_td|_d|_d|_d|_d	|_	d
|j
_tj|_|j d” |j d” |j d” |j d” |j d” |j d” |j d” |j d” |j d” |j d” |j td” |j d” |j d” |j d” |j d” |j d” |j d	” d
|j ” _d|j ” _|j tj” |j tj” || _d S )Né   éģ’’’l   ~t l   4ø? z-infgoĄŹ!	@TŚfoos   baré
   i’’’é   l          lü’’’       i’’’i’’’l   ’’’’ r   gVēÆŅ<ŚinfFzFew symbols!#$,;Śbars   fooé   )Śint32_valueŚint64_valueŚuint32_valueŚuint64_valueŚfloatŚfloat_valueŚdouble_valueŚ
bool_valueŚstring_valueŚbytes_valueŚmessage_valueŚvaluer   ŚBARŚ
enum_valueŚrepeated_int32_valueŚappendŚrepeated_int64_valueŚrepeated_uint32_valueŚrepeated_uint64_valueŚrepeated_float_valueŚrepeated_double_valueŚrepeated_bool_valueŚrepeated_string_valueŚrepeated_bytes_valueŚrepeated_message_valueŚaddŚrepeated_enum_valueŚFOOŚmessage©Śselfr5   © r8   ś[/var/www/html/env/lib/python3.10/site-packages/google/protobuf/internal/json_format_test.pyŚFillAllFields?   sB   

zJsonFormatBase.FillAllFieldsc                 C   s"   t  t  |”|” |  ||” d S ©N)r   ŚParseŚMessageToJsonŚassertEqual©r7   r5   Śparsed_messager8   r8   r9   ŚCheckParseBackd   s   ’zJsonFormatBase.CheckParseBackc                 C   s"   t  ” }|  tj|tj||” d S r;   )r   ŚTestMessageŚassertRaisesRegexpr   Ś
ParseErrorr<   )r7   ŚtextŚerror_messager5   r8   r8   r9   Ś
CheckErrori   s   żzJsonFormatBase.CheckErrorN)Ś__name__Ś
__module__Ś__qualname__r:   rA   rG   r8   r8   r8   r9   r   =   s    %r   c                   @   s¬  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;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` Z2dadb Z3dcdd Z4dedf Z5dgdh Z6diS )jŚJsonFormatTestc                 C   s2   t  ” }|  t |”d” t  ” }|  ||” d S )Nś{})r   rB   r>   r   r=   rA   r?   r8   r8   r9   ŚtestEmptyMessageToJsons   s   ’z%JsonFormatTest.testEmptyMessageToJsonc                 C   sH   t jdddgd}|  t t |””t d”” t  ” }|  ||” d S )NŚtestéY   é   )r!   r'   z6{"stringValue": "test", "repeatedInt32Value": [89, 4]}©r   rB   r>   ŚjsonŚloadsr   r=   rA   r?   r8   r8   r9   ŚtestPartialMessageToJsonz   s   ž’z'JsonFormatTest.testPartialMessageToJsonc                 C   sX   t  ” }d}|  |” |  t t |””t |”” t  ” }t ||” |  ||” d S )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   rB   r:   r>   rR   rS   r   r=   r<   ©r7   r5   rE   r@   r8   r8   r9   ŚtestAllFieldsToJson   s   
žz"JsonFormatTest.testAllFieldsToJsonc                 C   sH   d}t  ” }d|_|  t |”|” t  ” }t ||” |  ||” d S )Nz{
  "enumValue": 999
}iē  )r   rB   r&   r>   r   r=   r<   )r7   rE   r5   r@   r8   r8   r9   ŚtestUnknownEnumToJsonAndBack„   s   ’z+JsonFormatTest.testUnknownEnumToJsonAndBackc                 C   ób   t  ” }t jj}t jj}d|jj| _d|jj| _t	 
|”}t  ” }t	 ||” |  ||” d S ©Né   r   )r	   ŚTestMessageSetContainerŚTestMessageSetExtension1Śmessage_set_extensionŚTestMessageSetExtension2Śmessage_setŚ
ExtensionsŚiŚstrr   r=   r<   r>   )r7   r5   Śext1Śext2Śmessage_textr@   r8   r8   r9   ŚtestExtensionToJsonAndBackÆ   ó   ’z)JsonFormatTest.testExtensionToJsonAndBackc                 C   ó   |   dd” d S )Nz{"[extensionField]": {}}z8Message type proto3.TestMessage does not have extensions©rG   ©r7   r8   r8   r9   ŚtestExtensionErrors¼   ó   ’z"JsonFormatTest.testExtensionErrorsc                 C   rX   rY   )r	   r[   r\   r]   r^   r_   r`   ra   rb   r   ŚMessageToDictŚ	ParseDictr>   )r7   r5   rc   rd   Śmessage_dictr@   r8   r8   r9   ŚtestExtensionToDictAndBackĄ   rg   z)JsonFormatTest.testExtensionToDictAndBackc                 C   s>   ddd}t  t  |””}t ” }t ||” |  ||” d S )Nr   z&type.googleapis.com/proto3.TestMessage)Ś
int32Valueś@type)rR   rS   Śdumpsr   ŚAnyr   rn   r>   )r7   Ś	orig_dictŚcopied_dictr@   r8   r8   r9   Ś'testJsonParseDictToAnyDoesNotAlterInputĶ   s   žz6JsonFormatTest.testJsonParseDictToAnyDoesNotAlterInputc                 C   sd   t  ” }t jj}t jj}d|jj| _d|jj| _t	 
|”}dddiddidi}|  ||” dS )ś&See go/proto3-json-spec for spec.
    rZ   r   Ś
messageSetra   rb   )z@[protobuf_unittest.TestMessageSetExtension1.messageSetExtension]z@[protobuf_unittest.TestMessageSetExtension2.messageSetExtension]N)r	   r[   r\   r]   r^   r_   r`   ra   rb   r   rm   r>   )r7   r5   rc   rd   ro   Śgolden_dictr8   r8   r9   Ś/testExtensionSerializationDictMatchesProto3Spec×   s    ’’’ś’z>JsonFormatTest.testExtensionSerializationDictMatchesProto3Specc                 C   sn   t  ” }t jj}t jj}d|jj| _d|jj| _t	 
|”}d}d}d||f }|  t |”t |”” dS )rx   rZ   r   z>protobuf_unittest.TestMessageSetExtension1.messageSetExtensionz>protobuf_unittest.TestMessageSetExtension2.messageSetExtensionzZ{"messageSet": {    "[%s]": {        "i": 23    },    "[%s]": {        "str": "foo"    }}}N)r	   r[   r\   r]   r^   r_   r`   ra   rb   r   r=   r>   rR   rS   )r7   r5   rc   rd   re   Ś	ext1_textŚ	ext2_textŚgolden_textr8   r8   r9   Ś/testExtensionSerializationJsonMatchesProto3Specń   s   ’łz>JsonFormatTest.testExtensionSerializationJsonMatchesProto3Specc                 C   s   t  ” }tjd dk rd|_nd|_| jd d”7  _|  t |”d” t  ” }|  	||” d}t 
||” |  |jd	” d S )
Nr   é   u   &
<">	\/Ć¢ĀĀØĆ¢ĀĀ©z&
<">	\/s   āØā©śutf-8z;{
  "stringValue": "&\n<\"\r>\b\t\f\\\u0001/\u2028\u2029"
}z{"int32Value": "1"}é   )r   rB   ŚsysŚversion_infor!   Śdecoder>   r   r=   rA   r<   r   ©r7   r5   r@   rE   r8   r8   r9   ŚtestJsonEscapeString  s   žz#JsonFormatTest.testJsonEscapeStringc                 C   sD   t jdd}|  t t |d””t d”” t  ” }|  ||” d S )Nr   )r!   TaĖ  {"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": []}rQ   r?   r8   r8   r9   ŚtestAlwaysSeriliaze  s   ’žz"JsonFormatTest.testAlwaysSeriliazec                 C   sZ   t  ” }t d|” |  |jd” t d|” |  |jd” t d|” |  |jd” d S )Nz{"int32Value": -2.147483648e9}r   z{"int32Value": 1e5}i  z{"int32Value": 1.0}r   )r   rB   r   r<   r>   r   r6   r8   r8   r9   ŚtestIntegersRepresentedAsFloat:  s   z-JsonFormatTest.testIntegersRepresentedAsFloatc                 C   sč   t  ” }|  t t |d””t d”” 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d< d|jd< d|jd< d|jd< d|jd jd< |  t t |d””t d	”” t  ” }|  ||” d S )
NTzj{"boolMap": {},"int32Map": {},"int64Map": {},"uint32Map": {},"uint64Map": {},"stringMap": {},"mapMap": {}}r   é   Fr   Ś1Śnullzå{"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   ŚTestNestedMapr>   rR   rS   r   r=   Śbool_mapŚ	int32_mapŚ	int64_mapŚ
uint32_mapŚ
uint64_mapŚ
string_mapŚmap_maprA   r?   r8   r8   r9   ŚtestMapFieldsC  s0   ž











žzJsonFormatTest.testMapFieldsc                 C   sN   t  ” }|  t |d”d” d|_|  t |d”d” t  ” }|  ||” d S )NTrL   r   z{
  "oneofInt32Value": 0
})r   Ś	TestOneofr>   r   r=   Śoneof_int32_valuerA   r?   r8   r8   r9   ŚtestOneofFieldsk  s   
ž
žzJsonFormatTest.testOneofFieldsc                 C   sF   t  ” }t d|” |  |jd dd”” |  dd” |  dd” d S )Nz{"stringValue": "\uD83D\uDE01"}s   šr   Śstrictz{"stringValue": "\uD83D"}z*Invalid \\uXXXX escape|Unpaired.*surrogatez{"stringValue": "\uDE01"})r   rB   r   r<   r>   r!   r   rG   r6   r8   r8   r9   ŚtestSurrogatesz  s   
’žžzJsonFormatTest.testSurrogatesc                 C   s   t  ” }d|j_d|j_d|j ” _d|jd _d|j ” _d|jd _d|j ” _d|jd _d|j ” _d|jd	 _d
|j ” _d|jd _|  t 	t
 |d””t 	d”” t  ” }|  ||” d}t
 ||” |  |jjd” |  |jjd” |  |jd jd” |  |jd jd” d S )Nr   r   r   i'  i įõr   l   Ačė i’É;r   lż’’’ w#o9 rP   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"]}i’’i g     āŻĄit  )r   ŚTestTimestampr$   ŚsecondsŚnanosŚrepeated_valuer2   r>   rR   rS   r   r=   rA   r<   r   r8   r8   r9   ŚtestTimestampMessage  s2   žz#JsonFormatTest.testTimestampMessagec                 C   sØ   t  ” }d|j_d|j ” _d|jd _d|j ” _d|jd _d|j ” _d|jd _d|j ” _d	|j ” _|  t 	t
 |d
””t 	d”” t  ” }|  ||” d S )Nr   r   r   é’’’’iü’’iĄŲ§ r   lż’’’ s%l    s%Tzs{"value": "1s","repeatedValue": [  "0.000000010s",  "-1.000001s",  "10.011s",  "-315576000000s",  "315576000000s"]})r   ŚTestDurationr$   r   r   r2   r   r>   rR   rS   r   r=   rA   r?   r8   r8   r9   ŚtestDurationMessage³  s    žz"JsonFormatTest.testDurationMessagec                 C   sP   t  ” }|jj d” |jj d” |  t |d”d” t  ” }|  ||” d S )Nśfoo.barr   Tz{
  "value": "foo.bar,bar"
})	r   ŚTestFieldMaskr$   Śpathsr(   r>   r   r=   rA   r?   r8   r8   r9   ŚtestFieldMaskMessageĶ  s   
žz#JsonFormatTest.testFieldMaskMessagec                 C   s   t  ” }d|j_d|j_d|j_d|j_d|j ” _d|j ” _|j	 ”  |  
t t |d””t d”” t  ” }|  ||” d S )NFr   Ś ó    TaR  {
  "int32Value": 0,  "boolValue": false,  "stringValue": "",  "bytesValue": "",  "repeatedBoolValue": [true, false],  "repeatedInt32Value": [0],  "repeatedUint32Value": [],  "repeatedFloatValue": [],  "repeatedDoubleValue": [],  "repeatedBytesValue": [],  "repeatedInt64Value": [],  "repeatedUint64Value": [],  "repeatedStringValue": []})r   ŚTestWrapperr    r$   r   r!   r"   r.   r2   r'   r>   rR   rS   r   r=   rA   r?   r8   r8   r9   ŚtestWrapperMessageŁ  s   
žz!JsonFormatTest.testWrapperMessagec                 C   sš   t  ” }d|jd< d|jd< d|jd< d |jd< d|j d	”d
< d|jd	 d< |j d” |j d” |j d”}| g d¢” d| ” d< d|j ” d< |j ”  |  	t
 t |d””t
 d”” t  ” }|  ||” |jd  |jd  d S )NŚJimŚnamer   ŚageTŚattendŚemailŚSFOŚaddressŚcityi   Śhouse_numberŚempty_structŚ
empty_listŚlist)é   ŚsevenTFNé	   Śsubkey2r   Fa.  {  "value": {    "address": {      "city": "SFO",       "house_number": 1024    },     "empty_struct": {},     "empty_list": [],     "age": 10,     "name": "Jim",     "attend": true,     "email": null,     "list": [6, "seven", true, false, null, {"subkey2": 9}]  },  "repeatedValue": [{"age": 11}, {}]})r   Ś
TestStructr$   Śget_or_create_structŚget_or_create_listŚextendŚ
add_structr   r2   r>   rR   rS   r   r=   rA   )r7   r5   Śstruct_listr@   r8   r8   r9   ŚtestStructMessageö  s0   




’ž
z JsonFormatTest.testStructMessagec                 C   s¾   t  ” }d|j_d|j ” _d|j ” _d|j ” _|  	t
 t |d””t
 d”” t  ” }|  ||” |j ”  |  	t
 t |d””t
 d”” | ”  t d|” |  	|j d”d	” d S )
NŚhelloē333333&@Fr   z;{  "value": "hello",  "repeatedValue": [11.1, false, null]}zA{  "value": "hello",  "repeatedValue": [11.1, false, null, null]}z{"value": null}ŚkindŚ
null_value)r   Ś	TestValuer$   r!   r   r2   Śnumber_valuer    rÅ   r>   rR   rS   r   r=   rA   ŚClearr<   Ś
WhichOneofr?   r8   r8   r9   ŚtestValueMessage  s.   ’ž
’žzJsonFormatTest.testValueMessagec                 C   s¦   t  ” }d|jj ” _d|jj ” _d|jj ” _d|jj ” _d|jj ” j	d< d|j
 ” j ” _|j
 ”  |  t t |d””t d	”” t  ” }|  ||” d S )
NrĆ   r   TrĀ   r«   r¬   r   FzS{"value": [11.1, null, true, "hello", {"name": "Jim"}]
,"repeatedValue": [[1], []]})r   ŚTestListValuer$   Śvaluesr2   rĒ   rÅ   r    r!   Śstruct_valuer   r>   rR   rS   r   r=   rA   r?   r8   r8   r9   ŚtestListValueMessage:  s    
’žz#JsonFormatTest.testListValueMessagec              	   C   sŚ   t  ” }t  ” }t  ” }d|_d|_|j |” |j ”  |” |j ”  |” |j ”  |  t 	t
 |d””t 	d”” t  ” }|  ||” t jdddddddd	}| ”  |j |” |  t
 |d
”dd d” d S )NéŅ  é.  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
  }
}
r   r   gėQø	@r   )r    r   r   r   r   r   r!   Fr   éD   zD{
  "value": {
    "@type": "type.googleapis.com/proto3.TestMessage")r   ŚTestAnyŚMessageTyper$   ŚPackr   r2   r>   rR   rS   r   r=   rA   rB   rČ   )r7   r5   Śvalue1Śvalue2r@   Śtest_messager8   r8   r9   ŚtestAnyMessageK  s@   
’žłžzJsonFormatTest.testAnyMessagec                 C   sz   t  ” }d|_t ” }|j |” t ” }|  	t
”}tj|d|d W d    n1 s-w   Y  |  dt|j” d S )NŚstringTr   z]Can not find message descriptor by type_url: type.googleapis.com/protobuf_unittest.OneString.)r
   Ś	OneStringŚdatar   rŅ   Ś	any_valuerŌ   r   ŚDescriptorPoolŚassertRaisesŚ	TypeErrorr   r=   r>   rb   Ś	exception)r7   Śpacked_messager5   Ś
empty_poolŚcmr8   r8   r9   Ś'testAnyMessageDescriptorPoolMissingTypey  s   ’żz6JsonFormatTest.testAnyMessageDescriptorPoolMissingTypec           	      C   sÄ  t  ” }t ” }d|_| |” |  t t	 
|d””t d”” t  ” }|  ||” t ” }| |” |  t t	 
|d””t d”” |  ||” t ” }d|_| |” |  t t	 
|d””t d”” |  ||” t ” }|j d” |j d” | |” |  t t	 
|d””t d	”” |  ||” t ” }d
|d< | |” |  t t	 
|d””t d”” |  ||” t  ” }d|_| |” | |” |  t t	 
|d””t d”” |  ||” d S )NrĻ   TzQ{
  "@type": "type.googleapis.com/google.protobuf.Int32Value",
  "value": 1234
}
zb{
  "@type": "type.googleapis.com/google.protobuf.Timestamp",
  "value": "1970-01-01T00:00:00Z"
}
r   zO{
  "@type": "type.googleapis.com/google.protobuf.Duration",
  "value": "1s"
}
r£   r   zY{
  "@type": "type.googleapis.com/google.protobuf.FieldMask",
  "value": "foo.bar,bar"
}
r«   r¬   zX{
  "@type": "type.googleapis.com/google.protobuf.Struct",
  "value": {"name": "Jim"}
}
rŠ   z{
  "@type": "type.googleapis.com/google.protobuf.Any",
  "value": {
    "@type": "type.googleapis.com/google.protobuf.Int32Value",
    "value": 5678
  }
}
)r   rt   r   Ś
Int32Valuer$   rŌ   r>   rR   rS   r   r=   rA   r   Ś	Timestampr   ŚDurationr   r   Ś	FieldMaskr„   r(   r   ŚStruct)	r7   r5   r   r@   Ś	timestampŚdurationŚ
field_maskŚstruct_messageŚ
nested_anyr8   r8   r9   ŚtestWellKnownInAnyMessage  s~   
’ž
’ž
’ž
’ž
’ž

’ž
z(JsonFormatTest.testWellKnownInAnyMessagec                 C   s   t  ” }t  ” }|  |” t d|” |  ||” |  | d”” t d|” |  | d”” |  	tj
dtjd|” |  dd” d S )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}r#   z{"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   rB   r:   r   r<   r>   ŚassertFalseŚHasFieldŚ
assertTruerC   rD   rG   r?   r8   r8   r9   ŚtestParseNullÕ  s(   
éś’zJsonFormatTest.testParseNullc                 C   sR   t  ” }td|_d}|  t |”|” t  ” }t ||” |  t	 
|j”” d S )NŚnanz{
  "floatValue": "NaN"
})r   rB   r   r   r>   r   r=   r<   rņ   ŚmathŚisnanrU   r8   r8   r9   ŚtestNanFloat  s   
zJsonFormatTest.testNanFloatc                 C   rh   )Nr§   z1Failed to load JSON: (Expecting value)|(No JSON).ri   rj   r8   r8   r9   ŚtestParseEmptyText  rl   z!JsonFormatTest.testParseEmptyTextc                 C   sf   t  ” }d}t ||” d}t ||” |  dd” d}t ||” t ” }|  tjdtjd|” d S )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   rB   r   r<   rG   r
   ŚTestAllTypesrC   rD   ©r7   r5   rE   r8   r8   r9   ŚtestParseEnumValue  s"   žüz!JsonFormatTest.testParseEnumValuec                 C   s   |   dd” |   dd” d S )Nz{int32Value: 1}śQFailed to load JSON: Expecting property name( enclosed in double quotes)?: line 1ś{"unknownName": 1}zCMessage type "proto3.TestMessage" has no field named "unknownName".ri   rj   r8   r8   r9   ŚtestParseBadIdentifer$  ó   ’’z$JsonFormatTest.testParseBadIdentiferc                 C   s<   d}t  ” }tj||dd d}t  ” }tj||dd d S )Nrż   T)Śignore_unknown_fieldszl{
  "repeatedValue": [ {
    "@type": "type.googleapis.com/proto3.MessageType",
    "unknownName": 1
  }]
}
)r   rB   r   r<   rŅ   )r7   rE   r@   r8   r8   r9   ŚtestIgnoreUnknownField,  s   z%JsonFormatTest.testIgnoreUnknownFieldc                 C   rh   )Nz!{"int32Value": 1,
"int32Value":2}z.Failed to load JSON: duplicate key int32Value.ri   rj   r8   r8   r9   ŚtestDuplicateField9  rl   z!JsonFormatTest.testDuplicateFieldc                 C   ó   |   dd” |   dd” d S )Nz{"boolValue": 1}zGFailed to parse boolValue field: Expected true or false without quotes.z{"boolValue": "true"}ri   rj   r8   r8   r9   ŚtestInvalidBoolValue=  r’   z#JsonFormatTest.testInvalidBoolValuec                 C   sl   t  ” }d}|  tjtj||” |  dd” |  dd” |  dd” |  dd	” |  d
d” |  dd” d S )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   rB   rŽ   r   rD   r<   rG   rś   r8   r8   r9   ŚtestInvalidIntegerValueE  s.   ’’’’’’’z&JsonFormatTest.testInvalidIntegerValuec                 C   rh   )Nz{"floatValue": "nan"}zPFailed to parse floatValue field: Couldn't parse float "nan", use "NaN" instead.ri   rj   r8   r8   r9   ŚtestInvalidFloatValue]  rl   z$JsonFormatTest.testInvalidFloatValuec                 C   r  )Nz{"bytesValue": "AQI"}z4Failed to parse bytesValue field: Incorrect padding.z{"bytesValue": "AQI*"}ri   rj   r8   r8   r9   ŚtestInvalidBytesValueb  s   ’’z$JsonFormatTest.testInvalidBytesValuec                 C   rh   )Nz{"repeatedInt32Value": 12345}zkFailed to parse repeatedInt32Value field: repeated field repeatedInt32Value must be in \[\] which is 12345.ri   rj   r8   r8   r9   ŚtestInvalidRepeatedh  rl   z"JsonFormatTest.testInvalidRepeatedc                 C   s   t  ” }d}|  tjdtj||” d}|  tjdtj||” d}|  tjdtj||” tjdk r2d S d}|  tjd	tj||” d
}|  tjdtj||” d S )Nz!{"int32Map": {"null": 2, "2": 3}}z/Failed to parse int32Map field: invalid literalz{"int32Map": {1: 2, "2": 3}}rü   z{"boolMap": {"null": 1}}zDFailed to parse boolMap field: Expected "true" or "false", not null.)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   ŚTestMaprC   r   rD   r<   r   r   rś   r8   r8   r9   ŚtestInvalidMapm  sB   żüż
żüzJsonFormatTest.testInvalidMapc                 C   s   t  ” }d}|  tjdtj||” d}|  tjdtj||” d}|  tjdtj||” d}|  tjdtj||” d	|j_|  t	d
tj
|” d S )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čė zdate value out of range)r   r   rC   r   rD   r<   r   r$   r   ŚOverflowErrorr=   rś   r8   r8   r9   ŚtestInvalidTimestamp  s>   üżżżżz#JsonFormatTest.testInvalidTimestampc                 C   ó&   t  ” }d}|  tjdtj||” d S )Nz/{"oneofInt32Value": 1, "oneofStringValue": "2"}zTMessage type "proto3.TestOneof" should not have multiple "oneof_value" oneof fields.)r   r   rC   r   rD   r<   rś   r8   r8   r9   ŚtestInvalidOneof¬  s   üzJsonFormatTest.testInvalidOneofc                 C   r  )Nś{"value": 1234}zDFailed to parse value field: ListValue must be in \[\] which is 1234)r   rĖ   rC   r   rD   r<   rś   r8   r8   r9   ŚtestInvalidListValueµ  ó   żz#JsonFormatTest.testInvalidListValuec                 C   r  )Nr  zCFailed to parse value field: Struct must be in a dict which is 1234)r   r»   rC   r   rD   r<   rś   r8   r8   r9   ŚtestInvalidStruct½  r  z JsonFormatTest.testInvalidStructc                 C   sf   t  ” }d}|  tdtj||” d}|  tjdtj||” d}|  tdtj||” d}t ||” d S )Nz;{"@type": "type.googleapis.com/google.protobuf.Int32Value"}r$   r  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})r   rt   rC   ŚKeyErrorr   r<   rD   rß   rś   r8   r8   r9   ŚtestInvalidAnyÅ  s*   żżüzJsonFormatTest.testInvalidAnyc                 C   sŖ   t  ” }d|_|  dt |”” |  dt |dd”” t  ” }|  dt |dd”” |  dt |dd”” t  ” }t d|” |  d	|j” t d
|” |  d|j” d S )Né90  z{
  "int32Value": 12345
}z{
  "int32_value": 12345
}FTz{
  "repeatedValue": []
}z{
  "repeated_value": []
}z{"int32Value": 54321}i1Ō  z{"int32_value": 12345})r   rB   r   r>   r   r=   r   r<   r6   r8   r8   r9   ŚtestPreservingProtoFieldNamesÜ  s(   ’’’’z,JsonFormatTest.testPreservingProtoFieldNamesc                 C   s(   t  ” }d|_|  dtj|dd” d S )Nr  z{
"int32Value": 12345
}r   )Śindent)r   rB   r   r>   r   r=   r6   r8   r8   r9   Ś
testIndentń  s
   ’zJsonFormatTest.testIndentc              	   C   sR   t  ” }t j|_|j t j” |j t j” |  t 	d”t 	t
j|dd”” d S )Nz4{
  "enumValue": 1,
  "repeatedEnumValue": [0, 1]
}
T)Śuse_integers_for_enums)r   rB   r%   r&   r3   r(   r4   r>   rR   rS   r   r=   r6   r8   r8   r9   ŚtestFormatEnumsAsInts÷  s   ’üz$JsonFormatTest.testFormatEnumsAsIntsc                 C   s2   d}d|i}t  ” }t ||” |  ||j” d S ©Nr  rq   )r   rB   r   rn   r>   r   )r7   ŚexpectedŚjs_dictr5   r8   r8   r9   ŚtestParseDict  s
   zJsonFormatTest.testParseDictc                 C   s   ddddi}t  |t ” ” ddddi}|  t j”}t ” }t j|t ” |d W d    n1 s5w   Y  |  t	|j
d” d S )NrÜ   z&type.googleapis.com/proto3.MessageTyperĻ   )rr   r$   r   zvFailed to parse any_value field: Can not find message descriptor by type_url: type.googleapis.com/proto3.MessageType..)r   rn   r   rŅ   rŽ   rD   r   rŻ   r>   rb   rą   )r7   r  rć   rā   r8   r8   r9   Ś)testParseDictAnyDescriptorPoolMissingType
  s,   ž’ž’žžžz8JsonFormatTest.testParseDictAnyDescriptorPoolMissingTypec                 C   s,   t  ” }d|_ddi}|  |t |”” d S r  )r   rB   r   r>   r   rm   )r7   r5   r  r8   r8   r9   ŚtestMessageToDict$  s   ’z JsonFormatTest.testMessageToDictc                 C   s8   t  ” }d|_|  dt |”” t  ” }|  ||” d S )Nr  z{
  "@value": 12345
})r   ŚTestCustomJsonNamer$   r>   r   r=   rA   r?   r8   r8   r9   ŚtestJsonName+  s   ’zJsonFormatTest.testJsonNamec              
   C   sF   t jdddddd}|  tj|ddtjdddddd	d
dd” d S )NTr   r   rP   Śbla)r    r   r   r   r!   )Ś	sort_keysŚ3)Ś	boolValuerq   Ś
int64ValueŚuint32ValueŚstringValuer   )r  r%  )r   rB   r>   r   r=   rR   rs   r6   r8   r8   r9   ŚtestSortKeys3  s   ü
’žüzJsonFormatTest.testSortKeysN)7rH   rI   rJ   rM   rT   rV   rW   rf   rk   rp   rw   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  r  r  r  r  r  r  r  r  r  r   r!  r#  r+  r8   r8   r8   r9   rK   q   sj    
!

	(((.O-	 	rK   Ś__main__)Ś__doc__Ś
__author__rR   rõ   r   Ś	unittest2ŚunittestŚImportErrorŚgoogle.protobufr   r   r   r   r   r   r   r	   r
   Śgoogle.protobuf.internalr   r   r   Śgoogle.protobuf.utilr   ŚTestCaser   rK   rH   Śmainr8   r8   r8   r9   Ś<module>   sF    ’4       Z’