def testSurrogatesInPython2(self):
    # Test optional_string=u'\ud801\udc01'.
    # surrogate pair is acceptable in python2.
    msg = unittest_proto3_arena_pb2.TestAllTypes(
        optional_string=u'\ud801\udc01')
    # TODO(jieluo): Change pure python to have same behavior with c extension.
    # Some build in python2 consider u'\ud801\udc01' and u'\U00010401' are
    # equal, some are not equal.
    if api_implementation.Type() == 'python':
      self.assertEqual(msg.optional_string, u'\ud801\udc01')
    else:
      self.assertEqual(msg.optional_string, u'\U00010401')
    serialized = msg.SerializeToString()
    msg2 = unittest_proto3_arena_pb2.TestAllTypes()
    msg2.MergeFromString(serialized)
    self.assertEqual(msg2.optional_string, u'\U00010401')

    # Python2 does not reject surrogates at setters.
    msg = unittest_proto3_arena_pb2.TestAllTypes(
        optional_string=b'\xed\xa0\x81')
    unittest_proto3_arena_pb2.TestAllTypes(
        optional_string=u'\ud801')
    unittest_proto3_arena_pb2.TestAllTypes(
        optional_string=u'\ud801\ud801')