當前位置: 首頁>>代碼示例>>Python>>正文


Python unittest_pb2.TestAllTypes方法代碼示例

本文整理匯總了Python中google.protobuf.unittest_pb2.TestAllTypes方法的典型用法代碼示例。如果您正苦於以下問題:Python unittest_pb2.TestAllTypes方法的具體用法?Python unittest_pb2.TestAllTypes怎麽用?Python unittest_pb2.TestAllTypes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在google.protobuf.unittest_pb2的用法示例。


在下文中一共展示了unittest_pb2.TestAllTypes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _Database

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestAllTypes [as 別名]
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 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:19,代碼來源:symbol_database_test.py

示例2: testPackage

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestAllTypes [as 別名]
def testPackage(self):
    self.assertEqual(
        unittest_pb2.TestAllTypes.DESCRIPTOR.file.package,
        'protobuf_unittest')
    desc = unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR
    self.assertEqual(desc.file.package, 'protobuf_unittest')
    self.assertEqual(
        unittest_import_pb2.ImportMessage.DESCRIPTOR.file.package,
        'protobuf_unittest_import')

    self.assertEqual(
        unittest_pb2._FOREIGNENUM.file.package, 'protobuf_unittest')
    self.assertEqual(
        unittest_pb2._TESTALLTYPES_NESTEDENUM.file.package,
        'protobuf_unittest')
    self.assertEqual(
        unittest_import_pb2._IMPORTENUM.file.package,
        'protobuf_unittest_import') 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:20,代碼來源:generator_test.py

示例3: testOneof

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestAllTypes [as 別名]
def testOneof(self):
    desc = unittest_pb2.TestAllTypes.DESCRIPTOR
    self.assertEqual(1, len(desc.oneofs))
    self.assertEqual('oneof_field', desc.oneofs[0].name)
    self.assertEqual(0, desc.oneofs[0].index)
    self.assertIs(desc, desc.oneofs[0].containing_type)
    self.assertIs(desc.oneofs[0], desc.oneofs_by_name['oneof_field'])
    nested_names = set(['oneof_uint32', 'oneof_nested_message',
                        'oneof_string', 'oneof_bytes'])
    self.assertEqual(
        nested_names,
        set([field.name for field in desc.oneofs[0].fields]))
    for field_name, field_desc in list(desc.fields_by_name.items()):
      if field_name in nested_names:
        self.assertIs(desc.oneofs[0], field_desc.containing_oneof)
      else:
        self.assertIsNone(field_desc.containing_oneof) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:19,代碼來源:generator_test.py

示例4: testFindMethods

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestAllTypes [as 別名]
def testFindMethods(self):
    self.assertIs(
        self.pool.FindFileByName('google/protobuf/unittest.proto'),
        unittest_pb2.DESCRIPTOR)
    self.assertIs(
        self.pool.FindMessageTypeByName('protobuf_unittest.TestAllTypes'),
        unittest_pb2.TestAllTypes.DESCRIPTOR)
    self.assertIs(
        self.pool.FindFieldByName(
            'protobuf_unittest.TestAllTypes.optional_int32'),
        unittest_pb2.TestAllTypes.DESCRIPTOR.fields_by_name['optional_int32'])
    self.assertIs(
        self.pool.FindEnumTypeByName('protobuf_unittest.ForeignEnum'),
        unittest_pb2.ForeignEnum.DESCRIPTOR)
    self.assertIs(
        self.pool.FindExtensionByName(
            'protobuf_unittest.optional_int32_extension'),
        unittest_pb2.DESCRIPTOR.extensions_by_name['optional_int32_extension'])
    self.assertIs(
        self.pool.FindOneofByName('protobuf_unittest.TestAllTypes.oneof_field'),
        unittest_pb2.TestAllTypes.DESCRIPTOR.oneofs_by_name['oneof_field'])
    self.assertIs(
        self.pool.FindServiceByName('protobuf_unittest.TestService'),
        unittest_pb2.DESCRIPTOR.services_by_name['TestService']) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:26,代碼來源:descriptor_pool_test.py

示例5: testSingularListFields

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestAllTypes [as 別名]
def testSingularListFields(self):
    proto = unittest_pb2.TestAllTypes()
    proto.optional_fixed32 = 1
    proto.optional_int32 = 5
    proto.optional_string = 'foo'
    # Access sub-message but don't set it yet.
    nested_message = proto.optional_nested_message
    self.assertEqual(
      [ (proto.DESCRIPTOR.fields_by_name['optional_int32'  ], 5),
        (proto.DESCRIPTOR.fields_by_name['optional_fixed32'], 1),
        (proto.DESCRIPTOR.fields_by_name['optional_string' ], 'foo') ],
      proto.ListFields())

    proto.optional_nested_message.bb = 123
    self.assertEqual(
      [ (proto.DESCRIPTOR.fields_by_name['optional_int32'  ], 5),
        (proto.DESCRIPTOR.fields_by_name['optional_fixed32'], 1),
        (proto.DESCRIPTOR.fields_by_name['optional_string' ], 'foo'),
        (proto.DESCRIPTOR.fields_by_name['optional_nested_message' ],
             nested_message) ],
      proto.ListFields()) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:23,代碼來源:reflection_test.py

