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


Python unittest_pb2.TestEmptyMessage方法代碼示例

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


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

示例1: testMergeFrom

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestEmptyMessage [as 別名]
def testMergeFrom(self):
    message = unittest_pb2.TestAllTypes()
    message.optional_int32 = 1
    message.optional_uint32 = 2
    source = unittest_pb2.TestEmptyMessage()
    source.ParseFromString(message.SerializeToString())

    message.ClearField('optional_int32')
    message.optional_int64 = 3
    message.optional_uint32 = 4
    destination = unittest_pb2.TestEmptyMessage()
    destination.ParseFromString(message.SerializeToString())

    destination.MergeFrom(source)
    # Check that the fields where correctly merged, even stored in the unknown
    # fields set.
    message.ParseFromString(destination.SerializeToString())
    self.assertEqual(message.optional_int32, 1)
    self.assertEqual(message.optional_uint32, 2)
    self.assertEqual(message.optional_int64, 3) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:22,代碼來源:unknown_fields_test.py

示例2: testMergeFrom

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestEmptyMessage [as 別名]
def testMergeFrom(self):
    message = unittest_pb2.TestAllTypes()
    message.optional_int32 = 1
    message.optional_uint32 = 2
    source = unittest_pb2.TestEmptyMessage()
    source.ParseFromString(message.SerializeToString())

    message.ClearField('optional_int32')
    message.optional_int64 = 3
    message.optional_uint32 = 4
    destination = unittest_pb2.TestEmptyMessage()
    destination.ParseFromString(message.SerializeToString())
    unknown_fields = destination._unknown_fields[:]

    destination.MergeFrom(source)
    self.assertEqual(unknown_fields + source._unknown_fields,
                     destination._unknown_fields) 
開發者ID:katharosada,項目名稱:botchallenge,代碼行數:19,代碼來源:unknown_fields_test.py

示例3: testParseTruncated

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestEmptyMessage [as 別名]
def testParseTruncated(self):
    # This test is only applicable for the Python implementation of the API.
    if api_implementation.Type() != 'python':
      return

    first_proto = unittest_pb2.TestAllTypes()
    test_util.SetAllFields(first_proto)
    serialized = first_proto.SerializeToString()

    for truncation_point in range(len(serialized) + 1):
      try:
        second_proto = unittest_pb2.TestAllTypes()
        unknown_fields = unittest_pb2.TestEmptyMessage()
        pos = second_proto._InternalParse(serialized, 0, truncation_point)
        # If we didn't raise an error then we read exactly the amount expected.
        self.assertEqual(truncation_point, pos)

        # Parsing to unknown fields should not throw if parsing to known fields
        # did not.
        try:
          pos2 = unknown_fields._InternalParse(serialized, 0, truncation_point)
          self.assertEqual(truncation_point, pos2)
        except message.DecodeError:
          self.fail('Parsing unknown fields failed when parsing known fields '
                    'did not.')
      except message.DecodeError:
        # Parsing unknown fields should also fail.
        self.assertRaises(message.DecodeError, unknown_fields._InternalParse,
                          serialized, 0, truncation_point) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:31,代碼來源:reflection_test.py

示例4: testUnknownFields

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestEmptyMessage [as 別名]
def testUnknownFields(self):
    proto = unittest_pb2.TestAllTypes()
    test_util.SetAllFields(proto)

    serialized = proto.SerializeToString()

    # The empty message should be parsable with all of the fields
    # unknown.
    proto2 = unittest_pb2.TestEmptyMessage()

    # Parsing this message should succeed.
    self.assertEqual(
        len(serialized),
        proto2.MergeFromString(serialized))

    # Now test with a int64 field set.
    proto = unittest_pb2.TestAllTypes()
    proto.optional_int64 = 0x0fffffffffffffff
    serialized = proto.SerializeToString()
    # The empty message should be parsable with all of the fields
    # unknown.
    proto2 = unittest_pb2.TestEmptyMessage()
    # Parsing this message should succeed.
    self.assertEqual(
        len(serialized),
        proto2.MergeFromString(serialized)) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:28,代碼來源:reflection_test.py

示例5: testInitArgsUnknownFieldName

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestEmptyMessage [as 別名]
def testInitArgsUnknownFieldName(self):
    def InitalizeEmptyMessageWithExtraKeywordArg():
      unused_proto = unittest_pb2.TestEmptyMessage(unknown='unknown')
    self._CheckRaises(
        ValueError,
        InitalizeEmptyMessageWithExtraKeywordArg,
        'Protocol message TestEmptyMessage has no "unknown" field.') 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:9,代碼來源:reflection_test.py

示例6: setUp

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestEmptyMessage [as 別名]
def setUp(self):
    self.descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR
    self.all_fields = unittest_pb2.TestAllTypes()
    test_util.SetAllFields(self.all_fields)
    self.all_fields_data = self.all_fields.SerializeToString()
    self.empty_message = unittest_pb2.TestEmptyMessage()
    self.empty_message.ParseFromString(self.all_fields_data) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:9,代碼來源:unknown_fields_test.py

示例7: expectSerializeProto3

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestEmptyMessage [as 別名]
def expectSerializeProto3(self, preserve):
    message = unittest_proto3_arena_pb2.TestEmptyMessage()
    message.ParseFromString(self.all_fields_data)
    if preserve:
      self.assertEqual(self.all_fields_data, message.SerializeToString())
    else:
      self.assertEqual(0, len(message.SerializeToString())) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:9,代碼來源:unknown_fields_test.py

示例8: testCopyFrom

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestEmptyMessage [as 別名]
def testCopyFrom(self):
    message = unittest_pb2.TestEmptyMessage()
    message.CopyFrom(self.empty_message)
    self.assertEqual(message.SerializeToString(), self.all_fields_data) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:6,代碼來源:unknown_fields_test.py

示例9: testSerializeProto3

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestEmptyMessage [as 別名]
def testSerializeProto3(self):
    # Verify that proto3 doesn't preserve unknown fields.
    message = unittest_proto3_arena_pb2.TestEmptyMessage()
    message.ParseFromString(self.all_fields_data)
    self.assertEqual(0, len(message.SerializeToString())) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:7,代碼來源:unknown_fields_test.py

示例10: testInitArgsUnknownFieldName

# 需要導入模塊: from google.protobuf import unittest_pb2 [as 別名]
# 或者: from google.protobuf.unittest_pb2 import TestEmptyMessage [as 別名]
def testInitArgsUnknownFieldName(self):
    def InitalizeEmptyMessageWithExtraKeywordArg():
      unused_proto = unittest_pb2.TestEmptyMessage(unknown='unknown')
    self._CheckRaises(ValueError,
                      InitalizeEmptyMessageWithExtraKeywordArg,
                      'Protocol message has no "unknown" field.') 
開發者ID:sklearn-theano,項目名稱:sklearn-theano,代碼行數:8,代碼來源:reflection_test.py


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