def testSurrogatesInPython3(self):
    # Surrogates like U+D83D is an invalid unicode character, it is
    # supported by Python2 only because in some builds, unicode strings
    # use 2-bytes code units. Since Python 3.3, we don't have this problem.
    #
    # Surrogates are utf16 code units, in a unicode string they are invalid
    # characters even when they appear in pairs like u'\ud801\udc01'. Protobuf
    # Python3 reject such cases at setters and parsers. Python2 accpect it
    # to keep same features with the language itself. 'Unpaired pairs'
    # like u'\ud801' are rejected at parsers when strict utf8 check is enabled
    # in proto3 to keep same behavior with c extension.

    # Surrogates are rejected at setters in Python3.
    with self.assertRaises(ValueError):
      unittest_proto3_arena_pb2.TestAllTypes(
          optional_string=u'\ud801\udc01')
    with self.assertRaises(ValueError):
      unittest_proto3_arena_pb2.TestAllTypes(
          optional_string=b'\xed\xa0\x81')
    with self.assertRaises(ValueError):
      unittest_proto3_arena_pb2.TestAllTypes(
          optional_string=u'\ud801')
    with self.assertRaises(ValueError):
      unittest_proto3_arena_pb2.TestAllTypes(
          optional_string=u'\ud801\ud801')