docstr: Test PyUnicode_FromStringAndSize()
docstr_tok: ["Test","PyUnicode_FromStringAndSize","(",")"]
code: def test_fromstringandsize(self):
      """Test PyUnicode_FromStringAndSize()"""
      from _testcapi import (
          unicode_fromstringandsize as fromstringandsize,
      )
  
      self.assertEqual(fromstringandsize(b"abc"), "abc")
      self.assertEqual(fromstringandsize(b"abc", 2), "ab")
      self.assertEqual(fromstringandsize(b"abc\0def"), "abc\0def")
      self.assertEqual(
          fromstringandsize(b"\xc2\xa1\xc2\xa2"), "\xa1\xa2"
      )
      self.assertEqual(fromstringandsize(b"\xe4\xbd\xa0"), "\u4f60")
      self.assertEqual(
          fromstringandsize(b"\xf0\x9f\x98\x80"), "\U0001f600"
      )
      self.assertRaises(
          UnicodeDecodeError, fromstringandsize, b"\xc2\xa1", 1
      )
      self.assertRaises(
          UnicodeDecodeError, fromstringandsize, b"\xa1", 1
      )
      self.assertEqual(fromstringandsize(b"", 0), "")
      self.assertEqual(fromstringandsize(NULL, 0), "")
  
      self.assertRaises(
          MemoryError, fromstringandsize, b"abc", PY_SSIZE_T_MAX
      )
      self.assertRaises(SystemError, fromstringandsize, b"abc", -1)
      self.assertRaises(
          SystemError, fromstringandsize, b"abc", PY_SSIZE_T_MIN
      )
      self.assertRaises(SystemError, fromstringandsize, NULL, -1)
      self.assertRaises(
          SystemError, fromstringandsize, NULL, PY_SSIZE_T_MIN
      )
      self.assertRaises(SystemError, fromstringandsize, NULL, 3)
      self.assertRaises(
          SystemError, fromstringandsize, NULL, PY_SSIZE_T_MAX
      )
  
imports: import unittest
  import sys
  from test import support
  from test.support import import_helper
label_desc: Use image node_id 7 for calling the CAPITest obj's underlying member method code with example usage: obj.test_fromstringandsize() without return types