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


Python test_util.GoldenFileData方法代碼示例

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


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

示例1: testGoldenMessage

# 需要導入模塊: from google.protobuf.internal import test_util [as 別名]
# 或者: from google.protobuf.internal.test_util import GoldenFileData [as 別名]
def testGoldenMessage(self, message_module):
    # Proto3 doesn't have the "default_foo" members or foreign enums,
    # and doesn't preserve unknown fields, so for proto3 we use a golden
    # message that doesn't have these fields set.
    if message_module is unittest_pb2:
      golden_data = test_util.GoldenFileData(
          'golden_message_oneof_implemented')
    else:
      golden_data = test_util.GoldenFileData('golden_message_proto3')

    golden_message = message_module.TestAllTypes()
    golden_message.ParseFromString(golden_data)
    if message_module is unittest_pb2:
      test_util.ExpectAllFieldsSet(self, golden_message)
    self.assertEqual(golden_data, golden_message.SerializeToString())
    golden_copy = copy.deepcopy(golden_message)
    self.assertEqual(golden_data, golden_copy.SerializeToString()) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:19,代碼來源:message_test.py

示例2: testBadUtf8String

# 需要導入模塊: from google.protobuf.internal import test_util [as 別名]
# 或者: from google.protobuf.internal.test_util import GoldenFileData [as 別名]
def testBadUtf8String(self, message_module):
    if api_implementation.Type() != 'python':
      self.skipTest("Skipping testBadUtf8String, currently only the python "
                    "api implementation raises UnicodeDecodeError when a "
                    "string field contains bad utf-8.")
    bad_utf8_data = test_util.GoldenFileData('bad_utf8_string')
    with self.assertRaises(UnicodeDecodeError) as context:
      message_module.TestAllTypes.FromString(bad_utf8_data)
    self.assertIn('TestAllTypes.optional_string', str(context.exception)) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:11,代碼來源:message_test.py

示例3: testGoldenPackedMessage

# 需要導入模塊: from google.protobuf.internal import test_util [as 別名]
# 或者: from google.protobuf.internal.test_util import GoldenFileData [as 別名]
def testGoldenPackedMessage(self, message_module):
    golden_data = test_util.GoldenFileData('golden_packed_fields_message')
    golden_message = message_module.TestPackedTypes()
    golden_message.ParseFromString(golden_data)
    all_set = message_module.TestPackedTypes()
    test_util.SetAllPackedFields(all_set)
    self.assertEqual(all_set, golden_message)
    self.assertEqual(golden_data, all_set.SerializeToString())
    golden_copy = copy.deepcopy(golden_message)
    self.assertEqual(golden_data, golden_copy.SerializeToString()) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:12,代碼來源:message_test.py

示例4: testPickleSupport

# 需要導入模塊: from google.protobuf.internal import test_util [as 別名]
# 或者: from google.protobuf.internal.test_util import GoldenFileData [as 別名]
def testPickleSupport(self, message_module):
    golden_data = test_util.GoldenFileData('golden_message')
    golden_message = message_module.TestAllTypes()
    golden_message.ParseFromString(golden_data)
    pickled_message = pickle.dumps(golden_message)

    unpickled_message = pickle.loads(pickled_message)
    self.assertEqual(unpickled_message, golden_message) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:10,代碼來源:message_test.py

示例5: testGoldenExtensions

# 需要導入模塊: from google.protobuf.internal import test_util [as 別名]
# 或者: from google.protobuf.internal.test_util import GoldenFileData [as 別名]
def testGoldenExtensions(self):
    golden_data = test_util.GoldenFileData('golden_message')
    golden_message = unittest_pb2.TestAllExtensions()
    golden_message.ParseFromString(golden_data)
    all_set = unittest_pb2.TestAllExtensions()
    test_util.SetAllExtensions(all_set)
    self.assertEqual(all_set, golden_message)
    self.assertEqual(golden_data, golden_message.SerializeToString())
    golden_copy = copy.deepcopy(golden_message)
    self.assertEqual(golden_data, golden_copy.SerializeToString()) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:12,代碼來源:message_test.py

示例6: testBadUtf8String

