docstr: Test PyUnicode_AsCharmapString()
docstr_tok: ["Test","PyUnicode_AsCharmapString","(",")"]
code: def test_ascharmapstring(self):
      """Test PyUnicode_AsCharmapString()"""
      ascharmapstring = _testcapi.unicode_ascharmapstring
  
      self.assertEqual(
          ascharmapstring("abc", {97: 3, 98: 0, 99: 7}), b"\3\0\7"
      )
      self.assertEqual(
          ascharmapstring("\xa1\xa2\xa3", {0xA1: 3, 0xA2: 0, 0xA3: 7}),
          b"\3\0\7",
      )
      self.assertEqual(
          ascharmapstring(
              "\u4f60\u597d\u4e16", {0x4F60: 3, 0x597D: 0, 0x4E16: 7}
          ),
          b"\3\0\7",
      )
      self.assertEqual(
          ascharmapstring(
              "\U0001f600\U0001f601\U0001f602",
              {0x1F600: 3, 0x1F601: 0, 0x1F602: 7},
          ),
          b"\3\0\7",
      )
      self.assertEqual(
          ascharmapstring("abc", {97: 3, 98: b"", 99: b"spam"}),
          b"\3spam",
      )
  
      self.assertRaises(UnicodeEncodeError, ascharmapstring, "a", {})
      self.assertRaises(
          UnicodeEncodeError, ascharmapstring, "a", {97: None}
      )
      self.assertRaises(TypeError, ascharmapstring, b"a", {})
      self.assertRaises(TypeError, ascharmapstring, [], {})
      self.assertRaises(TypeError, ascharmapstring, "a", NULL)
  
imports: import unittest
  import sys
  from test.support import import_helper
label_desc: Use image node_id 18 for calling the CAPITest obj's underlying member method code with example usage: obj.test_ascharmapstring() without return types