docstr: Test PyUnicode_DecodeUTF16Stateful()
docstr_tok: ["Test","PyUnicode_DecodeUTF16Stateful","(",")"]
code: def test_decodeutf16stateful(self):
      """Test PyUnicode_DecodeUTF16Stateful()"""
      decodeutf16stateful = _testcapi.unicode_decodeutf16stateful
  
      naturalbyteorder = -1 if sys.byteorder == "little" else 1
      for s in ["abc", "\xa1\xa2", "\u4f60\u597d", "a\U0001f600"]:
          b = s.encode("utf-16")
          self.assertEqual(
              decodeutf16stateful(0, b), (naturalbyteorder, s, len(b))
          )
          b = s.encode("utf-16le")
          self.assertEqual(decodeutf16stateful(-1, b), (-1, s, len(b)))
          self.assertEqual(
              decodeutf16stateful(0, b"\xff\xfe" + b),
              (-1, s, len(b) + 2),
          )
          b = s.encode("utf-16be")
          self.assertEqual(decodeutf16stateful(1, b), (1, s, len(b)))
          self.assertEqual(
              decodeutf16stateful(0, b"\xfe\xff" + b),
              (1, s, len(b) + 2),
          )
  
      self.assertEqual(
          decodeutf16stateful(-1, b"\x61\x00\x3d"), (-1, "a", 2)
      )
      self.assertEqual(
          decodeutf16stateful(-1, b"\x61\x00\x3d\xd8"), (-1, "a", 2)
      )
      self.assertEqual(
          decodeutf16stateful(-1, b"\x61\x00\x3d\xd8\x00"), (-1, "a", 2)
      )
      self.assertEqual(
          decodeutf16stateful(1, b"\x00\x61\xd8"), (1, "a", 2)
      )
      self.assertEqual(
          decodeutf16stateful(1, b"\x00\x61\xd8\x3d"), (1, "a", 2)
      )
      self.assertEqual(
          decodeutf16stateful(1, b"\x00\x61\xd8\x3d\xde"), (1, "a", 2)
      )
      self.assertEqual(
          decodeutf16stateful(0, b"\xff\xfe\x61\x00\x3d\xd8\x00"),
          (-1, "a", 4),
      )
      self.assertEqual(
          decodeutf16stateful(0, b"\xfe\xff\x00\x61\xd8\x3d\xde"),
          (1, "a", 4),
      )
  
      self.assertRaises(
          UnicodeDecodeError, decodeutf16stateful, -1, b"\x00\xde"
      )
      self.assertRaises(
          UnicodeDecodeError, decodeutf16stateful, 1, b"\xde\x00"
      )
      self.assertRaises(
          UnicodeDecodeError, decodeutf16stateful, 0, b"\xde\xde"
      )
      self.assertEqual(
          decodeutf16stateful(-1, b"\x00\xde", "replace"),
          (-1, "\ufffd", 2),
      )
      self.assertEqual(
          decodeutf16stateful(1, b"\xde\x00", "replace"),
          (1, "\ufffd", 2),
      )
      self.assertEqual(
          decodeutf16stateful(0, b"\xde\xde", "replace"),
          (0, "\ufffd", 2),
      )
      self.assertEqual(
          decodeutf16stateful(0, b"\xff\xfe\x00\xde", "replace"),
          (-1, "\ufffd", 4),
      )
      self.assertEqual(
          decodeutf16stateful(0, b"\xfe\xff\xde\x00", "replace"),
          (1, "\ufffd", 4),
      )
  
      self.assertRaises(
          UnicodeDecodeError,
          decodeutf16stateful,
          -1,
          b"\x3d\xd8\x61\x00",
      )
      self.assertEqual(
          decodeutf16stateful(-1, b"\x3d\xd8\x61\x00", "replace"),
          (-1, "\ufffda", 4),
      )
      self.assertRaises(
          UnicodeDecodeError,
          decodeutf16stateful,
          1,
          b"\xd8\x3d\x00\x61",
      )
      self.assertEqual(
          decodeutf16stateful(1, b"\xd8\x3d\x00\x61", "replace"),
          (1, "\ufffda", 4),
      )
  
      self.assertRaises(
          LookupError, decodeutf16stateful, -1, b"\x00\xde", "foo"
      )
      self.assertRaises(
          LookupError, decodeutf16stateful, 1, b"\xde\x00", "foo"
      )
      self.assertRaises(
          LookupError, decodeutf16stateful, 0, b"\xde\xde", "foo"
      )
  
imports: import unittest
  import sys
  from test.support import import_helper
label_desc: Use image node_id 8 for calling the CAPITest obj's underlying member method code with example usage: obj.test_decodeutf16stateful() without return types