json_format_test.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 #
3 # Protocol Buffers - Google's data interchange format
4 # Copyright 2008 Google Inc. All rights reserved.
5 # https://developers.google.com/protocol-buffers/
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are
9 # met:
10 #
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following disclaimer
15 # in the documentation and/or other materials provided with the
16 # distribution.
17 # * Neither the name of Google Inc. nor the names of its
18 # contributors may be used to endorse or promote products derived from
19 # this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 """Test for google.protobuf.json_format."""
34 
35 __author__ = 'jieluo@google.com (Jie Luo)'
36 
37 import json
38 import math
39 import sys
40 
41 try:
42  import unittest2 as unittest #PY26
43 except ImportError:
44  import unittest
45 
46 from google.protobuf import any_pb2
47 from google.protobuf import duration_pb2
48 from google.protobuf import field_mask_pb2
49 from google.protobuf import struct_pb2
50 from google.protobuf import timestamp_pb2
51 from google.protobuf import wrappers_pb2
52 from google.protobuf import any_test_pb2
53 from google.protobuf import unittest_mset_pb2
54 from google.protobuf import unittest_pb2
55 from google.protobuf import descriptor_pool
56 from google.protobuf import json_format
57 from google.protobuf.util import json_format_pb2
58 from google.protobuf.util import json_format_proto3_pb2
59 
60 
61 class JsonFormatBase(unittest.TestCase):
62 
63  def FillAllFields(self, message):
64  message.int32_value = 20
65  message.int64_value = -20
66  message.uint32_value = 3120987654
67  message.uint64_value = 12345678900
68  message.float_value = float('-inf')
69  message.double_value = 3.1415
70  message.bool_value = True
71  message.string_value = 'foo'
72  message.bytes_value = b'bar'
73  message.message_value.value = 10
74  message.enum_value = json_format_proto3_pb2.BAR
75  # Repeated
76  message.repeated_int32_value.append(0x7FFFFFFF)
77  message.repeated_int32_value.append(-2147483648)
78  message.repeated_int64_value.append(9007199254740992)
79  message.repeated_int64_value.append(-9007199254740992)
80  message.repeated_uint32_value.append(0xFFFFFFF)
81  message.repeated_uint32_value.append(0x7FFFFFF)
82  message.repeated_uint64_value.append(9007199254740992)
83  message.repeated_uint64_value.append(9007199254740991)
84  message.repeated_float_value.append(0)
85 
86  message.repeated_double_value.append(1E-15)
87  message.repeated_double_value.append(float('inf'))
88  message.repeated_bool_value.append(True)
89  message.repeated_bool_value.append(False)
90  message.repeated_string_value.append('Few symbols!#$,;')
91  message.repeated_string_value.append('bar')
92  message.repeated_bytes_value.append(b'foo')
93  message.repeated_bytes_value.append(b'bar')
94  message.repeated_message_value.add().value = 10
95  message.repeated_message_value.add().value = 11
96  message.repeated_enum_value.append(json_format_proto3_pb2.FOO)
97  message.repeated_enum_value.append(json_format_proto3_pb2.BAR)
98  self.message = message
99 
100  def CheckParseBack(self, message, parsed_message):
101  json_format.Parse(json_format.MessageToJson(message),
102  parsed_message)
103  self.assertEqual(message, parsed_message)
104 
105  def CheckError(self, text, error_message):
106  message = json_format_proto3_pb2.TestMessage()
107  self.assertRaisesRegexp(
109  error_message,
110  json_format.Parse, text, message)
111 
112 
114 
116  message = json_format_proto3_pb2.TestMessage()
117  self.assertEqual(json_format.MessageToJson(message),
118  '{}')
119  parsed_message = json_format_proto3_pb2.TestMessage()
120  self.CheckParseBack(message, parsed_message)
121 
123  message = json_format_proto3_pb2.TestMessage(
124  string_value='test',
125  repeated_int32_value=[89, 4])
126  self.assertEqual(json.loads(json_format.MessageToJson(message)),
127  json.loads('{"stringValue": "test", '
128  '"repeatedInt32Value": [89, 4]}'))
129  parsed_message = json_format_proto3_pb2.TestMessage()
130  self.CheckParseBack(message, parsed_message)
131 
133  message = json_format_proto3_pb2.TestMessage()
134  text = ('{"int32Value": 20, '
135  '"int64Value": "-20", '
136  '"uint32Value": 3120987654,'
137  '"uint64Value": "12345678900",'
138  '"floatValue": "-Infinity",'
139  '"doubleValue": 3.1415,'
140  '"boolValue": true,'
141  '"stringValue": "foo",'
142  '"bytesValue": "YmFy",'
143  '"messageValue": {"value": 10},'
144  '"enumValue": "BAR",'
145  '"repeatedInt32Value": [2147483647, -2147483648],'
146  '"repeatedInt64Value": ["9007199254740992", "-9007199254740992"],'
147  '"repeatedUint32Value": [268435455, 134217727],'
148  '"repeatedUint64Value": ["9007199254740992", "9007199254740991"],'
149  '"repeatedFloatValue": [0],'
150  '"repeatedDoubleValue": [1e-15, "Infinity"],'
151  '"repeatedBoolValue": [true, false],'
152  '"repeatedStringValue": ["Few symbols!#$,;", "bar"],'
153  '"repeatedBytesValue": ["Zm9v", "YmFy"],'
154  '"repeatedMessageValue": [{"value": 10}, {"value": 11}],'
155  '"repeatedEnumValue": ["FOO", "BAR"]'
156  '}')
157  self.FillAllFields(message)
158  self.assertEqual(
159  json.loads(json_format.MessageToJson(message)),
160  json.loads(text))
161  parsed_message = json_format_proto3_pb2.TestMessage()
162  json_format.Parse(text, parsed_message)
163  self.assertEqual(message, parsed_message)
164 
166  text = '{\n "enumValue": 999\n}'
167  message = json_format_proto3_pb2.TestMessage()
168  message.enum_value = 999
169  self.assertEqual(json_format.MessageToJson(message),
170  text)
171  parsed_message = json_format_proto3_pb2.TestMessage()
172  json_format.Parse(text, parsed_message)
173  self.assertEqual(message, parsed_message)
174 
176  message = unittest_mset_pb2.TestMessageSetContainer()
177  ext1 = unittest_mset_pb2.TestMessageSetExtension1.message_set_extension
178  ext2 = unittest_mset_pb2.TestMessageSetExtension2.message_set_extension
179  message.message_set.Extensions[ext1].i = 23
180  message.message_set.Extensions[ext2].str = 'foo'
181  message_text = json_format.MessageToJson(
182  message
183  )
184  parsed_message = unittest_mset_pb2.TestMessageSetContainer()
185  json_format.Parse(message_text, parsed_message)
186  self.assertEqual(message, parsed_message)
187 
189  self.CheckError('{"[extensionField]": {}}',
190  'Message type proto3.TestMessage does not have extensions')
191 
193  message = unittest_mset_pb2.TestMessageSetContainer()
194  ext1 = unittest_mset_pb2.TestMessageSetExtension1.message_set_extension
195  ext2 = unittest_mset_pb2.TestMessageSetExtension2.message_set_extension
196  message.message_set.Extensions[ext1].i = 23
197  message.message_set.Extensions[ext2].str = 'foo'
198  message_dict = json_format.MessageToDict(
199  message
200  )
201  parsed_message = unittest_mset_pb2.TestMessageSetContainer()
202  json_format.ParseDict(message_dict, parsed_message)
203  self.assertEqual(message, parsed_message)
204 
206  message = unittest_pb2.TestAllExtensions()
207  ext1 = unittest_pb2.TestNestedExtension.test
208  message.Extensions[ext1] = 'data'
209  message_dict = json_format.MessageToDict(
210  message
211  )
212  parsed_message = unittest_pb2.TestAllExtensions()
213  json_format.ParseDict(message_dict, parsed_message)
214  self.assertEqual(message, parsed_message)
215 
217  orig_dict = {
218  'int32Value': 20,
219  '@type': 'type.googleapis.com/proto3.TestMessage'
220  }
221  copied_dict = json.loads(json.dumps(orig_dict))
222  parsed_message = any_pb2.Any()
223  json_format.ParseDict(copied_dict, parsed_message)
224  self.assertEqual(copied_dict, orig_dict)
225 
227  """See go/proto3-json-spec for spec.
228  """
229  message = unittest_mset_pb2.TestMessageSetContainer()
230  ext1 = unittest_mset_pb2.TestMessageSetExtension1.message_set_extension
231  ext2 = unittest_mset_pb2.TestMessageSetExtension2.message_set_extension
232  message.message_set.Extensions[ext1].i = 23
233  message.message_set.Extensions[ext2].str = 'foo'
234  message_dict = json_format.MessageToDict(
235  message
236  )
237  golden_dict = {
238  'messageSet': {
239  '[protobuf_unittest.'
240  'TestMessageSetExtension1.messageSetExtension]': {
241  'i': 23,
242  },
243  '[protobuf_unittest.'
244  'TestMessageSetExtension2.messageSetExtension]': {
245  'str': u'foo',
246  },
247  },
248  }
249  self.assertEqual(golden_dict, message_dict)
250 
252  """See go/proto3-json-spec for spec.
253  """
254  message = json_format_pb2.TestMessageWithExtension()
255  ext = json_format_pb2.TestExtension.ext
256  message.Extensions[ext].value = 'stuff'
257  message_dict = json_format.MessageToDict(
258  message
259  )
260  expected_dict = {
261  '[protobuf_unittest.TestExtension.ext]': {
262  'value': u'stuff',
263  },
264  }
265  self.assertEqual(expected_dict, message_dict)
266 
267 
269  """See go/proto3-json-spec for spec.
270  """
271  message = unittest_mset_pb2.TestMessageSetContainer()
272  ext1 = unittest_mset_pb2.TestMessageSetExtension1.message_set_extension
273  ext2 = unittest_mset_pb2.TestMessageSetExtension2.message_set_extension
274  message.message_set.Extensions[ext1].i = 23
275  message.message_set.Extensions[ext2].str = 'foo'
276  message_text = json_format.MessageToJson(
277  message
278  )
279  ext1_text = ('protobuf_unittest.TestMessageSetExtension1.'
280  'messageSetExtension')
281  ext2_text = ('protobuf_unittest.TestMessageSetExtension2.'
282  'messageSetExtension')
283  golden_text = ('{"messageSet": {'
284  ' "[%s]": {'
285  ' "i": 23'
286  ' },'
287  ' "[%s]": {'
288  ' "str": "foo"'
289  ' }'
290  '}}') % (ext1_text, ext2_text)
291  self.assertEqual(json.loads(golden_text), json.loads(message_text))
292 
293 
295  message = json_format_proto3_pb2.TestMessage()
296  if sys.version_info[0] < 3:
297  message.string_value = '&\n<\"\r>\b\t\f\\\001/\xe2\x80\xa8\xe2\x80\xa9'
298  else:
299  message.string_value = '&\n<\"\r>\b\t\f\\\001/'
300  message.string_value += (b'\xe2\x80\xa8\xe2\x80\xa9').decode('utf-8')
301  self.assertEqual(
302  json_format.MessageToJson(message),
303  '{\n "stringValue": '
304  '"&\\n<\\\"\\r>\\b\\t\\f\\\\\\u0001/\\u2028\\u2029"\n}')
305  parsed_message = json_format_proto3_pb2.TestMessage()
306  self.CheckParseBack(message, parsed_message)
307  text = u'{"int32Value": "\u0031"}'
308  json_format.Parse(text, message)
309  self.assertEqual(message.int32_value, 1)
310 
312  message = json_format_proto3_pb2.TestMessage(
313  string_value='foo')
314  self.assertEqual(
315  json.loads(json_format.MessageToJson(message, True)),
316  json.loads('{'
317  '"repeatedStringValue": [],'
318  '"stringValue": "foo",'
319  '"repeatedBoolValue": [],'
320  '"repeatedUint32Value": [],'
321  '"repeatedInt32Value": [],'
322  '"enumValue": "FOO",'
323  '"int32Value": 0,'
324  '"floatValue": 0,'
325  '"int64Value": "0",'
326  '"uint32Value": 0,'
327  '"repeatedBytesValue": [],'
328  '"repeatedUint64Value": [],'
329  '"repeatedDoubleValue": [],'
330  '"bytesValue": "",'
331  '"boolValue": false,'
332  '"repeatedEnumValue": [],'
333  '"uint64Value": "0",'
334  '"doubleValue": 0,'
335  '"repeatedFloatValue": [],'
336  '"repeatedInt64Value": [],'
337  '"repeatedMessageValue": []}'))
338  parsed_message = json_format_proto3_pb2.TestMessage()
339  self.CheckParseBack(message, parsed_message)
340 
342  message = json_format_proto3_pb2.TestMessage()
343  json_format.Parse('{"int32Value": -2.147483648e9}', message)
344  self.assertEqual(message.int32_value, -2147483648)
345  json_format.Parse('{"int32Value": 1e5}', message)
346  self.assertEqual(message.int32_value, 100000)
347  json_format.Parse('{"int32Value": 1.0}', message)
348  self.assertEqual(message.int32_value, 1)
349 
350  def testMapFields(self):
351  message = json_format_proto3_pb2.TestNestedMap()
352  self.assertEqual(
353  json.loads(json_format.MessageToJson(message, True)),
354  json.loads('{'
355  '"boolMap": {},'
356  '"int32Map": {},'
357  '"int64Map": {},'
358  '"uint32Map": {},'
359  '"uint64Map": {},'
360  '"stringMap": {},'
361  '"mapMap": {}'
362  '}'))
363  message.bool_map[True] = 1
364  message.bool_map[False] = 2
365  message.int32_map[1] = 2
366  message.int32_map[2] = 3
367  message.int64_map[1] = 2
368  message.int64_map[2] = 3
369  message.uint32_map[1] = 2
370  message.uint32_map[2] = 3
371  message.uint64_map[1] = 2
372  message.uint64_map[2] = 3
373  message.string_map['1'] = 2
374  message.string_map['null'] = 3
375  message.map_map['1'].bool_map[True] = 3
376  self.assertEqual(
377  json.loads(json_format.MessageToJson(message, False)),
378  json.loads('{'
379  '"boolMap": {"false": 2, "true": 1},'
380  '"int32Map": {"1": 2, "2": 3},'
381  '"int64Map": {"1": 2, "2": 3},'
382  '"uint32Map": {"1": 2, "2": 3},'
383  '"uint64Map": {"1": 2, "2": 3},'
384  '"stringMap": {"1": 2, "null": 3},'
385  '"mapMap": {"1": {"boolMap": {"true": 3}}}'
386  '}'))
387  parsed_message = json_format_proto3_pb2.TestNestedMap()
388  self.CheckParseBack(message, parsed_message)
389 
390  def testOneofFields(self):
391  message = json_format_proto3_pb2.TestOneof()
392  # Always print does not affect oneof fields.
393  self.assertEqual(
394  json_format.MessageToJson(message, True),
395  '{}')
396  message.oneof_int32_value = 0
397  self.assertEqual(
398  json_format.MessageToJson(message, True),
399  '{\n'
400  ' "oneofInt32Value": 0\n'
401  '}')
402  parsed_message = json_format_proto3_pb2.TestOneof()
403  self.CheckParseBack(message, parsed_message)
404 
405  def testSurrogates(self):
406  # Test correct surrogate handling.
407  message = json_format_proto3_pb2.TestMessage()
408  json_format.Parse('{"stringValue": "\\uD83D\\uDE01"}', message)
409  self.assertEqual(message.string_value,
410  b'\xF0\x9F\x98\x81'.decode('utf-8', 'strict'))
411 
412  # Error case: unpaired high surrogate.
413  self.CheckError(
414  '{"stringValue": "\\uD83D"}',
415  r'Invalid \\uXXXX escape|Unpaired.*surrogate')
416 
417  # Unpaired low surrogate.
418  self.CheckError(
419  '{"stringValue": "\\uDE01"}',
420  r'Invalid \\uXXXX escape|Unpaired.*surrogate')
421 
423  message = json_format_proto3_pb2.TestTimestamp()
424  message.value.seconds = 0
425  message.value.nanos = 0
426  message.repeated_value.add().seconds = 20
427  message.repeated_value[0].nanos = 1
428  message.repeated_value.add().seconds = 0
429  message.repeated_value[1].nanos = 10000
430  message.repeated_value.add().seconds = 100000000
431  message.repeated_value[2].nanos = 0
432  # Maximum time
433  message.repeated_value.add().seconds = 253402300799
434  message.repeated_value[3].nanos = 999999999
435  # Minimum time
436  message.repeated_value.add().seconds = -62135596800
437  message.repeated_value[4].nanos = 0
438  self.assertEqual(
439  json.loads(json_format.MessageToJson(message, True)),
440  json.loads('{'
441  '"value": "1970-01-01T00:00:00Z",'
442  '"repeatedValue": ['
443  ' "1970-01-01T00:00:20.000000001Z",'
444  ' "1970-01-01T00:00:00.000010Z",'
445  ' "1973-03-03T09:46:40Z",'
446  ' "9999-12-31T23:59:59.999999999Z",'
447  ' "0001-01-01T00:00:00Z"'
448  ']'
449  '}'))
450  parsed_message = json_format_proto3_pb2.TestTimestamp()
451  self.CheckParseBack(message, parsed_message)
452  text = (r'{"value": "1970-01-01T00:00:00.01+08:00",'
453  r'"repeatedValue":['
454  r' "1970-01-01T00:00:00.01+08:30",'
455  r' "1970-01-01T00:00:00.01-01:23"]}')
456  json_format.Parse(text, parsed_message)
457  self.assertEqual(parsed_message.value.seconds, -8 * 3600)
458  self.assertEqual(parsed_message.value.nanos, 10000000)
459  self.assertEqual(parsed_message.repeated_value[0].seconds, -8.5 * 3600)
460  self.assertEqual(parsed_message.repeated_value[1].seconds, 3600 + 23 * 60)
461 
463  message = json_format_proto3_pb2.TestDuration()
464  message.value.seconds = 1
465  message.repeated_value.add().seconds = 0
466  message.repeated_value[0].nanos = 10
467  message.repeated_value.add().seconds = -1
468  message.repeated_value[1].nanos = -1000
469  message.repeated_value.add().seconds = 10
470  message.repeated_value[2].nanos = 11000000
471  message.repeated_value.add().seconds = -315576000000
472  message.repeated_value.add().seconds = 315576000000
473  self.assertEqual(
474  json.loads(json_format.MessageToJson(message, True)),
475  json.loads('{'
476  '"value": "1s",'
477  '"repeatedValue": ['
478  ' "0.000000010s",'
479  ' "-1.000001s",'
480  ' "10.011s",'
481  ' "-315576000000s",'
482  ' "315576000000s"'
483  ']'
484  '}'))
485  parsed_message = json_format_proto3_pb2.TestDuration()
486  self.CheckParseBack(message, parsed_message)
487 
489  message = json_format_proto3_pb2.TestFieldMask()
490  message.value.paths.append('foo.bar')
491  message.value.paths.append('bar')
492  self.assertEqual(
493  json_format.MessageToJson(message, True),
494  '{\n'
495  ' "value": "foo.bar,bar"\n'
496  '}')
497  parsed_message = json_format_proto3_pb2.TestFieldMask()
498  self.CheckParseBack(message, parsed_message)
499 
500  message.value.Clear()
501  self.assertEqual(
502  json_format.MessageToJson(message, True),
503  '{\n'
504  ' "value": ""\n'
505  '}')
506  self.CheckParseBack(message, parsed_message)
507 
509  message = json_format_proto3_pb2.TestWrapper()
510  message.bool_value.value = False
511  message.int32_value.value = 0
512  message.string_value.value = ''
513  message.bytes_value.value = b''
514  message.repeated_bool_value.add().value = True
515  message.repeated_bool_value.add().value = False
516  message.repeated_int32_value.add()
517  self.assertEqual(
518  json.loads(json_format.MessageToJson(message, True)),
519  json.loads('{\n'
520  ' "int32Value": 0,'
521  ' "boolValue": false,'
522  ' "stringValue": "",'
523  ' "bytesValue": "",'
524  ' "repeatedBoolValue": [true, false],'
525  ' "repeatedInt32Value": [0],'
526  ' "repeatedUint32Value": [],'
527  ' "repeatedFloatValue": [],'
528  ' "repeatedDoubleValue": [],'
529  ' "repeatedBytesValue": [],'
530  ' "repeatedInt64Value": [],'
531  ' "repeatedUint64Value": [],'
532  ' "repeatedStringValue": []'
533  '}'))
534  parsed_message = json_format_proto3_pb2.TestWrapper()
535  self.CheckParseBack(message, parsed_message)
536 
537  def testStructMessage(self):
538  message = json_format_proto3_pb2.TestStruct()
539  message.value['name'] = 'Jim'
540  message.value['age'] = 10
541  message.value['attend'] = True
542  message.value['email'] = None
543  message.value.get_or_create_struct('address')['city'] = 'SFO'
544  message.value['address']['house_number'] = 1024
545  message.value.get_or_create_struct('empty_struct')
546  message.value.get_or_create_list('empty_list')
547  struct_list = message.value.get_or_create_list('list')
548  struct_list.extend([6, 'seven', True, False, None])
549  struct_list.add_struct()['subkey2'] = 9
550  message.repeated_value.add()['age'] = 11
551  message.repeated_value.add()
552  self.assertEqual(
553  json.loads(json_format.MessageToJson(message, False)),
554  json.loads(
555  '{'
556  ' "value": {'
557  ' "address": {'
558  ' "city": "SFO", '
559  ' "house_number": 1024'
560  ' }, '
561  ' "empty_struct": {}, '
562  ' "empty_list": [], '
563  ' "age": 10, '
564  ' "name": "Jim", '
565  ' "attend": true, '
566  ' "email": null, '
567  ' "list": [6, "seven", true, false, null, {"subkey2": 9}]'
568  ' },'
569  ' "repeatedValue": [{"age": 11}, {}]'
570  '}'))
571  parsed_message = json_format_proto3_pb2.TestStruct()
572  self.CheckParseBack(message, parsed_message)
573  # check for regression; this used to raise
574  parsed_message.value['empty_struct']
575  parsed_message.value['empty_list']
576 
577  def testValueMessage(self):
578  message = json_format_proto3_pb2.TestValue()
579  message.value.string_value = 'hello'
580  message.repeated_value.add().number_value = 11.1
581  message.repeated_value.add().bool_value = False
582  message.repeated_value.add().null_value = 0
583  self.assertEqual(
584  json.loads(json_format.MessageToJson(message, False)),
585  json.loads(
586  '{'
587  ' "value": "hello",'
588  ' "repeatedValue": [11.1, false, null]'
589  '}'))
590  parsed_message = json_format_proto3_pb2.TestValue()
591  self.CheckParseBack(message, parsed_message)
592  # Can't parse back if the Value message is not set.
593  message.repeated_value.add()
594  self.assertEqual(
595  json.loads(json_format.MessageToJson(message, False)),
596  json.loads(
597  '{'
598  ' "value": "hello",'
599  ' "repeatedValue": [11.1, false, null, null]'
600  '}'))
601  message.Clear()
602  json_format.Parse('{"value": null}', message)
603  self.assertEqual(message.value.WhichOneof('kind'), 'null_value')
604 
606  message = json_format_proto3_pb2.TestListValue()
607  message.value.values.add().number_value = 11.1
608  message.value.values.add().null_value = 0
609  message.value.values.add().bool_value = True
610  message.value.values.add().string_value = 'hello'
611  message.value.values.add().struct_value['name'] = 'Jim'
612  message.repeated_value.add().values.add().number_value = 1
613  message.repeated_value.add()
614  self.assertEqual(
615  json.loads(json_format.MessageToJson(message, False)),
616  json.loads(
617  '{"value": [11.1, null, true, "hello", {"name": "Jim"}]\n,'
618  '"repeatedValue": [[1], []]}'))
619  parsed_message = json_format_proto3_pb2.TestListValue()
620  self.CheckParseBack(message, parsed_message)
621 
622  def testAnyMessage(self):
623  message = json_format_proto3_pb2.TestAny()
624  value1 = json_format_proto3_pb2.MessageType()
625  value2 = json_format_proto3_pb2.MessageType()
626  value1.value = 1234
627  value2.value = 5678
628  message.value.Pack(value1)
629  message.repeated_value.add().Pack(value1)
630  message.repeated_value.add().Pack(value2)
631  message.repeated_value.add()
632  self.assertEqual(
633  json.loads(json_format.MessageToJson(message, True)),
634  json.loads(
635  '{\n'
636  ' "repeatedValue": [ {\n'
637  ' "@type": "type.googleapis.com/proto3.MessageType",\n'
638  ' "value": 1234\n'
639  ' }, {\n'
640  ' "@type": "type.googleapis.com/proto3.MessageType",\n'
641  ' "value": 5678\n'
642  ' },\n'
643  ' {}],\n'
644  ' "value": {\n'
645  ' "@type": "type.googleapis.com/proto3.MessageType",\n'
646  ' "value": 1234\n'
647  ' }\n'
648  '}\n'))
649  parsed_message = json_format_proto3_pb2.TestAny()
650  self.CheckParseBack(message, parsed_message)
651  # Must print @type first
652  test_message = json_format_proto3_pb2.TestMessage(
653  bool_value=True,
654  int32_value=20,
655  int64_value=-20,
656  uint32_value=20,
657  uint64_value=20,
658  double_value=3.14,
659  string_value='foo')
660  message.Clear()
661  message.value.Pack(test_message)
662  self.assertEqual(
663  json_format.MessageToJson(message, False)[0:68],
664  '{\n'
665  ' "value": {\n'
666  ' "@type": "type.googleapis.com/proto3.TestMessage"')
667 
669  packed_message = unittest_pb2.OneString()
670  packed_message.data = 'string'
671  message = any_test_pb2.TestAny()
672  message.any_value.Pack(packed_message)
673  empty_pool = descriptor_pool.DescriptorPool()
674  with self.assertRaises(TypeError) as cm:
675  json_format.MessageToJson(message, True, descriptor_pool=empty_pool)
676  self.assertEqual(
677  'Can not find message descriptor by type_url:'
678  ' type.googleapis.com/protobuf_unittest.OneString.',
679  str(cm.exception))
680 
682  message = any_pb2.Any()
683  int32_value = wrappers_pb2.Int32Value()
684  int32_value.value = 1234
685  message.Pack(int32_value)
686  self.assertEqual(
687  json.loads(json_format.MessageToJson(message, True)),
688  json.loads(
689  '{\n'
690  ' "@type": \"type.googleapis.com/google.protobuf.Int32Value\",\n'
691  ' "value": 1234\n'
692  '}\n'))
693  parsed_message = any_pb2.Any()
694  self.CheckParseBack(message, parsed_message)
695 
696  timestamp = timestamp_pb2.Timestamp()
697  message.Pack(timestamp)
698  self.assertEqual(
699  json.loads(json_format.MessageToJson(message, True)),
700  json.loads(
701  '{\n'
702  ' "@type": "type.googleapis.com/google.protobuf.Timestamp",\n'
703  ' "value": "1970-01-01T00:00:00Z"\n'
704  '}\n'))
705  self.CheckParseBack(message, parsed_message)
706 
707  duration = duration_pb2.Duration()
708  duration.seconds = 1
709  message.Pack(duration)
710  self.assertEqual(
711  json.loads(json_format.MessageToJson(message, True)),
712  json.loads(
713  '{\n'
714  ' "@type": "type.googleapis.com/google.protobuf.Duration",\n'
715  ' "value": "1s"\n'
716  '}\n'))
717  self.CheckParseBack(message, parsed_message)
718 
719  field_mask = field_mask_pb2.FieldMask()
720  field_mask.paths.append('foo.bar')
721  field_mask.paths.append('bar')
722  message.Pack(field_mask)
723  self.assertEqual(
724  json.loads(json_format.MessageToJson(message, True)),
725  json.loads(
726  '{\n'
727  ' "@type": "type.googleapis.com/google.protobuf.FieldMask",\n'
728  ' "value": "foo.bar,bar"\n'
729  '}\n'))
730  self.CheckParseBack(message, parsed_message)
731 
732  struct_message = struct_pb2.Struct()
733  struct_message['name'] = 'Jim'
734  message.Pack(struct_message)
735  self.assertEqual(
736  json.loads(json_format.MessageToJson(message, True)),
737  json.loads(
738  '{\n'
739  ' "@type": "type.googleapis.com/google.protobuf.Struct",\n'
740  ' "value": {"name": "Jim"}\n'
741  '}\n'))
742  self.CheckParseBack(message, parsed_message)
743 
744  nested_any = any_pb2.Any()
745  int32_value.value = 5678
746  nested_any.Pack(int32_value)
747  message.Pack(nested_any)
748  self.assertEqual(
749  json.loads(json_format.MessageToJson(message, True)),
750  json.loads(
751  '{\n'
752  ' "@type": "type.googleapis.com/google.protobuf.Any",\n'
753  ' "value": {\n'
754  ' "@type": "type.googleapis.com/google.protobuf.Int32Value",\n'
755  ' "value": 5678\n'
756  ' }\n'
757  '}\n'))
758  self.CheckParseBack(message, parsed_message)
759 
760  def testParseNull(self):
761  message = json_format_proto3_pb2.TestMessage()
762  parsed_message = json_format_proto3_pb2.TestMessage()
763  self.FillAllFields(parsed_message)
764  json_format.Parse('{"int32Value": null, '
765  '"int64Value": null, '
766  '"uint32Value": null,'
767  '"uint64Value": null,'
768  '"floatValue": null,'
769  '"doubleValue": null,'
770  '"boolValue": null,'
771  '"stringValue": null,'
772  '"bytesValue": null,'
773  '"messageValue": null,'
774  '"enumValue": null,'
775  '"repeatedInt32Value": null,'
776  '"repeatedInt64Value": null,'
777  '"repeatedUint32Value": null,'
778  '"repeatedUint64Value": null,'
779  '"repeatedFloatValue": null,'
780  '"repeatedDoubleValue": null,'
781  '"repeatedBoolValue": null,'
782  '"repeatedStringValue": null,'
783  '"repeatedBytesValue": null,'
784  '"repeatedMessageValue": null,'
785  '"repeatedEnumValue": null'
786  '}',
787  parsed_message)
788  self.assertEqual(message, parsed_message)
789  # Null and {} should have different behavior for sub message.
790  self.assertFalse(parsed_message.HasField('message_value'))
791  json_format.Parse('{"messageValue": {}}', parsed_message)
792  self.assertTrue(parsed_message.HasField('message_value'))
793  # Null is not allowed to be used as an element in repeated field.
794  self.assertRaisesRegexp(
796  'Failed to parse repeatedInt32Value field: '
797  'null is not allowed to be used as an element in a repeated field.',
798  json_format.Parse,
799  '{"repeatedInt32Value":[1, null]}',
800  parsed_message)
801  self.CheckError('{"repeatedMessageValue":[null]}',
802  'Failed to parse repeatedMessageValue field: null is not'
803  ' allowed to be used as an element in a repeated field.')
804 
805  def testNanFloat(self):
806  message = json_format_proto3_pb2.TestMessage()
807  message.float_value = float('nan')
808  text = '{\n "floatValue": "NaN"\n}'
809  self.assertEqual(json_format.MessageToJson(message), text)
810  parsed_message = json_format_proto3_pb2.TestMessage()
811  json_format.Parse(text, parsed_message)
812  self.assertTrue(math.isnan(parsed_message.float_value))
813 
815  message = json_format_proto3_pb2.TestMessage()
816  text = ('{"repeatedFloatValue": [3.4028235e+39, 1.4028235e-39]\n}')
817  json_format.Parse(text, message)
818  self.assertEqual(message.repeated_float_value[0], float('inf'))
819  self.assertAlmostEqual(message.repeated_float_value[1], 1.4028235e-39)
820 
822  self.CheckError('',
823  r'Failed to load JSON: (Expecting value)|(No JSON).')
824 
826  message = json_format_proto3_pb2.TestMessage()
827  text = '{"enumValue": 0}'
828  json_format.Parse(text, message)
829  text = '{"enumValue": 1}'
830  json_format.Parse(text, message)
831  self.CheckError(
832  '{"enumValue": "baz"}',
833  'Failed to parse enumValue field: Invalid enum value baz '
834  'for enum type proto3.EnumType.')
835  # Proto3 accepts numeric unknown enums.
836  text = '{"enumValue": 12345}'
837  json_format.Parse(text, message)
838  # Proto2 does not accept unknown enums.
839  message = unittest_pb2.TestAllTypes()
840  self.assertRaisesRegexp(
842  'Failed to parse optionalNestedEnum field: Invalid enum value 12345 '
843  'for enum type protobuf_unittest.TestAllTypes.NestedEnum.',
844  json_format.Parse, '{"optionalNestedEnum": 12345}', message)
845 
847  self.CheckError('{int32Value: 1}',
848  (r'Failed to load JSON: Expecting property name'
849  r'( enclosed in double quotes)?: line 1'))
850  self.CheckError('{"unknownName": 1}',
851  'Message type "proto3.TestMessage" has no field named '
852  '"unknownName".')
853 
855  text = '{"unknownName": 1}'
856  parsed_message = json_format_proto3_pb2.TestMessage()
857  json_format.Parse(text, parsed_message, ignore_unknown_fields=True)
858  text = ('{\n'
859  ' "repeatedValue": [ {\n'
860  ' "@type": "type.googleapis.com/proto3.MessageType",\n'
861  ' "unknownName": 1\n'
862  ' }]\n'
863  '}\n')
864  parsed_message = json_format_proto3_pb2.TestAny()
865  json_format.Parse(text, parsed_message, ignore_unknown_fields=True)
866 
868  self.CheckError('{"int32Value": 1,\n"int32Value":2}',
869  'Failed to load JSON: duplicate key int32Value.')
870 
872  self.CheckError('{"boolValue": 1}',
873  'Failed to parse boolValue field: '
874  'Expected true or false without quotes.')
875  self.CheckError('{"boolValue": "true"}',
876  'Failed to parse boolValue field: '
877  'Expected true or false without quotes.')
878 
880  message = json_format_proto3_pb2.TestMessage()
881  text = '{"int32Value": 0x12345}'
882  self.assertRaises(json_format.ParseError,
883  json_format.Parse, text, message)
884  self.CheckError('{"int32Value": 1.5}',
885  'Failed to parse int32Value field: '
886  'Couldn\'t parse integer: 1.5.')
887  self.CheckError('{"int32Value": 012345}',
888  (r'Failed to load JSON: Expecting \'?,\'? delimiter: '
889  r'line 1.'))
890  self.CheckError('{"int32Value": " 1 "}',
891  'Failed to parse int32Value field: '
892  'Couldn\'t parse integer: " 1 ".')
893  self.CheckError('{"int32Value": "1 "}',
894  'Failed to parse int32Value field: '
895  'Couldn\'t parse integer: "1 ".')
896  self.CheckError('{"int32Value": 12345678901234567890}',
897  'Failed to parse int32Value field: Value out of range: '
898  '12345678901234567890.')
899  self.CheckError('{"uint32Value": -1}',
900  'Failed to parse uint32Value field: '
901  'Value out of range: -1.')
902 
904  self.CheckError('{"floatValue": "nan"}',
905  'Failed to parse floatValue field: Couldn\'t '
906  'parse float "nan", use "NaN" instead.')
907 
909  self.CheckError('{"bytesValue": "AQI"}',
910  'Failed to parse bytesValue field: Incorrect padding.')
911  self.CheckError('{"bytesValue": "AQI*"}',
912  'Failed to parse bytesValue field: Incorrect padding.')
913 
915  self.CheckError('{"repeatedInt32Value": 12345}',
916  (r'Failed to parse repeatedInt32Value field: repeated field'
917  r' repeatedInt32Value must be in \[\] which is 12345.'))
918 
919  def testInvalidMap(self):
920  message = json_format_proto3_pb2.TestMap()
921  text = '{"int32Map": {"null": 2, "2": 3}}'
922  self.assertRaisesRegexp(
924  'Failed to parse int32Map field: invalid literal',
925  json_format.Parse, text, message)
926  text = '{"int32Map": {1: 2, "2": 3}}'
927  self.assertRaisesRegexp(
929  (r'Failed to load JSON: Expecting property name'
930  r'( enclosed in double quotes)?: line 1'),
931  json_format.Parse, text, message)
932  text = '{"boolMap": {"null": 1}}'
933  self.assertRaisesRegexp(
935  'Failed to parse boolMap field: Expected "true" or "false", not null.',
936  json_format.Parse, text, message)
937  if sys.version_info < (2, 7):
938  return
939  text = r'{"stringMap": {"a": 3, "\u0061": 2}}'
940  self.assertRaisesRegexp(
942  'Failed to load JSON: duplicate key a',
943  json_format.Parse, text, message)
944  text = r'{"stringMap": 0}'
945  self.assertRaisesRegexp(
947  'Failed to parse stringMap field: Map field string_map must be '
948  'in a dict which is 0.',
949  json_format.Parse, text, message)
950 
952  message = json_format_proto3_pb2.TestTimestamp()
953  text = '{"value": "10000-01-01T00:00:00.00Z"}'
954  self.assertRaisesRegexp(
956  'Failed to parse value field: '
957  'time data \'10000-01-01T00:00:00\' does not match'
958  ' format \'%Y-%m-%dT%H:%M:%S\'.',
959  json_format.Parse, text, message)
960  text = '{"value": "1970-01-01T00:00:00.0123456789012Z"}'
961  self.assertRaisesRegexp(
963  'nanos 0123456789012 more than 9 fractional digits.',
964  json_format.Parse, text, message)
965  text = '{"value": "1972-01-01T01:00:00.01+08"}'
966  self.assertRaisesRegexp(
968  (r'Invalid timezone offset value: \+08.'),
969  json_format.Parse, text, message)
970  # Time smaller than minimum time.
971  text = '{"value": "0000-01-01T00:00:00Z"}'
972  self.assertRaisesRegexp(
974  'Failed to parse value field: year (0 )?is out of range.',
975  json_format.Parse, text, message)
976  # Time bigger than maxinum time.
977  message.value.seconds = 253402300800
978  self.assertRaisesRegexp(
979  OverflowError,
980  'date value out of range',
981  json_format.MessageToJson, message)
982 
983  def testInvalidOneof(self):
984  message = json_format_proto3_pb2.TestOneof()
985  text = '{"oneofInt32Value": 1, "oneofStringValue": "2"}'
986  self.assertRaisesRegexp(
988  'Message type "proto3.TestOneof"'
989  ' should not have multiple "oneof_value" oneof fields.',
990  json_format.Parse, text, message)
991 
993  message = json_format_proto3_pb2.TestListValue()
994  text = '{"value": 1234}'
995  self.assertRaisesRegexp(
997  r'Failed to parse value field: ListValue must be in \[\] which is 1234',
998  json_format.Parse, text, message)
999 
1001  message = json_format_proto3_pb2.TestStruct()
1002  text = '{"value": 1234}'
1003  self.assertRaisesRegexp(
1005  'Failed to parse value field: Struct must be in a dict which is 1234',
1006  json_format.Parse, text, message)
1007 
1008  def testInvalidAny(self):
1009  message = any_pb2.Any()
1010  text = '{"@type": "type.googleapis.com/google.protobuf.Int32Value"}'
1011  self.assertRaisesRegexp(
1012  KeyError,
1013  'value',
1014  json_format.Parse, text, message)
1015  text = '{"value": 1234}'
1016  self.assertRaisesRegexp(
1018  '@type is missing when parsing any message.',
1019  json_format.Parse, text, message)
1020  text = '{"@type": "type.googleapis.com/MessageNotExist", "value": 1234}'
1021  self.assertRaisesRegexp(
1022  TypeError,
1023  'Can not find message descriptor by type_url: '
1024  'type.googleapis.com/MessageNotExist.',
1025  json_format.Parse, text, message)
1026  # Only last part is to be used: b/25630112
1027  text = (r'{"@type": "incorrect.googleapis.com/google.protobuf.Int32Value",'
1028  r'"value": 1234}')
1029  json_format.Parse(text, message)
1030 
1032  message = json_format_proto3_pb2.TestMessage()
1033  message.int32_value = 12345
1034  self.assertEqual('{\n "int32Value": 12345\n}',
1035  json_format.MessageToJson(message))
1036  self.assertEqual('{\n "int32_value": 12345\n}',
1037  json_format.MessageToJson(message, False, True))
1038  # When including_default_value_fields is True.
1039  message = json_format_proto3_pb2.TestTimestamp()
1040  self.assertEqual('{\n "repeatedValue": []\n}',
1041  json_format.MessageToJson(message, True, False))
1042  self.assertEqual('{\n "repeated_value": []\n}',
1043  json_format.MessageToJson(message, True, True))
1044 
1045  # Parsers accept both original proto field names and lowerCamelCase names.
1046  message = json_format_proto3_pb2.TestMessage()
1047  json_format.Parse('{"int32Value": 54321}', message)
1048  self.assertEqual(54321, message.int32_value)
1049  json_format.Parse('{"int32_value": 12345}', message)
1050  self.assertEqual(12345, message.int32_value)
1051 
1052  def testIndent(self):
1053  message = json_format_proto3_pb2.TestMessage()
1054  message.int32_value = 12345
1055  self.assertEqual('{\n"int32Value": 12345\n}',
1056  json_format.MessageToJson(message, indent=0))
1057 
1059  message = json_format_proto3_pb2.TestMessage()
1060  message.enum_value = json_format_proto3_pb2.BAR
1061  message.repeated_enum_value.append(json_format_proto3_pb2.FOO)
1062  message.repeated_enum_value.append(json_format_proto3_pb2.BAR)
1063  self.assertEqual(json.loads('{\n'
1064  ' "enumValue": 1,\n'
1065  ' "repeatedEnumValue": [0, 1]\n'
1066  '}\n'),
1067  json.loads(json_format.MessageToJson(
1068  message, use_integers_for_enums=True)))
1069 
1070  def testParseDict(self):
1071  expected = 12345
1072  js_dict = {'int32Value': expected}
1073  message = json_format_proto3_pb2.TestMessage()
1074  json_format.ParseDict(js_dict, message)
1075  self.assertEqual(expected, message.int32_value)
1076 
1078  # Confirm that ParseDict does not raise ParseError with default pool
1079  js_dict = {
1080  'any_value': {
1081  '@type': 'type.googleapis.com/proto3.MessageType',
1082  'value': 1234
1083  }
1084  }
1085  json_format.ParseDict(js_dict, any_test_pb2.TestAny())
1086  # Check ParseDict raises ParseError with empty pool
1087  js_dict = {
1088  'any_value': {
1089  '@type': 'type.googleapis.com/proto3.MessageType',
1090  'value': 1234
1091  }
1092  }
1093  with self.assertRaises(json_format.ParseError) as cm:
1094  empty_pool = descriptor_pool.DescriptorPool()
1095  json_format.ParseDict(js_dict,
1096  any_test_pb2.TestAny(),
1097  descriptor_pool=empty_pool)
1098  self.assertEqual(
1099  str(cm.exception),
1100  'Failed to parse any_value field: Can not find message descriptor by'
1101  ' type_url: type.googleapis.com/proto3.MessageType..')
1102 
1104  message = json_format_proto3_pb2.TestMessage()
1105  message.int32_value = 12345
1106  expected = {'int32Value': 12345}
1107  self.assertEqual(expected,
1108  json_format.MessageToDict(message))
1109 
1110  def testJsonName(self):
1111  message = json_format_proto3_pb2.TestCustomJsonName()
1112  message.value = 12345
1113  self.assertEqual('{\n "@value": 12345\n}',
1114  json_format.MessageToJson(message))
1115  parsed_message = json_format_proto3_pb2.TestCustomJsonName()
1116  self.CheckParseBack(message, parsed_message)
1117 
1118  def testSortKeys(self):
1119  # Testing sort_keys is not perfectly working, as by random luck we could
1120  # get the output sorted. We just use a selection of names.
1121  message = json_format_proto3_pb2.TestMessage(bool_value=True,
1122  int32_value=1,
1123  int64_value=3,
1124  uint32_value=4,
1125  string_value='bla')
1126  self.assertEqual(
1127  json_format.MessageToJson(message, sort_keys=True),
1128  # We use json.dumps() instead of a hardcoded string due to differences
1129  # between Python 2 and Python 3.
1130  json.dumps({'boolValue': True, 'int32Value': 1, 'int64Value': '3',
1131  'uint32Value': 4, 'stringValue': 'bla'},
1132  indent=2, sort_keys=True))
1133 
1134 
1135 if __name__ == '__main__':
1136  unittest.main()
google::protobuf.internal.json_format_test.JsonFormatTest.testParseDict
def testParseDict(self)
Definition: json_format_test.py:1070
google::protobuf.internal.json_format_test.JsonFormatTest.testExtensionSerializationJsonMatchesProto3Spec
def testExtensionSerializationJsonMatchesProto3Spec(self)
Definition: json_format_test.py:268
google::protobuf.internal.json_format_test.JsonFormatTest.testWrapperMessage
def testWrapperMessage(self)
Definition: json_format_test.py:508
google::protobuf.internal.json_format_test.JsonFormatTest.testDuplicateField
def testDuplicateField(self)
Definition: json_format_test.py:867
google::protobuf.internal.json_format_test.JsonFormatTest.testInvalidOneof
def testInvalidOneof(self)
Definition: json_format_test.py:983
google::protobuf.internal.json_format_test.JsonFormatTest.testExtensionToDictAndBack
def testExtensionToDictAndBack(self)
Definition: json_format_test.py:192
google::protobuf.internal.json_format_test.JsonFormatTest.testInvalidAny
def testInvalidAny(self)
Definition: json_format_test.py:1008
google::protobuf.internal.json_format_test.JsonFormatTest.testWellKnownInAnyMessage
def testWellKnownInAnyMessage(self)
Definition: json_format_test.py:681
google::protobuf.internal.json_format_test.JsonFormatTest.testInvalidIntegerValue
def testInvalidIntegerValue(self)
Definition: json_format_test.py:879
google::protobuf.internal.json_format_test.JsonFormatTest.testInvalidStruct
def testInvalidStruct(self)
Definition: json_format_test.py:1000
google::protobuf.internal.json_format_test.JsonFormatTest.testParseNull
def testParseNull(self)
Definition: json_format_test.py:760
google::protobuf.internal.json_format_test.JsonFormatTest.testParseDictAnyDescriptorPoolMissingType
def testParseDictAnyDescriptorPoolMissingType(self)
Definition: json_format_test.py:1077
google::protobuf.internal.json_format_test.JsonFormatTest.testIndent
def testIndent(self)
Definition: json_format_test.py:1052
google::protobuf.internal.json_format_test.JsonFormatBase.FillAllFields
def FillAllFields(self, message)
Definition: json_format_test.py:63
google::protobuf
Definition: data_proto2_to_proto3_util.h:12
google::protobuf.internal.json_format_test.JsonFormatTest.testInvalidListValue
def testInvalidListValue(self)
Definition: json_format_test.py:992
google::protobuf.internal.json_format_test.JsonFormatBase.CheckParseBack
def CheckParseBack(self, message, parsed_message)
Definition: json_format_test.py:100
google::protobuf.internal.json_format_test.JsonFormatTest.testPartialMessageToJson
def testPartialMessageToJson(self)
Definition: json_format_test.py:122
google::protobuf.internal.json_format_test.JsonFormatTest.testUnknownEnumToJsonAndBack
def testUnknownEnumToJsonAndBack(self)
Definition: json_format_test.py:165
google::protobuf.internal.json_format_test.JsonFormatTest.testExtensionSerializationDictMatchesProto3SpecMore
def testExtensionSerializationDictMatchesProto3SpecMore(self)
Definition: json_format_test.py:251
google::protobuf.internal.json_format_test.JsonFormatTest.testJsonEscapeString
def testJsonEscapeString(self)
Definition: json_format_test.py:294
google::protobuf::util
Definition: data_proto2_to_proto3_util.h:13
google::protobuf.internal.json_format_test.JsonFormatTest.testStructMessage
def testStructMessage(self)
Definition: json_format_test.py:537
google::protobuf.internal.json_format_test.JsonFormatTest.testJsonParseDictToAnyDoesNotAlterInput
def testJsonParseDictToAnyDoesNotAlterInput(self)
Definition: json_format_test.py:216
google::protobuf.internal.json_format_test.JsonFormatTest.testIgnoreUnknownField
def testIgnoreUnknownField(self)
Definition: json_format_test.py:854
google::protobuf.internal.json_format_test.JsonFormatTest.testMessageToDict
def testMessageToDict(self)
Definition: json_format_test.py:1103
google::protobuf.internal.json_format_test.JsonFormatTest.testEmptyMessageToJson
def testEmptyMessageToJson(self)
Definition: json_format_test.py:115
google::protobuf.internal.json_format_test.JsonFormatTest.testFieldMaskMessage
def testFieldMaskMessage(self)
Definition: json_format_test.py:488
google::protobuf.internal.json_format_test.JsonFormatBase.message
message
Definition: json_format_test.py:98
update_failure_list.str
str
Definition: update_failure_list.py:41
google::protobuf.internal.json_format_test.JsonFormatTest.testParseEmptyText
def testParseEmptyText(self)
Definition: json_format_test.py:821
google::protobuf.internal.json_format_test.JsonFormatBase
Definition: json_format_test.py:61
google::protobuf.internal.json_format_test.JsonFormatTest.testInvalidFloatValue
def testInvalidFloatValue(self)
Definition: json_format_test.py:903
google::protobuf.internal.json_format_test.JsonFormatTest.testJsonName
def testJsonName(self)
Definition: json_format_test.py:1110
google::protobuf.internal.json_format_test.JsonFormatTest.testListValueMessage
def testListValueMessage(self)
Definition: json_format_test.py:605
google::protobuf.internal.json_format_test.JsonFormatTest.testInvalidMap
def testInvalidMap(self)
Definition: json_format_test.py:919
google::protobuf.internal.json_format_test.JsonFormatTest.testAllFieldsToJson
def testAllFieldsToJson(self)
Definition: json_format_test.py:132
google::protobuf.internal.json_format_test.JsonFormatTest.testParseDoubleToFloat
def testParseDoubleToFloat(self)
Definition: json_format_test.py:814
google::protobuf.internal.json_format_test.JsonFormatTest.testIntegersRepresentedAsFloat
def testIntegersRepresentedAsFloat(self)
Definition: json_format_test.py:341
google::protobuf.internal.json_format_test.JsonFormatTest.testTimestampMessage
def testTimestampMessage(self)
Definition: json_format_test.py:422
google::protobuf.internal.json_format_test.JsonFormatTest.testSurrogates
def testSurrogates(self)
Definition: json_format_test.py:405
google::protobuf.internal.json_format_test.JsonFormatTest.testExtensionToDictAndBackWithScalar
def testExtensionToDictAndBackWithScalar(self)
Definition: json_format_test.py:205
google::protobuf.internal.json_format_test.JsonFormatTest.testExtensionSerializationDictMatchesProto3Spec
def testExtensionSerializationDictMatchesProto3Spec(self)
Definition: json_format_test.py:226
google::protobuf.internal.json_format_test.JsonFormatTest
Definition: json_format_test.py:113
google::protobuf.internal.json_format_test.JsonFormatTest.testMapFields
def testMapFields(self)
Definition: json_format_test.py:350
google::protobuf.internal.json_format_test.JsonFormatTest.testAlwaysSeriliaze
def testAlwaysSeriliaze(self)
Definition: json_format_test.py:311
google::protobuf.internal.json_format_test.JsonFormatTest.testDurationMessage
def testDurationMessage(self)
Definition: json_format_test.py:462
google::protobuf.internal.json_format_test.JsonFormatTest.testAnyMessage
def testAnyMessage(self)
Definition: json_format_test.py:622
google::protobuf.internal.json_format_test.JsonFormatTest.testExtensionToJsonAndBack
def testExtensionToJsonAndBack(self)
Definition: json_format_test.py:175
google::protobuf.internal.json_format_test.JsonFormatTest.testInvalidRepeated
def testInvalidRepeated(self)
Definition: json_format_test.py:914
google::protobuf.descriptor_pool.DescriptorPool
Definition: descriptor_pool.py:102
google::protobuf.internal.json_format_test.JsonFormatTest.testAnyMessageDescriptorPoolMissingType
def testAnyMessageDescriptorPoolMissingType(self)
Definition: json_format_test.py:668
google::protobuf.internal.json_format_test.JsonFormatTest.testInvalidBoolValue
def testInvalidBoolValue(self)
Definition: json_format_test.py:871
google::protobuf.internal.json_format_test.JsonFormatTest.testFormatEnumsAsInts
def testFormatEnumsAsInts(self)
Definition: json_format_test.py:1058
google::protobuf.internal.json_format_test.JsonFormatTest.testPreservingProtoFieldNames
def testPreservingProtoFieldNames(self)
Definition: json_format_test.py:1031
google::protobuf.internal.json_format_test.JsonFormatTest.testNanFloat
def testNanFloat(self)
Definition: json_format_test.py:805
google::protobuf.internal.json_format_test.JsonFormatBase.CheckError
def CheckError(self, text, error_message)
Definition: json_format_test.py:105
google::protobuf.internal.json_format_test.JsonFormatTest.testParseBadIdentifer
def testParseBadIdentifer(self)
Definition: json_format_test.py:846
google::protobuf.json_format.ParseError
Definition: json_format.py:95
google::protobuf.internal.json_format_test.JsonFormatTest.testSortKeys
def testSortKeys(self)
Definition: json_format_test.py:1118
google::protobuf.internal.json_format_test.JsonFormatTest.testValueMessage
def testValueMessage(self)
Definition: json_format_test.py:577
google::protobuf.internal.json_format_test.JsonFormatTest.testOneofFields
def testOneofFields(self)
Definition: json_format_test.py:390
google::protobuf.internal.json_format_test.JsonFormatTest.testInvalidBytesValue
def testInvalidBytesValue(self)
Definition: json_format_test.py:908
google::protobuf.internal.json_format_test.JsonFormatTest.testParseEnumValue
def testParseEnumValue(self)
Definition: json_format_test.py:825
google::protobuf.internal.json_format_test.JsonFormatTest.testExtensionErrors
def testExtensionErrors(self)
Definition: json_format_test.py:188
google::protobuf.internal.json_format_test.JsonFormatTest.testInvalidTimestamp
def testInvalidTimestamp(self)
Definition: json_format_test.py:951


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:55