Python google.protobuf.text_format.ParseLines() Examples

The following are 16 code examples for showing how to use google.protobuf.text_format.ParseLines(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module google.protobuf.text_format , or try the search function .

Example 1
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: text_format_test.py    License: MIT License 6 votes vote down vote up
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.). 
Example 2
Project: sklearn-theano   Author: sklearn-theano   File: text_format_test.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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.). 
Example 3
Project: keras-lambda   Author: sunilmallya   File: text_format_test.py    License: MIT License 6 votes vote down vote up
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.). 
Example 4
Project: lambda-packs   Author: ryfeus   File: text_format_test.py    License: MIT License 5 votes vote down vote up
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) 
Example 5
Project: lambda-packs   Author: ryfeus   File: text_format_test.py    License: MIT License 5 votes vote down vote up
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.). 
Example 6
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: text_format_test.py    License: MIT License 5 votes vote down vote up
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) 
Example 7
Project: sklearn-theano   Author: sklearn-theano   File: text_format_test.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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) 
Example 8
Project: botchallenge   Author: katharosada   File: text_format_test.py    License: MIT License 5 votes vote down vote up
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) 
Example 9
Project: coremltools   Author: apple   File: text_format_test.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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) 
Example 10
Project: coremltools   Author: apple   File: text_format_test.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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.). 
Example 11
Project: go2mapillary   Author: enricofer   File: text_format_test.py    License: GNU General Public License v3.0 5 votes vote down vote up
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) 
Example 12
Project: go2mapillary   Author: enricofer   File: text_format_test.py    License: GNU General Public License v3.0 5 votes vote down vote up
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.). 
Example 13
Project: tfx   Author: tensorflow   File: compiler_test.py    License: Apache License 2.0 5 votes vote down vote up
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()) 
Example 14
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) 
Example 15
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.). 
Example 16
Project: keras-lambda   Author: sunilmallya   File: text_format_test.py    License: MIT License 5 votes vote down vote up
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)