docstr: Test PyUnicode_Translate()
docstr_tok: ["Test","PyUnicode_Translate","(",")"]
code: def test_translate(self):
      """Test PyUnicode_Translate()"""
      from _testcapi import unicode_translate as translate
  
      self.assertEqual(
          translate(
              "abcd",
              {ord("a"): "A", ord("b"): ord("B"), ord("c"): "<>"},
          ),
          "AB<>d",
      )
      self.assertEqual(
          translate(
              "абвг",
              {ord("а"): "А", ord("б"): ord("Б"), ord("в"): "<>"},
          ),
          "АБ<>г",
      )
      self.assertEqual(translate("abc", {}), "abc")
      self.assertEqual(translate("abc", []), "abc")
      self.assertRaises(
          UnicodeTranslateError, translate, "abc", {ord("b"): None}
      )
      self.assertRaises(
          UnicodeTranslateError,
          translate,
          "abc",
          {ord("b"): None},
          "strict",
      )
      self.assertRaises(
          LookupError, translate, "abc", {ord("b"): None}, "foo"
      )
      self.assertEqual(
          translate("abc", {ord("b"): None}, "ignore"), "ac"
      )
      self.assertEqual(
          translate("abc", {ord("b"): None}, "replace"), "a\ufffdc"
      )
      self.assertEqual(
          translate("abc", {ord("b"): None}, "backslashreplace"),
          r"a\x62c",
      )
      # XXX Other error handlers do not support UnicodeTranslateError
      self.assertRaises(TypeError, translate, b"abc", [])
      self.assertRaises(TypeError, translate, 123, [])
      self.assertRaises(TypeError, translate, "abc", {ord("a"): b"A"})
      self.assertRaises(TypeError, translate, "abc", 123)
      self.assertRaises(TypeError, translate, "abc", NULL)
      self.assertRaises(
          LookupError, translate, "abc", {ord("b"): None}, "foo"
      )
  
imports: import unittest
  import sys
  from test import support
  from test.support import import_helper
label_desc: Use image node_id 33 for calling the CAPITest obj's underlying member method code with example usage: obj.test_translate() without return types