本文整理汇总了Python中google.protobuf.text_format.ParseLines方法的典型用法代码示例。如果您正苦于以下问题:Python text_format.ParseLines方法的具体用法?Python text_format.ParseLines怎么用?Python text_format.ParseLines使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.protobuf.text_format
的用法示例。
在下文中一共展示了text_format.ParseLines方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testMapOrderSemantics
# 需要导入模块: from google.protobuf import text_format [as 别名]
# 或者: from google.protobuf.text_format import ParseLines [as 别名]
def testMapOrderSemantics(self):
golden_lines = self.ReadGolden('map_test_data.txt')
# The C++ implementation emits defaulted-value fields, while the Python
# implementation does not. Adjusting for this is awkward, but it is
# valuable to test against a common golden file.
line_blacklist = (' key: 0\n', ' value: 0\n', ' key: false\n',
' value: false\n')
golden_lines = [line for line in golden_lines if line not in line_blacklist]
message = map_unittest_pb2.TestMap()
text_format.ParseLines(golden_lines, message)
candidate = text_format.MessageToString(message)
# The Python implementation emits "1.0" for the double value that the C++
# implementation emits as "1".
candidate = candidate.replace('1.0', '1', 2)
self.assertMultiLineEqual(candidate, ''.join(golden_lines))
# Tests of proto2-only features (MessageSet, extensions, etc.).
示例2: testMapOrderSemantics
# 需要导入模块: from google.protobuf import text_format [as 别名]
# 或者: from google.protobuf.text_format import ParseLines [as 别名]
def testMapOrderSemantics(self):
golden_lines = self.ReadGolden('map_test_data.txt')
# The C++ implementation emits defaulted-value fields, while the Python
# implementation does not. Adjusting for this is awkward, but it is
# valuable to test against a common golden file.
line_blacklist = (' key: 0\n',
' value: 0\n',
' key: false\n',
' value: false\n')
golden_lines = [line for line in golden_lines if line not in line_blacklist]
message = map_unittest_pb2.TestMap()
text_format.ParseLines(golden_lines, message)
candidate = text_format.MessageToString(message)
# The Python implementation emits "1.0" for the double value that the C++
# implementation emits as "1".
candidate = candidate.replace('1.0', '1', 2)
self.assertMultiLineEqual(candidate, ''.join(golden_lines))
# Tests of proto2-only features (MessageSet, extensions, etc.).
示例3: testParseLinesGolden
# 需要导入模块: from google.protobuf import text_format [as 别名]
# 或者: from google.protobuf.text_format import ParseLines [as 别名]
def testParseLinesGolden(self):
opened = self.ReadGolden('text_format_unittest_data_oneof_implemented.txt')
parsed_message = unittest_pb2.TestAllTypes()
r = text_format.ParseLines(opened, parsed_message)
self.assertIs(r, parsed_message)
message = unittest_pb2.TestAllTypes()
test_util.SetAllFields(message)
self.assertEqual(message, parsed_message)
示例4: testMapOrderEnforcement
# 需要导入模块: from google.protobuf import text_format [as 别名]
# 或者: from google.protobuf.text_format import ParseLines [as 别名]
def testMapOrderEnforcement(self):
message = map_unittest_pb2.TestMap()
for letter in string.ascii_uppercase[13:26]:
message.map_string_string[letter] = 'dummy'
for letter in reversed(string.ascii_uppercase[0:13]):
message.map_string_string[letter] = 'dummy'
golden = ''.join(('map_string_string {\n key: "%c"\n value: "dummy"\n}\n'
% (letter,) for letter in string.ascii_uppercase))
self.CompareToGoldenText(text_format.MessageToString(message), golden)
# TODO(teboring): In c/137553523, not serializing default value for map entry
# message has been fixed. This test needs to be disabled in order to submit
# that cl. Add this back when c/137553523 has been submitted.
# def testMapOrderSemantics(self):
# golden_lines = self.ReadGolden('map_test_data.txt')
# message = map_unittest_pb2.TestMap()
# text_format.ParseLines(golden_lines, message)
# candidate = text_format.MessageToString(message)
# # The Python implementation emits "1.0" for the double value that the C++
# # implementation emits as "1".
# candidate = candidate.replace('1.0', '1', 2)
# candidate = candidate.replace('0.0', '0', 2)
# self.assertMultiLineEqual(candidate, ''.join(golden_lines))
# Tests of proto2-only features (MessageSet, extensions, etc.).
示例5: testParseLinesGolden
# 需要导入模块: from google.protobuf import text_format [as 别名]
# 或者: from google.protobuf.text_format import ParseLines [as 别名]
def testParseLinesGolden(self):
opened = self.ReadGolden('text_format_unittest_data.txt')
parsed_message = unittest_pb2.TestAllTypes()
r = text_format.ParseLines(opened, parsed_message)
self.assertIs(r, parsed_message)
message = unittest_pb2.TestAllTypes()
test_util.SetAllFields(message)
self.assertEqual(message, parsed_message)
示例6: testParseLinesGolden
# 需要导入模块: from google.protobuf import text_format [as 别名]
# 或者: from google.protobuf.text_format import ParseLines [as 别名]
def testParseLinesGolden(self):
opened = self.ReadGolden('text_format_unittest_data.txt')
parsed_message = unittest_pb2.TestAllTypes()
r = text_format.ParseLines(opened, parsed_message)
self.assertIs(r, parsed_message)
message = unittest_pb2.TestAllTypes()
test_util.SetAllFields(message)
self.assertEquals(message, parsed_message)
示例7: _set_up_test_pipeline_pb
# 需要导入模块: from google.protobuf import text_format [as 别名]
# 或者: from google.protobuf.text_format import ParseLines [as 别名]
def _set_up_test_pipeline_pb(self):
"""Read expected pipeline pb from a text proto file."""
test_pb_filepath = os.path.join(
os.path.dirname(__file__), "testdata", "iris_pipeline_ir.pbtxt")
with open(test_pb_filepath) as text_pb_file:
self._pipeline_pb = text_format.ParseLines(text_pb_file,
pipeline_pb2.Pipeline())