• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- coding: utf-8 -*-
2# Protocol Buffers - Google's data interchange format
3# Copyright 2008 Google Inc.  All rights reserved.
4#
5# Use of this source code is governed by a BSD-style
6# license that can be found in the LICENSE file or at
7# https://developers.google.com/open-source/licenses/bsd
8
9"""Tests Nextgen Pythonic protobuf APIs."""
10
11import unittest
12
13from google.protobuf import proto_json
14from google.protobuf.util import json_format_proto3_pb2
15
16
17class ProtoJsonTest(unittest.TestCase):
18
19  def test_simple_serialize(self):
20    message = json_format_proto3_pb2.TestMessage()
21    message.int32_value = 12345
22    expected = {'int32Value': 12345}
23    self.assertEqual(expected, proto_json.serialize(message))
24
25  def test_simple_parse(self):
26    expected = 12345
27    js_dict = {'int32Value': expected}
28    message = proto_json.parse(json_format_proto3_pb2.TestMessage,
29                               js_dict)
30    self.assertEqual(expected, message.int32_value)  # pytype: disable=attribute-error
31
32
33if __name__ == "__main__":
34  unittest.main()
35