本文整理匯總了Python中google.protobuf.internal.test_util.ExpectAllFieldsSet方法的典型用法代碼示例。如果您正苦於以下問題:Python test_util.ExpectAllFieldsSet方法的具體用法?Python test_util.ExpectAllFieldsSet怎麽用?Python test_util.ExpectAllFieldsSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類google.protobuf.internal.test_util
的用法示例。
在下文中一共展示了test_util.ExpectAllFieldsSet方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testGoldenMessage
# 需要導入模塊: from google.protobuf.internal import test_util [as 別名]
# 或者: from google.protobuf.internal.test_util import ExpectAllFieldsSet [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())
示例2: testParseAllFields
# 需要導入模塊: from google.protobuf.internal import test_util [as 別名]
# 或者: from google.protobuf.internal.test_util import ExpectAllFieldsSet [as 別名]
def testParseAllFields(self, message_module):
message = message_module.TestAllTypes()
test_util.SetAllFields(message)
ascii_text = text_format.MessageToString(message)
parsed_message = message_module.TestAllTypes()
text_format.Parse(ascii_text, parsed_message)
self.assertEqual(message, parsed_message)
if message_module is unittest_pb2:
test_util.ExpectAllFieldsSet(self, message)
示例3: testParseAndMergeUtf8
# 需要導入模塊: from google.protobuf.internal import test_util [as 別名]
# 或者: from google.protobuf.internal.test_util import ExpectAllFieldsSet [as 別名]
def testParseAndMergeUtf8(self, message_module):
message = message_module.TestAllTypes()
test_util.SetAllFields(message)
ascii_text = text_format.MessageToString(message)
ascii_text = ascii_text.encode('utf-8')
parsed_message = message_module.TestAllTypes()
text_format.Parse(ascii_text, parsed_message)
self.assertEqual(message, parsed_message)
if message_module is unittest_pb2:
test_util.ExpectAllFieldsSet(self, message)
parsed_message.Clear()
text_format.Merge(ascii_text, parsed_message)
self.assertEqual(message, parsed_message)
if message_module is unittest_pb2:
test_util.ExpectAllFieldsSet(self, message)
if six.PY2:
msg2 = message_module.TestAllTypes()
text = ('optional_string: "café"')
text_format.Merge(text, msg2)
self.assertEqual(msg2.optional_string, 'café')
msg2.Clear()
text_format.Parse(text, msg2)
self.assertEqual(msg2.optional_string, 'café')
示例4: testGoldenMessage
# 需要導入模塊: from google.protobuf.internal import test_util [as 別名]
# 或者: from google.protobuf.internal.test_util import ExpectAllFieldsSet [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())
示例5: testParseAllFields
# 需要導入模塊: from google.protobuf.internal import test_util [as 別名]
# 或者: from google.protobuf.internal.test_util import ExpectAllFieldsSet [as 別名]
def testParseAllFields(self):
message = unittest_pb2.TestAllTypes()
test_util.SetAllFields(message)
ascii_text = text_format.MessageToString(message)
parsed_message = unittest_pb2.TestAllTypes()
text_format.Parse(ascii_text, parsed_message)
self.assertEqual(message, parsed_message)
test_util.ExpectAllFieldsSet(self, message)
示例6: testGoldenMessage
# 需要導入模塊: from google.protobuf.internal import test_util [as 別名]
# 或者: from google.protobuf.internal.test_util import ExpectAllFieldsSet [as 別名]
def testGoldenMessage(self):
golden_data = test_util.GoldenFile('golden_message').read()
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())
示例7: testMergeAllFields
# 需要導入模塊: from google.protobuf.internal import test_util [as 別名]
# 或者: from google.protobuf.internal.test_util import ExpectAllFieldsSet [as 別名]
def testMergeAllFields(self):
message = unittest_pb2.TestAllTypes()
test_util.SetAllFields(message)
ascii_text = text_format.MessageToString(message)
parsed_message = unittest_pb2.TestAllTypes()
text_format.Merge(ascii_text, parsed_message)
self.assertEqual(message, parsed_message)
test_util.ExpectAllFieldsSet(self, message)