PHP 8.2.30
Preview: symbol_database_test.py Size: 5.50 KB
/lib/python2.7/site-packages/google/protobuf/internal/symbol_database_test.py

#
# Protocol Buffers - Google's data interchange format
# Copyright 2008 Google Inc.  All rights reserved.
# https://developers.google.com/protocol-buffers/
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
#     * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#     * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""Tests for google.protobuf.symbol_database."""

try:
  import unittest2 as unittest  #PY26
except ImportError:
  import unittest

from google.protobuf import unittest_pb2
from google.protobuf import descriptor
from google.protobuf import descriptor_pool
from google.protobuf import symbol_database


class SymbolDatabaseTest(unittest.TestCase):

  def _Database(self):
    if descriptor._USE_C_DESCRIPTORS:
      # The C++ implementation does not allow mixing descriptors from
      # different pools.
      db = symbol_database.SymbolDatabase(pool=descriptor_pool.Default())
    else:
      db = symbol_database.SymbolDatabase()
    # Register representative types from unittest_pb2.
    db.RegisterFileDescriptor(unittest_pb2.DESCRIPTOR)
    db.RegisterMessage(unittest_pb2.TestAllTypes)
    db.RegisterMessage(unittest_pb2.TestAllTypes.NestedMessage)
    db.RegisterMessage(unittest_pb2.TestAllTypes.OptionalGroup)
    db.RegisterMessage(unittest_pb2.TestAllTypes.RepeatedGroup)
    db.RegisterEnumDescriptor(unittest_pb2.ForeignEnum.DESCRIPTOR)
    db.RegisterEnumDescriptor(unittest_pb2.TestAllTypes.NestedEnum.DESCRIPTOR)
    db.RegisterServiceDescriptor(unittest_pb2._TESTSERVICE)
    return db

  def testGetPrototype(self):
    instance = self._Database().GetPrototype(
        unittest_pb2.TestAllTypes.DESCRIPTOR)
    self.assertTrue(instance is unittest_pb2.TestAllTypes)

  def testGetMessages(self):
    messages = self._Database().GetMessages(
        ['google/protobuf/unittest.proto'])
    self.assertTrue(
        unittest_pb2.TestAllTypes is
        messages['protobuf_unittest.TestAllTypes'])

  def testGetSymbol(self):
    self.assertEqual(
        unittest_pb2.TestAllTypes, self._Database().GetSymbol(
            'protobuf_unittest.TestAllTypes'))
    self.assertEqual(
        unittest_pb2.TestAllTypes.NestedMessage, self._Database().GetSymbol(
            'protobuf_unittest.TestAllTypes.NestedMessage'))
    self.assertEqual(
        unittest_pb2.TestAllTypes.OptionalGroup, self._Database().GetSymbol(
            'protobuf_unittest.TestAllTypes.OptionalGroup'))
    self.assertEqual(
        unittest_pb2.TestAllTypes.RepeatedGroup, self._Database().GetSymbol(
            'protobuf_unittest.TestAllTypes.RepeatedGroup'))

  def testEnums(self):
    # Check registration of types in the pool.
    self.assertEqual(
        'protobuf_unittest.ForeignEnum',
        self._Database().pool.FindEnumTypeByName(
            'protobuf_unittest.ForeignEnum').full_name)
    self.assertEqual(
        'protobuf_unittest.TestAllTypes.NestedEnum',
        self._Database().pool.FindEnumTypeByName(
            'protobuf_unittest.TestAllTypes.NestedEnum').full_name)

  def testFindMessageTypeByName(self):
    self.assertEqual(
        'protobuf_unittest.TestAllTypes',
        self._Database().pool.FindMessageTypeByName(
            'protobuf_unittest.TestAllTypes').full_name)
    self.assertEqual(
        'protobuf_unittest.TestAllTypes.NestedMessage',
        self._Database().pool.FindMessageTypeByName(
            'protobuf_unittest.TestAllTypes.NestedMessage').full_name)

  def testFindServiceByName(self):
    self.assertEqual(
        'protobuf_unittest.TestService',
        self._Database().pool.FindServiceByName(
            'protobuf_unittest.TestService').full_name)

  def testFindFileContainingSymbol(self):
    # Lookup based on either enum or message.
    self.assertEqual(
        'google/protobuf/unittest.proto',
        self._Database().pool.FindFileContainingSymbol(
            'protobuf_unittest.TestAllTypes.NestedEnum').name)
    self.assertEqual(
        'google/protobuf/unittest.proto',
        self._Database().pool.FindFileContainingSymbol(
            'protobuf_unittest.TestAllTypes').name)

  def testFindFileByName(self):
    self.assertEqual(
        'google/protobuf/unittest.proto',
        self._Database().pool.FindFileByName(
            'google/protobuf/unittest.proto').name)


if __name__ == '__main__':
  unittest.main()

Directory Contents

Dirs: 1 × Files: 129

Name Size Perms Modified Actions
- drwxr-xr-x 2025-10-28 07:00:44
Edit Download
6.96 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
4.84 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
4.84 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
6.90 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
3.37 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
3.37 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
20.40 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
24.48 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
24.48 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
30.56 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
25.39 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
25.30 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
4.50 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
2.56 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
2.56 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
42.62 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
35.53 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
35.53 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
20.43 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
11.03 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
11.03 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
12.12 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
7.57 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
7.57 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
41.73 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
32.79 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
32.79 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
27.87 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
28.82 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
28.65 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
3.47 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
2.92 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
2.92 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
7.63 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
5.49 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
5.49 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
24.34 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
14.02 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
14.02 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
2.98 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
3.03 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
3.03 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
14.40 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
12.98 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
12.98 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
40.46 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
33.87 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
33.87 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
9.43 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
6.74 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
6.74 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
3.29 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
2.56 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
2.56 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
8.28 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
5.40 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
5.40 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
85.56 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
71.09 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
70.97 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
9.38 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
6.04 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
6.04 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
4.85 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
4.00 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
4.00 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
7.13 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
5.02 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
5.02 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
4.16 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
3.62 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
3.62 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
19.87 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
10.76 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
10.76 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
3.66 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
2.85 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
2.85 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
56.49 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
50.45 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
50.34 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
125.23 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
96.92 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
96.92 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
5.26 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
5.18 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
5.18 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
5.50 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
4.65 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
4.65 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
4.40 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
3.81 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
3.81 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
5.80 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
4.58 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
4.58 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
33.15 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
31.33 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
31.28 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
2.81 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
1.96 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
1.96 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
63.68 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
56.52 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
56.52 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
13.90 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
11.58 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
11.58 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
13.52 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
11.46 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
11.46 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
27.62 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
32.88 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
32.88 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
34.58 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
25.40 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
25.40 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
8.25 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
8.82 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
8.82 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
10.65 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
6.77 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
6.77 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
15.07 KB lrw-r--r-- 2025-10-21 13:29:01
Edit Download
15.94 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
15.50 KB lrw-r--r-- 2025-10-21 13:29:19
Edit Download
0 B lrw-r--r-- 2025-10-21 13:29:01
Edit Download
156 B lrw-r--r-- 2025-10-21 13:29:19
Edit Download
156 B lrw-r--r-- 2025-10-21 13:29:19
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).