-Make message CopyFrom() call UPB code instead of default implementation for python UPB

-Add upb_Message_Clear() in UPB accessors
-Add upb_Message_CopyFrom() in UPB copy
-Fix UPB upb_Message_DeepClone() bug for repeated extensions

PiperOrigin-RevId: 527644009
pull/12588/head
Jie Luo 2 years ago committed by Copybara-Service
parent 167e3e5081
commit e202f31b78
  1. 27
      python/google/protobuf/internal/message_test.py

@ -1373,6 +1373,33 @@ class Proto2Test(unittest.TestCase):
123, 123,
msg1.submessage.Extensions[more_extensions_pb2.optional_int_extension]) msg1.submessage.Extensions[more_extensions_pb2.optional_int_extension])
def testCopyFromAll(self):
message = unittest_pb2.TestAllTypes()
test_util.SetAllFields(message)
copy = unittest_pb2.TestAllTypes()
copy.CopyFrom(message)
self.assertEqual(message, copy)
message.repeated_nested_message.add().bb = 123
self.assertNotEqual(message, copy)
def testCopyFromAllExtensions(self):
all_set = unittest_pb2.TestAllExtensions()
test_util.SetAllExtensions(all_set)
copy = unittest_pb2.TestAllExtensions()
copy.CopyFrom(all_set)
self.assertEqual(all_set, copy)
all_set.Extensions[unittest_pb2.repeatedgroup_extension].add().a = 321
self.assertNotEqual(all_set, copy)
def testCopyFromAllPackedExtensions(self):
all_set = unittest_pb2.TestPackedExtensions()
test_util.SetAllPackedExtensions(all_set)
copy = unittest_pb2.TestPackedExtensions()
copy.CopyFrom(all_set)
self.assertEqual(all_set, copy)
all_set.Extensions[unittest_pb2.packed_float_extension].extend([61.0, 71.0])
self.assertNotEqual(all_set, copy)
def testGoldenExtensions(self): def testGoldenExtensions(self):
golden_data = test_util.GoldenFileData('golden_message') golden_data = test_util.GoldenFileData('golden_message')
golden_message = unittest_pb2.TestAllExtensions() golden_message = unittest_pb2.TestAllExtensions()

Loading…
Cancel
Save