def testmergeallextensions(self):
    message = unittest_pb2.testallextensions()
    test_util.setallextensions(message)
    ascii_text = text_format.messagetostring(message)

    parsed_message = unittest_pb2.testallextensions()
    text_format.merge(ascii_text, parsed_message)
    self.assertequal(message, parsed_message)
  def testmergegoldenextensions(self):
    golden_text = '\n'.join(self.readgolden(
        'text_format_unittest_extensions_data.txt'))
    parsed_message = unittest_pb2.testallextensions()
    text_format.merge(golden_text, parsed_message)

    message = unittest_pb2.testallextensions()
    test_util.setallextensions(message)
    self.assertequals(message, parsed_message)
 def testgoldenextensions(self):
     golden_data = test_util.goldenfile("golden_message").read()
     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())
 def testprintbadenumvalueextensions(self):
   message = unittest_pb2.testallextensions()
   message.extensions[unittest_pb2.optional_nested_enum_extension] = 100
   message.extensions[unittest_pb2.optional_foreign_enum_extension] = 101
   message.extensions[unittest_pb2.optional_import_enum_extension] = 102
   self.comparetogoldentext(
       text_format.messagetostring(message),
       '[protobuf_unittest.optional_nested_enum_extension]: 100\n'
       '[protobuf_unittest.optional_foreign_enum_extension]: 101\n'
       '[protobuf_unittest.optional_import_enum_extension]: 102\n')
 def testmergebadextension(self):
   message = unittest_pb2.testallextensions()
   text = '[unknown_extension]: 8\n'
   self.assertraiseswithmessage(
       text_format.parseerror,
       '1:2 : extension "unknown_extension" not registered.',
       text_format.merge, text, message)
   message = unittest_pb2.testalltypes()
   self.assertraiseswithmessage(
       text_format.parseerror,
       ('1:2 : message type "protobuf_unittest.testalltypes" does not have '
        'extensions.'),
       text_format.merge, text, message)
 def testprintallextensions(self):
   message = unittest_pb2.testallextensions()
   test_util.setallextensions(message)
   self.comparetogoldenfile(
     self.removeredundantzeros(text_format.messagetostring(message)),
     'text_format_unittest_extensions_data.txt')