docstr: Test PyUnicode_AsEncodedString()
docstr_tok: ["Test","PyUnicode_AsEncodedString","(",")"]
code: def test_asencodedstring(self):
      """Test PyUnicode_AsEncodedString()"""
      asencodedstring = _testcapi.unicode_asencodedstring
  
      self.assertEqual(asencodedstring("abc", NULL), b"abc")
      self.assertEqual(asencodedstring("abc", "ascii"), b"abc")
      s = "a\xa1\u4f60\U0001f600"
      b = b"a\xc2\xa1\xe4\xbd\xa0\xf0\x9f\x98\x80"
      self.assertEqual(asencodedstring(s, NULL), b)
      self.assertEqual(asencodedstring(s, "utf-8"), b)
      self.assertEqual(
          asencodedstring("\xa1\xa2", "latin1"), b"\xa1\xa2"
      )
      self.assertRaises(
          UnicodeEncodeError, asencodedstring, "\xa1\xa2", "ascii"
      )
      self.assertEqual(asencodedstring(s, "ascii", "replace"), b"a???")
  
      self.assertRaises(LookupError, asencodedstring, "abc", "foo")
      self.assertRaises(LookupError, asencodedstring, s, "ascii", "foo")
      self.assertRaises(TypeError, asencodedstring, b"abc", NULL)
      self.assertRaises(TypeError, asencodedstring, b"abc", "ascii")
      self.assertRaises(TypeError, asencodedstring, [], NULL)
      self.assertRaises(TypeError, asencodedstring, [], "ascii")
  
imports: import unittest
  import sys
  from test.support import import_helper
label_desc: Use image node_id 3 for calling the CAPITest obj's underlying member method code with example usage: obj.test_asencodedstring() without return types