# 需要導入模塊: from google.protobuf.internal import test_util [as 別名]
# 或者: from google.protobuf.internal.test_util import GoldenFileData [as 別名]
def testBadUtf8String(self):
    if api_implementation.Type() != 'python':
      self.skipTest("Skipping testBadUtf8String, currently only the python "
                    "api implementation raises UnicodeDecodeError when a "
                    "string field contains bad utf-8.")
    bad_utf8_data = test_util.GoldenFileData('bad_utf8_string')
    with self.assertRaises(UnicodeDecodeError) as context:
      unittest_pb2.TestAllTypes.FromString(bad_utf8_data)
    self.assertIn('field: protobuf_unittest.TestAllTypes.optional_string',
                  str(context.exception)) 
開發者ID:katharosada,項目名稱:botchallenge,代碼行數:12,代碼來源:message_test.py

示例7: testGoldenMessage

# 需要導入模塊: from google.protobuf.internal import test_util [as 別名]
# 或者: from google.protobuf.internal.test_util import GoldenFileData [as 別名]
def testGoldenMessage(self):
    golden_data = test_util.GoldenFileData(
        'golden_message_oneof_implemented')
    golden_message = unittest_pb2.TestAllTypes()
    golden_message.ParseFromString(golden_data)
    test_util.ExpectAllFieldsSet(self, golden_message)
    self.assertEqual(golden_data, golden_message.SerializeToString())
    golden_copy = copy.deepcopy(golden_message)
    self.assertEqual(golden_data, golden_copy.SerializeToString()) 
開發者ID:katharosada,項目名稱:botchallenge,代碼行數:11,代碼來源:message_test.py

示例8: testGoldenExtensions

# 需要導入模塊: from google.protobuf.internal import test_util [as 別名]
# 或者: from google.protobuf.internal.test_util import GoldenFileData [as 別名]
def testGoldenExtensions(self):
    golden_data = test_util.GoldenFileData('golden_message')
    golden_message = unittest_pb2.TestAllExtensions()
    golden_message.ParseFromString(golden_data)
    all_set = unittest_pb2.TestAllExtensions()
    test_util.SetAllExtensions(all_set)
    self.assertEquals(all_set, golden_message)
    self.assertEqual(golden_data, golden_message.SerializeToString())
    golden_copy = copy.deepcopy(golden_message)
    self.assertEqual(golden_data, golden_copy.SerializeToString()) 
開發者ID:katharosada,項目名稱:botchallenge,代碼行數:12,代碼來源:message_test.py

示例9: testGoldenPackedMessage

# 需要導入模塊: from google.protobuf.internal import test_util [as 別名]
# 或者: from google.protobuf.internal.test_util import GoldenFileData [as 別名]
def testGoldenPackedMessage(self):
    golden_data = test_util.GoldenFileData('golden_packed_fields_message')
    golden_message = unittest_pb2.TestPackedTypes()
    golden_message.ParseFromString(golden_data)
    all_set = unittest_pb2.TestPackedTypes()
    test_util.SetAllPackedFields(all_set)
    self.assertEquals(all_set, golden_message)
    self.assertEqual(golden_data, all_set.SerializeToString())
    golden_copy = copy.deepcopy(golden_message)
    self.assertEqual(golden_data, golden_copy.SerializeToString()) 
開發者ID:katharosada,項目名稱:botchallenge,代碼行數:12,代碼來源:message_test.py

示例10: testGoldenPackedExtensions

# 需要導入模塊: from google.protobuf.internal import test_util [as 別名]
# 或者: from google.protobuf.internal.test_util import GoldenFileData [as 別名]
def testGoldenPackedExtensions(self):
    golden_data = test_util.GoldenFileData('golden_packed_fields_message')
    golden_message = unittest_pb2.TestPackedExtensions()
    golden_message.ParseFromString(golden_data)
    all_set = unittest_pb2.TestPackedExtensions()
    test_util.SetAllPackedExtensions(all_set)
    self.assertEquals(all_set, golden_message)
    self.assertEqual(golden_data, all_set.SerializeToString())
    golden_copy = copy.deepcopy(golden_message)
    self.assertEqual(golden_data, golden_copy.SerializeToString()) 
開發者ID:katharosada,項目名稱:botchallenge,代碼行數:12,代碼來源:message_test.py


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