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


Python unittest_pb2.optional_int32_extension方法代碼示例

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


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

示例1: testTopLevelExtensionsForOptionalScalar

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import optional_int32_extension [as 別名]
def testTopLevelExtensionsForOptionalScalar(self):
    extendee_proto = unittest_pb2.TestAllExtensions()
    extension = unittest_pb2.optional_int32_extension
    self.assertTrue(not extendee_proto.HasExtension(extension))
    self.assertEqual(0, extendee_proto.Extensions[extension])
    # As with normal scalar fields, just doing a read doesn't actually set the
    # "has" bit.
    self.assertTrue(not extendee_proto.HasExtension(extension))
    # Actually set the thing.
    extendee_proto.Extensions[extension] = 23
    self.assertEqual(23, extendee_proto.Extensions[extension])
    self.assertTrue(extendee_proto.HasExtension(extension))
    # Ensure that clearing works as well.
    extendee_proto.ClearExtension(extension)
    self.assertEqual(0, extendee_proto.Extensions[extension])
    self.assertTrue(not extendee_proto.HasExtension(extension)) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:18,代碼來源:reflection_test.py

示例2: testRegisteredExtensions

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import optional_int32_extension [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

示例3: testExtensionFieldNumbers

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import optional_int32_extension [as 別名]
def testExtensionFieldNumbers(self):
    self.assertEqual(unittest_pb2.TestRequired.single.number, 1000)
    self.assertEqual(unittest_pb2.TestRequired.SINGLE_FIELD_NUMBER, 1000)
    self.assertEqual(unittest_pb2.TestRequired.multi.number, 1001)
    self.assertEqual(unittest_pb2.TestRequired.MULTI_FIELD_NUMBER, 1001)
    self.assertEqual(unittest_pb2.optional_int32_extension.number, 1)
    self.assertEqual(unittest_pb2.OPTIONAL_INT32_EXTENSION_FIELD_NUMBER, 1)
    self.assertEqual(unittest_pb2.optionalgroup_extension.number, 16)
    self.assertEqual(unittest_pb2.OPTIONALGROUP_EXTENSION_FIELD_NUMBER, 16)
    self.assertEqual(unittest_pb2.optional_nested_message_extension.number, 18)
    self.assertEqual(
      unittest_pb2.OPTIONAL_NESTED_MESSAGE_EXTENSION_FIELD_NUMBER, 18)
    self.assertEqual(unittest_pb2.optional_nested_enum_extension.number, 21)
    self.assertEqual(unittest_pb2.OPTIONAL_NESTED_ENUM_EXTENSION_FIELD_NUMBER,
      21)
    self.assertEqual(unittest_pb2.repeated_int32_extension.number, 31)
    self.assertEqual(unittest_pb2.REPEATED_INT32_EXTENSION_FIELD_NUMBER, 31)
    self.assertEqual(unittest_pb2.repeatedgroup_extension.number, 46)
    self.assertEqual(unittest_pb2.REPEATEDGROUP_EXTENSION_FIELD_NUMBER, 46)
    self.assertEqual(unittest_pb2.repeated_nested_message_extension.number, 48)
    self.assertEqual(
      unittest_pb2.REPEATED_NESTED_MESSAGE_EXTENSION_FIELD_NUMBER, 48)
    self.assertEqual(unittest_pb2.repeated_nested_enum_extension.number, 51)
    self.assertEqual(unittest_pb2.REPEATED_NESTED_ENUM_EXTENSION_FIELD_NUMBER,
      51) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:27,代碼來源:reflection_test.py

示例4: testSingularListExtensions

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import optional_int32_extension [as 別名]
def testSingularListExtensions(self):
    proto = unittest_pb2.TestAllExtensions()
    proto.Extensions[unittest_pb2.optional_fixed32_extension] = 1
    proto.Extensions[unittest_pb2.optional_int32_extension  ] = 5
    proto.Extensions[unittest_pb2.optional_string_extension ] = 'foo'
    self.assertEqual(
      [ (unittest_pb2.optional_int32_extension  , 5),
        (unittest_pb2.optional_fixed32_extension, 1),
        (unittest_pb2.optional_string_extension , 'foo') ],
      proto.ListFields()) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:12,代碼來源:reflection_test.py

示例5: testRepeatedListExtensions

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import optional_int32_extension [as 別名]
def testRepeatedListExtensions(self):
    proto = unittest_pb2.TestAllExtensions()
    proto.Extensions[unittest_pb2.repeated_fixed32_extension].append(1)
    proto.Extensions[unittest_pb2.repeated_int32_extension  ].append(5)
    proto.Extensions[unittest_pb2.repeated_int32_extension  ].append(11)
    proto.Extensions[unittest_pb2.repeated_string_extension ].append('foo')
    proto.Extensions[unittest_pb2.repeated_string_extension ].append('bar')
    proto.Extensions[unittest_pb2.repeated_string_extension ].append('baz')
    proto.Extensions[unittest_pb2.optional_int32_extension  ] = 21
    self.assertEqual(
      [ (unittest_pb2.optional_int32_extension  , 21),
        (unittest_pb2.repeated_int32_extension  , [5, 11]),
        (unittest_pb2.repeated_fixed32_extension, [1]),
        (unittest_pb2.repeated_string_extension , ['foo', 'bar', 'baz']) ],
      proto.ListFields()) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:17,代碼來源:reflection_test.py

示例6: testMergeFromExtensionsSingular

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import optional_int32_extension [as 別名]
def testMergeFromExtensionsSingular(self):
    proto1 = unittest_pb2.TestAllExtensions()
    proto1.Extensions[unittest_pb2.optional_int32_extension] = 1

    proto2 = unittest_pb2.TestAllExtensions()
    proto2.MergeFrom(proto1)
    self.assertEqual(
        1, proto2.Extensions[unittest_pb2.optional_int32_extension]) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:10,代碼來源:reflection_test.py

示例7: testExtensions

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import optional_int32_extension [as 別名]
def testExtensions(self):
    proto = unittest_pb2.TestAllExtensions()
    self.assertEqual(0, proto.ByteSize())
    extension = unittest_pb2.optional_int32_extension  # Field #1, 1 byte.
    proto.Extensions[extension] = 23
    # 1 byte for tag, 1 byte for value.
    self.assertEqual(2, proto.ByteSize())
    field = unittest_pb2.TestAllTypes.DESCRIPTOR.fields_by_name[
        'optional_int32']
    with self.assertRaises(KeyError):
      proto.Extensions[field] = 23 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:13,代碼來源:reflection_test.py

示例8: testMergeDuplicateExtensionScalars

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import optional_int32_extension [as 別名]
def testMergeDuplicateExtensionScalars(self):
    message = unittest_pb2.TestAllExtensions()
    text = ('[protobuf_unittest.optional_int32_extension]: 42 '
            '[protobuf_unittest.optional_int32_extension]: 67')
    text_format.Merge(text, message)
    self.assertEqual(67,
                     message.Extensions[unittest_pb2.optional_int32_extension]) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:9,代碼來源:text_format_test.py

示例9: testParseDuplicateExtensionScalars

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import optional_int32_extension [as 別名]
def testParseDuplicateExtensionScalars(self):
    message = unittest_pb2.TestAllExtensions()
    text = ('[protobuf_unittest.optional_int32_extension]: 42 '
            '[protobuf_unittest.optional_int32_extension]: 67')
    six.assertRaisesRegex(self, text_format.ParseError, (
        '1:96 : Message type "protobuf_unittest.TestAllExtensions" '
        'should not have multiple '
        '"protobuf_unittest.optional_int32_extension" extensions.'),
                          text_format.Parse, text, message) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:11,代碼來源:text_format_test.py

示例10: testRegisteredExtensions

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

  # 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:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:14,代碼來源:reflection_test.py


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