示例6: testRepeatedListFields

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestAllTypes [as 別名]
def testRepeatedListFields(self):
    proto = unittest_pb2.TestAllTypes()
    proto.repeated_fixed32.append(1)
    proto.repeated_int32.append(5)
    proto.repeated_int32.append(11)
    proto.repeated_string.extend(['foo', 'bar'])
    proto.repeated_string.extend([])
    proto.repeated_string.append('baz')
    proto.repeated_string.extend(str(x) for x in range(2))
    proto.optional_int32 = 21
    proto.repeated_bool  # Access but don't set anything; should not be listed.
    self.assertEqual(
      [ (proto.DESCRIPTOR.fields_by_name['optional_int32'  ], 21),
        (proto.DESCRIPTOR.fields_by_name['repeated_int32'  ], [5, 11]),
        (proto.DESCRIPTOR.fields_by_name['repeated_fixed32'], [1]),
        (proto.DESCRIPTOR.fields_by_name['repeated_string' ],
          ['foo', 'bar', 'baz', '0', '1']) ],
      proto.ListFields()) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:20,代碼來源:reflection_test.py

示例7: testDisallowedAssignments

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestAllTypes [as 別名]
def testDisallowedAssignments(self):
    # It's illegal to assign values directly to repeated fields
    # or to nonrepeated composite fields.  Ensure that this fails.
    proto = unittest_pb2.TestAllTypes()
    # Repeated fields.
    self.assertRaises(AttributeError, setattr, proto, 'repeated_int32', 10)
    # Lists shouldn't work, either.
    self.assertRaises(AttributeError, setattr, proto, 'repeated_int32', [10])
    # Composite fields.
    self.assertRaises(AttributeError, setattr, proto,
                      'optional_nested_message', 23)
    # Assignment to a repeated nested message field without specifying
    # the index in the array of nested messages.
    self.assertRaises(AttributeError, setattr, proto.repeated_nested_message,
                      'bb', 34)
    # Assignment to an attribute of a repeated field.
    self.assertRaises(AttributeError, setattr, proto.repeated_float,
                      'some_attribute', 34)
    # proto.nonexistent_field = 23 should fail as well.
    self.assertRaises(AttributeError, setattr, proto, 'nonexistent_field', 23) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:22,代碼來源:reflection_test.py

示例8: testRepeatedScalarTypeSafety

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestAllTypes [as 別名]
def testRepeatedScalarTypeSafety(self):
    proto = unittest_pb2.TestAllTypes()
    self.assertRaises(TypeError, proto.repeated_int32.append, 1.1)
    self.assertRaises(TypeError, proto.repeated_int32.append, 'foo')
    self.assertRaises(TypeError, proto.repeated_string, 10)
    self.assertRaises(TypeError, proto.repeated_bytes, 10)

    proto.repeated_int32.append(10)
    proto.repeated_int32[0] = 23
    self.assertRaises(IndexError, proto.repeated_int32.__setitem__, 500, 23)
    self.assertRaises(TypeError, proto.repeated_int32.__setitem__, 0, 'abc')
    self.assertRaises(TypeError, proto.repeated_int32.__setitem__, 0, [])
    self.assertRaises(TypeError, proto.repeated_int32.__setitem__,
                      'index', 23)

    proto.repeated_string.append('2')
    self.assertRaises(TypeError, proto.repeated_string.__setitem__, 0, 10)

    # Repeated enums tests.
    #proto.repeated_nested_enum.append(0) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:22,代碼來源:reflection_test.py

示例9: testRegisteredExtensions

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestAllTypes [as 別名]
def testRegisteredExtensions(self):
    pool = unittest_pb2.DESCRIPTOR.pool
    self.assertTrue(
        pool.FindExtensionByNumber(
            unittest_pb2.TestAllExtensions.DESCRIPTOR, 1))
    self.assertIs(
        pool.FindExtensionByName(
            'protobuf_unittest.optional_int32_extension').containing_type,
        unittest_pb2.TestAllExtensions.DESCRIPTOR)
    # Make sure extensions haven't been registered into types that shouldn't
    # have any.
    self.assertEqual(0, len(
        pool.FindAllExtensions(unittest_pb2.TestAllTypes.DESCRIPTOR)))

  # If message A directly contains message B, and
  # a.HasField('b') is currently False, then mutating any
  # extension in B should change a.HasField('b') to True
  # (and so on up the object tree). 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:20,代碼來源:reflection_test.py

