
XXc           @   s<  d  Z  d Z d d l Z d d l Z d d l Z y d d l Z Wn e k
 r_ d d l Z n Xd 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 e j f d     YZ d e f d     YZ e d k r8e j   n  d S(   s%   Test for google.protobuf.json_format.s   jieluo@google.com (Jie Luo)iN(   t   any_pb2(   t   duration_pb2(   t   field_mask_pb2(   t
   struct_pb2(   t   timestamp_pb2(   t   wrappers_pb2(   t   well_known_types(   t   json_format(   t   json_format_proto3_pb2t   JsonFormatBasec           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s  d | _  d | _ d | _ d | _ t d  | _ d | _ t | _ d | _	 d | _
 d	 | j _ t j | _ | j j d
  | j j d  | j j d  | j j d  | j j d  | j j d  | j j d  | j j d  | j j d  | j j d  | j j t d   | j j t  | j j t  | j j d  | j j d  | j j d  | j j d  d	 | j j   _ d | j j   _ | j j t j  | j j t j  | |  _ d  S(   Ni   iI~    I4   s   -infgo!	@t   foot   bari
   ii   I        I      iiI i    gV瞯<t   infs   Few symbols!#$,;i   (    t   int32_valuet   int64_valuet   uint32_valuet   uint64_valuet   floatt   float_valuet   double_valuet   Truet
   bool_valuet   string_valuet   bytes_valuet   message_valuet   valueR   t   BARt
   enum_valuet   repeated_int32_valuet   appendt   repeated_int64_valuet   repeated_uint32_valuet   repeated_uint64_valuet   repeated_float_valuet   repeated_double_valuet   repeated_bool_valuet   Falset   repeated_string_valuet   repeated_bytes_valuet   repeated_message_valuet   addt   repeated_enum_valuet   FOOt   message(   t   selfR+   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   FillAllFields;   sB    								c         C   s-   t  j t  j |  |  |  j | |  d  S(   N(   R   t   Parset   MessageToJsont   assertEqual(   R,   R+   t   parsed_message(    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   CheckParseBack`   s    c         C   s/   t  j   } |  j t j | t j | |  d  S(   N(   R   t   TestMessaget   assertRaisesRegexpR   t
   ParseErrorR.   (   R,   t   textt   error_messageR+   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt
   CheckErrore   s
    (   t   __name__t
   __module__R-   R2   R8   (    (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyR	   9   s   	%	t   JsonFormatTestc           B   sg  e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d    Z" d!   Z# d"   Z$ d#   Z% d$   Z& d%   Z' d&   Z( RS('   c         C   sE   t  j   } |  j t j |  d  t  j   } |  j | |  d  S(   Ns   {}(   R   R3   R0   R   R/   R2   (   R,   R+   R1   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testEmptyMessageToJsono   s
    c         C   si   t  j d d d d d g  } |  j t j t j |   t j d   t  j   } |  j | |  d  S(   NR   t   testR   iY   i   s6   {"stringValue": "test", "repeatedInt32Value": [89, 4]}(   R   R3   R0   t   jsont   loadsR   R/   R2   (   R,   R+   R1   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testPartialMessageToJsonv   s    	c         C   sz   t  j   } d } |  j |  |  j t j t j |   t j |   t  j   } t j | |  |  j | |  d  S(   Ns  {"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   R3   R-   R0   R>   R?   R   R/   R.   (   R,   R+   R6   R1   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testAllFieldsToJson   s    c         C   s   t  j   } t j d d k  r+ d | _ n! d | _ | j d j d  7_ |  j t j |  d  t  j   } |  j	 | |  d } t j
 | |  |  j | j d	  d  S(
   Ni    i   s   &
<">	\/  s   &
<">	\/s     s   utf-8s;   {
  "stringValue": "&\n<\"\r>\b\t\f\\\u0001/\u2028\u2029"
}u   {"int32Value": "1"}i   (   R   R3   t   syst   version_infoR   t   decodeR0   R   R/   R2   R.   R   (   R,   R+   R1   R6   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testJsonEscapeString   s    	c         C   s`   t  j d d  } |  j t j t j | t   t j d   t  j   } |  j | |  d  S(   NR   R
   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   R3   R0   R>   R?   R   R/   R   R2   (   R,   R+   R1   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testAlwaysSeriliaze   s    		c         C   sy   t  j   } t j d |  |  j | j d  t j d |  |  j | j d  t j d |  |  j | j d  d  S(   Ns   {"int32Value": -2.147483648e9}i   s   {"int32Value": 1e5}i s   {"int32Value": 1.0}i   (   R   R3   R   R.   R0   R   (   R,   R+   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testIntegersRepresentedAsFloat   s    c         C   s   t  j   } d | j t <d | j t <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
 t j t j | t   t j d   t  j   } |  j | |  d  S(   Ni   i   i   t   1t   nulls   {"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}}(   R   t   TestMapt   bool_mapR   R$   t	   int32_mapt	   int64_mapt
   uint32_mapt
   uint64_mapt
   string_mapR0   R>   R?   R   R/   R2   (   R,   R+   R1   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testMapFields   s$    c         C   sm   t  j   } |  j t j | t  d  d | _ |  j t j | t  d  t  j   } |  j | |  d  S(   Ns   {}i    s   {
  "oneofInt32Value": 0
}(   R   t	   TestOneofR0   R   R/   R   t   oneof_int32_valueR2   (   R,   R+   R1   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testOneofFields   s    	c         C   s_   t  j   } t j d |  |  j | j d j d d   |  j d d  |  j d d  d  S(   Ns   {"stringValue": "\uD83D\uDE01"}s   😁s   utf-8t   stricts   {"stringValue": "\uD83D"}s*   Invalid \\uXXXX escape|Unpaired.*surrogates   {"stringValue": "\uDE01"}(   R   R3   R   R.   R0   R   RD   R8   (   R,   R+   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testSurrogates  s    c         C   s  t  j   } d | j _ d | j _ d | j j   _ d | j d _ d | j j   _ d | j d _ d | j j   _ d | j d _ d | j j   _ d | j d	 _ d
 | j j   _ d | j d _ |  j t j	 t
 j | t   t j	 d   t  j   } |  j | |  d } t
 j | |  |  j | j j d  |  j | j j d  |  j | j d j d  |  j | j d j d d  d  S(   Ni    i   i   i'  i i   IA:   iɚ;i   I 	ni   s   {"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"]}s}   {"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  i g      !i   i<   ig     id  (   R   t   TestTimestampR   t   secondst   nanost   repeated_valueR(   R0   R>   R?   R   R/   R   R2   R.   (   R,   R+   R1   R6   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testTimestampMessage  s0    
c         C   s   t  j   } d | j _ d | j j   _ d | j d _ d | j j   _ d | j d _ d | j j   _ d | j d _ d | j j   _ d	 | j j   _ |  j t j	 t
 j | t   t j	 d
   t  j   } |  j | |  d  S(   Ni   i    i
   iiiا i   I b4I yI   ss   {"value": "1s","repeatedValue": [  "0.000000010s",  "-1.000001s",  "10.011s",  "-315576000000s",  "315576000000s"]}(   R   t   TestDurationR   RX   RZ   R(   RY   R0   R>   R?   R   R/   R   R2   (   R,   R+   R1   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testDurationMessage<  s    
c         C   sn   t  j   } | j j j d  | j j j d  |  j t j | t  d  t  j   } |  j	 | |  d  S(   Ns   foo.barR   s   {
  "value": "foo.bar,bar"
}(
   R   t   TestFieldMaskR   t   pathsR   R0   R   R/   R   R2   (   R,   R+   R1   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testFieldMaskMessageV  s    c         C   s   t  j   } t | j _ d | j _ d | j _ d | j _ t | j	 j
   _ t | j	 j
   _ | j j
   |  j t j t j | t   t j d   t  j   } |  j | |  d  S(   Ni    t    sR  {
  "int32Value": 0,  "boolValue": false,  "stringValue": "",  "bytesValue": "",  "repeatedBoolValue": [true, false],  "repeatedInt32Value": [0],  "repeatedUint32Value": [],  "repeatedFloatValue": [],  "repeatedDoubleValue": [],  "repeatedBytesValue": [],  "repeatedInt64Value": [],  "repeatedUint64Value": [],  "repeatedStringValue": []}(   R   t   TestWrapperR$   R   R   R   R   R   R   R#   R(   R   R0   R>   R?   R   R/   R2   (   R,   R+   R1   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testWrapperMessageb  s    c         C   s  t  j   } d | j d <d | j d <t | j d <d  | j d <d | j j d  d	 <d
 | j d d <| j j d  } | j d d t t d  g  d | j	   d <d | j
 j   d <| j
 j   |  j t j t j | t   t j d   t  j   } |  j | |  d  S(   Nt   Jimt   namei
   t   aget   attendt   emailt   SFOt   addresst   cityi   t   house_numbert   listi   t   seveni	   t   subkey2i   s   {  "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   t
   TestStructR   R   t   Nonet   get_or_create_structt   get_or_create_listt   extendR$   t
   add_structRZ   R(   R0   R>   R?   R   R/   R2   (   R,   R+   t   struct_listR1   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testStructMessage  s$    
c         C   s  t  j   } d | j _ d | j j   _ t | j j   _ d | j j   _	 |  j
 t j t j | t   t j d   t  j   } |  j | |  | j j   |  j
 t j t j | t   t j d   | j   t j d |  |  j
 | j j d  d  d  S(	   Nt   hellog333333&@i    s;   {  "value": "hello",  "repeatedValue": [11.1, false, null]}sA   {  "value": "hello",  "repeatedValue": [11.1, false, null, null]}s   {"value": null}t   kindt
   null_value(   R   t	   TestValueR   R   RZ   R(   t   number_valueR$   R   Rz   R0   R>   R?   R   R/   R2   t   ClearR.   t
   WhichOneof(   R,   R+   R1   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testValueMessage  s&    


c         C   s   t  j   } d | j j j   _ d | j j j   _ t | j j j   _ d | j j j   _	 d | j j j   j
 d <d | j j   j j   _ | j j   |  j t j t j | t   t j d   t  j   } |  j | |  d  S(   Ng333333&@i    Rx   Rd   Re   i   sS   {"value": [11.1, null, true, "hello", {"name": "Jim"}]
,"repeatedValue": [[1], []]}(   R   t   TestListValueR   t   valuesR(   R|   Rz   R   R   R   t   struct_valueRZ   R0   R>   R?   R   R/   R$   R2   (   R,   R+   R1   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testListValueMessage  s    
c         C   s@  t  j   } t  j   } t  j   } d | _ d | _ | j j |  | j j   j |  | j j   j |  | j j   |  j t j	 t
 j | t   t j	 d   t  j   } |  j | |  t  j d t d d d d d	 d d
 d d d d d  } | j   | j j |  |  j t
 j | t  d d !d  d  S(   Ni  i.  s  {
  "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   i   R   iR   R   R   gQ	@R   R
   i    iD   sD   {
  "value": {
    "@type": "type.googleapis.com/proto3.TestMessage"(   R   t   TestAnyt   MessageTypeR   t   PackRZ   R(   R0   R>   R?   R   R/   R   R2   R3   R}   R$   (   R,   R+   t   value1t   value2R1   t   test_message(    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testAnyMessage  s8    		
		
c   	      C   sx  t  j   } t j   } d | _ | j |  |  j t j t	 j
 | t   t j d   t  j   } |  j | |  t j   } | j |  |  j t j t	 j
 | t   t j d   |  j | |  t j   } d | _ | j |  |  j t j t	 j
 | t   t j d   |  j | |  t j   } | j j d  | j j d  | j |  |  j t j t	 j
 | t   t j d   |  j | |  t j   } d	 | d
 <| j |  |  j t j t	 j
 | t   t j d   |  j | |  t  j   } d | _ | j |  | j |  |  j t j t	 j
 | t   t j d   |  j | |  d  S(   Ni  sQ   {
  "@type": "type.googleapis.com/google.protobuf.Int32Value",
  "value": 1234
}
sb   {
  "@type": "type.googleapis.com/google.protobuf.Timestamp",
  "value": "1970-01-01T00:00:00Z"
}
i   sO   {
  "@type": "type.googleapis.com/google.protobuf.Duration",
  "value": "1s"
}
s   foo.barR   sY   {
  "@type": "type.googleapis.com/google.protobuf.FieldMask",
  "value": "foo.bar,bar"
}
Rd   Re   sX   {
  "@type": "type.googleapis.com/google.protobuf.Struct",
  "value": {"name": "Jim"}
}
i.  s   {
  "@type": "type.googleapis.com/google.protobuf.Any",
  "value": {
    "@type": "type.googleapis.com/google.protobuf.Int32Value",
    "value": 5678
  }
}
(   R    t   AnyR   t
   Int32ValueR   R   R0   R>   R?   R   R/   R   R2   R   t	   TimestampR   t   DurationRX   R   t	   FieldMaskR_   R   R   t   Struct(	   R,   R+   R   R1   t	   timestampt   durationt
   field_maskt   struct_messaget
   nested_any(    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testWellKnownInAnyMessage  sf    	

	



	
c         C   s   t  j   } t  j   } |  j |  t j d |  |  j | |  |  j | j d   t j d |  |  j | j d   |  j	 t j
 d t j d |  d  S(   Ns  {"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   s   {"messageValue": {}}sk   Failed to parse repeatedInt32Value field: null is not allowed to be used as an element in a repeated field.s    {"repeatedInt32Value":[1, null]}(   R   R3   R-   R   R.   R0   t   assertFalset   HasFieldt
   assertTrueR4   R5   (   R,   R+   R1   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testParseNullJ  s    	c         C   ss   t  j   } t d  | _ d } |  j t j |  |  t  j   } t j | |  |  j t	 j
 | j   d  S(   Nt   nans   {
  "floatValue": "NaN"
}(   R   R3   R   R   R0   R   R/   R.   R   t   matht   isnan(   R,   R+   R6   R1   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testNanFloatt  s    c         C   s   |  j  d d  d  S(   NRa   s1   Failed to load JSON: (Expecting value)|(No JSON).(   R8   (   R,   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testParseEmptyText}  s    	c         C   sL   t  j   } d } t j | |  d } t j | |  |  j d d  d  S(   Ns   {"enumValue": 0}s   {"enumValue": 1}s   {"enumValue": "baz"}sV   Failed to parse enumValue field: Invalid enum value baz for enum type proto3.EnumType.(   R   R3   R   R.   R8   (   R,   R+   R6   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testParseEnumValue  s    c         C   s$   |  j  d d  |  j  d d  d  S(   Ns   {int32Value: 1}sQ   Failed to load JSON: Expecting property name( enclosed in double quotes)?: line 1s   {"unknownName": 1}sC   Message type "proto3.TestMessage" has no field named "unknownName".(   R8   (   R,   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testParseBadIdentifer  s    		c         C   sT   d } t  j   } t j | | d t d } t  j   } t j | | d t d  S(   Ns   {"unknownName": 1}t   ignore_unknown_fieldssl   {
  "repeatedValue": [ {
    "@type": "type.googleapis.com/proto3.MessageType",
    "unknownName": 1
  }]
}
(   R   R3   R   R.   R   R   (   R,   R6   R1   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testIgnoreUnknownField  s    c         C   s'   t  j d k  r d  S|  j d d  d  S(   Ni   i   s!   {"int32Value": 1,
"int32Value":2}s.   Failed to load JSON: duplicate key int32Value.(   i   i   (   RB   RC   R8   (   R,   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testDuplicateField  s    	c         C   s$   |  j  d d  |  j  d d  d  S(   Ns   {"boolValue": 1}sG   Failed to parse boolValue field: Expected true or false without quotes.s   {"boolValue": "true"}(   R8   (   R,   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testInvalidBoolValue  s    		c         C   s   t  j   } d } |  j t j t j | |  |  j d d  |  j d d  |  j d d  |  j d d	  |  j d
 d  |  j d d  d  S(   Ns   {"int32Value": 0x12345}s   {"int32Value": 1.5}s>   Failed to parse int32Value field: Couldn't parse integer: 1.5.s   {"int32Value": 012345}s9   Failed 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}sK   Failed to parse int32Value field: Value out of range: 12345678901234567890.s   {"uint32Value": -1}s:   Failed to parse uint32Value field: Value out of range: -1.(   R   R3   t   assertRaisesR   R5   R.   R8   (   R,   R+   R6   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testInvalidIntegerValue  s     						c         C   s   |  j  d d  d  S(   Ns   {"floatValue": "nan"}sP   Failed to parse floatValue field: Couldn't parse float "nan", use "NaN" instead.(   R8   (   R,   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testInvalidFloatValue  s    	c         C   s$   |  j  d d  |  j  d d  d  S(   Ns   {"bytesValue": "AQI"}s4   Failed to parse bytesValue field: Incorrect padding.s   {"bytesValue": "AQI*"}(   R8   (   R,   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testInvalidBytesValue  s    		c         C   s   t  j   } d } |  j t j d t j | |  d } |  j t j d t j | |  d } |  j t j d t j | |  t j d k  r d  Sd	 } |  j t j d
 t j | |  d  S(   Ns!   {"int32Map": {"null": 2, "2": 3}}s/   Failed to parse int32Map field: invalid literals   {"int32Map": {1: 2, "2": 3}}sQ   Failed to load JSON: Expecting property name( enclosed in double quotes)?: line 1s   {"boolMap": {"null": 1}}sD   Failed to parse boolMap field: Expected "true" or "false", not null.i   i   s$   {"stringMap": {"a": 3, "\u0061": 2}}s$   Failed to load JSON: duplicate key a(   i   i   (   R   RJ   R4   R   R5   R.   RB   RC   (   R,   R+   R6   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testInvalidMap  s.    c         C   s   t  j   } d } |  j t j d t j | |  d } |  j t j d t j | |  d } |  j t j d t j | |  d } |  j t j d t j | |  d	 | j _ |  j t	 d
 t j
 |  d  S(   Ns%   {"value": "10000-01-01T00:00:00.00Z"}sK   time data '10000-01-01T00:00:00' does not match format '%Y-%m-%dT%H:%M:%S'.s/   {"value": "1970-01-01T00:00:00.0123456789012Z"}s2   nanos 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"}s2   Failed to parse value field: year is out of range.IA:   s   date value out of range(   R   RW   R4   R   R5   R.   R   R   RX   t   OverflowErrorR/   (   R,   R+   R6   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testInvalidTimestamp  s4    c         C   s5   t  j   } d } |  j t j d t j | |  d  S(   Ns/   {"oneofInt32Value": 1, "oneofStringValue": "2"}sT   Message type "proto3.TestOneof" should not have multiple "oneof_value" oneof fields.(   R   RR   R4   R   R5   R.   (   R,   R+   R6   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testInvalidOneof  s    c         C   s5   t  j   } d } |  j t j d t j | |  d  S(   Ns   {"value": 1234}sD   Failed to parse value field: ListValue must be in \[\] which is 1234(   R   R   R4   R   R5   R.   (   R,   R+   R6   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testInvalidListValue  s    c         C   s5   t  j   } d } |  j t j d t j | |  d  S(   Ns   {"value": 1234}sC   Failed to parse value field: Struct must be in a dict which is 1234(   R   Rp   R4   R   R5   R.   (   R,   R+   R6   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testInvalidStruct  s    c         C   s   t  j   } d } |  j t d t j | |  d } |  j t j d t j | |  d } |  j t d t j | |  d } t j | |  d  S(   Ns;   {"@type": "type.googleapis.com/google.protobuf.Int32Value"}R   s   {"value": 1234}s*   @type is missing when parsing any message.s?   {"@type": "type.googleapis.com/MessageNotExist", "value": 1234}sQ   Can not find message descriptor by type_url: type.googleapis.com/MessageNotExist.sN   {"@type": "incorrect.googleapis.com/google.protobuf.Int32Value","value": 1234}(   R    R   R4   t   KeyErrorR   R.   R5   t	   TypeError(   R,   R+   R6   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testInvalidAny%  s$    c         C   s   t  j   } d | _ |  j d t j |   |  j d t j | t t   t  j   } t j d |  |  j d | j  t j d |  |  j d | j  d  S(   Ni90  s   {
  "int32Value": 12345
}s   {
  "int32_value": 12345
}s   {"int32Value": 54321}i1  s   {"int32_value": 12345}(	   R   R3   R   R0   R   R/   R$   R   R.   (   R,   R+   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testPreservingProtoFieldNames<  s    			c         C   sF   d } i | d 6} t  j   } t j | |  |  j | | j  d  S(   Ni90  t
   int32Value(   R   R3   R   t	   ParseDictR0   R   (   R,   t   expectedt   js_dictR+   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testParseDictK  s
    c         C   s?   t  j   } d | _ i d d 6} |  j | t j |   d  S(   Ni90  R   (   R   R3   R   R0   R   t   MessageToDict(   R,   R+   R   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testMessageToDictR  s
    		c         C   sN   t  j   } d | _ |  j d t j |   t  j   } |  j | |  d  S(   Ni90  s   {
  "@value": 12345
}(   R   t   TestCustomJsonNameR   R0   R   R/   R2   (   R,   R+   R1   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   testJsonNameY  s    		()   R9   R:   R<   R@   RA   RE   RF   RG   RQ   RT   RV   R[   R]   R`   Rc   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   (    (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyR;   m   sN   		
	!								(				!			.	O	*																					t   __main__(   t   __doc__t
   __author__R>   R   RB   t	   unittest2t   unittestt   ImportErrort   google.protobufR    R   R   R   R   R   t   google.protobuf.internalR   R   t   google.protobuf.utilR   t   TestCaseR	   R;   R9   t   main(    (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/json_format_test.pyt   <module>!   s.   4  