示例10: testMergeFromRepeatedNestedMessage

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestAllTypes [as 別名]
def testMergeFromRepeatedNestedMessage(self):
    # Test merge with a repeated nested message.
    proto1 = unittest_pb2.TestAllTypes()
    m = proto1.repeated_nested_message.add()
    m.bb = 123
    m = proto1.repeated_nested_message.add()
    m.bb = 321

    proto2 = unittest_pb2.TestAllTypes()
    m = proto2.repeated_nested_message.add()
    m.bb = 999
    proto2.MergeFrom(proto1)
    self.assertEqual(999, proto2.repeated_nested_message[0].bb)
    self.assertEqual(123, proto2.repeated_nested_message[1].bb)
    self.assertEqual(321, proto2.repeated_nested_message[2].bb)

    proto3 = unittest_pb2.TestAllTypes()
    proto3.repeated_nested_message.MergeFrom(proto2.repeated_nested_message)
    self.assertEqual(999, proto3.repeated_nested_message[0].bb)
    self.assertEqual(123, proto3.repeated_nested_message[1].bb)
    self.assertEqual(321, proto3.repeated_nested_message[2].bb) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:23,代碼來源:reflection_test.py

示例11: testClear

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestAllTypes [as 別名]
def testClear(self):
    proto = unittest_pb2.TestAllTypes()
    # C++ implementation does not support lazy fields right now so leave it
    # out for now.
    if api_implementation.Type() == 'python':
      test_util.SetAllFields(proto)
    else:
      test_util.SetAllNonLazyFields(proto)
    # Clear the message.
    proto.Clear()
    self.assertEqual(proto.ByteSize(), 0)
    empty_proto = unittest_pb2.TestAllTypes()
    self.assertEqual(proto, empty_proto)

    # Test if extensions which were set are cleared.
    proto = unittest_pb2.TestAllExtensions()
    test_util.SetAllExtensions(proto)
    # Clear the message.
    proto.Clear()
    self.assertEqual(proto.ByteSize(), 0)
    empty_proto = unittest_pb2.TestAllExtensions()
    self.assertEqual(proto, empty_proto) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:24,代碼來源:reflection_test.py

示例12: testOtherNumerics

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestAllTypes [as 別名]
def testOtherNumerics(self):
    self.proto.optional_fixed32 = 1234
    # One byte for tag and 4 bytes for fixed32.
    self.assertEqual(5, self.Size())
    self.proto = unittest_pb2.TestAllTypes()

    self.proto.optional_fixed64 = 1234
    # One byte for tag and 8 bytes for fixed64.
    self.assertEqual(9, self.Size())
    self.proto = unittest_pb2.TestAllTypes()

    self.proto.optional_float = 1.234
    # One byte for tag and 4 bytes for float.
    self.assertEqual(5, self.Size())
    self.proto = unittest_pb2.TestAllTypes()

    self.proto.optional_double = 1.234
    # One byte for tag and 8 bytes for float.
    self.assertEqual(9, self.Size())
    self.proto = unittest_pb2.TestAllTypes()

    self.proto.optional_sint32 = 64
    # One byte for tag and 2 bytes for zig-zag-encoded 64.
    self.assertEqual(3, self.Size())
    self.proto = unittest_pb2.TestAllTypes() 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:27,代碼來源:reflection_test.py

示例13: testMergeFromStringWhenFieldsAlreadySet

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestAllTypes [as 別名]
def testMergeFromStringWhenFieldsAlreadySet(self):
    first_proto = unittest_pb2.TestAllTypes()
    first_proto.repeated_string.append('foobar')
    first_proto.optional_int32 = 23
    first_proto.optional_nested_message.bb = 42
    serialized = first_proto.SerializeToString()

    second_proto = unittest_pb2.TestAllTypes()
    second_proto.repeated_string.append('baz')
    second_proto.optional_int32 = 100
    second_proto.optional_nested_message.bb = 999

    bytes_parsed = second_proto.MergeFromString(serialized)
    self.assertEqual(len(serialized), bytes_parsed)

    # Ensure that we append to repeated fields.
    self.assertEqual(['baz', 'foobar'], list(second_proto.repeated_string))
    # Ensure that we overwrite nonrepeatd scalars.
    self.assertEqual(23, second_proto.optional_int32)
    # Ensure that we recursively call MergeFromString() on
    # submessages.
    self.assertEqual(42, second_proto.optional_nested_message.bb) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:24,代碼來源:reflection_test.py

示例14: testGetPrototype

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestAllTypes [as 別名]
def testGetPrototype(self):
    instance = self._Database().GetPrototype(
        unittest_pb2.TestAllTypes.DESCRIPTOR)
    self.assertTrue(instance is unittest_pb2.TestAllTypes) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:6,代碼來源:symbol_database_test.py

示例15: testGetMessages

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestAllTypes [as 別名]
def testGetMessages(self):
    messages = self._Database().GetMessages(
        ['google/protobuf/unittest.proto'])
    self.assertTrue(
        unittest_pb2.TestAllTypes is
        messages['protobuf_unittest.TestAllTypes']) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:8,代碼來源:symbol_database_test.py


注:本文中的google.protobuf.unittest_pb2.TestAllTypes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。