"""simple docstring"""




# This code is adapted from OpenAI's release
# https://github.com/openai/human-eval/blob/master/human_eval/execution.py

import contextlib
import faulthandler
import io
import multiprocessing
import os
import platform
import signal
import tempfile





def 							SCREAMING_SNAKE_CASE  (    _lowerCamelCase		: List[str]    ,_lowerCamelCase		: Tuple    ,_lowerCamelCase		: Any    ,_lowerCamelCase		: Tuple			) ->   List[Any]:
  _lowerCAmelCase		: Optional[int]						    =  multiprocessing.Manager()
  _lowerCAmelCase		: Optional[Any]						    =  manager.list()

  _lowerCAmelCase		: Dict						    =  multiprocessing.Process(target=_lowerCamelCase    ,args=(check_program, result, timeout)			)
  p.start()
  p.join(timeout=timeout + 1			)
  if p.is_alive():
    p.kill()

  if not result:
    result.append("""timed out"""			)

  return {
      "task_id": task_id,
      "passed": result[0] == "passed",
      "result": result[0],
      "completion_id": completion_id,
  }





def 							SCREAMING_SNAKE_CASE  (    _lowerCamelCase		: Dict    ,_lowerCamelCase		: Tuple    ,_lowerCamelCase		: Union[str, Any]			) ->   Any:
  with create_tempdir():
    # These system calls are needed when cleaning up tempdir.
    import os
    import shutil

    _lowerCAmelCase		: List[Any]						    =  shutil.rmtree
    _lowerCAmelCase		: List[Any]						    =  os.rmdir
    _lowerCAmelCase		: Optional[Any]						    =  os.chdir

    # Disable functionalities that can make destructive changes to the test.
    reliability_guard()

    # Run program.
    try:
      _lowerCAmelCase		: List[Any]						    =  {}
      with swallow_io():
        with time_limit(_lowerCamelCase			):
          exec(_lowerCamelCase    ,_lowerCamelCase			)
      result.append("""passed"""			)
    except TimeoutException:
      result.append("""timed out"""			)
    except BaseException as e:
      result.append(f"failed: {e}"			)

    # Needed for cleaning up.
    _lowerCAmelCase		: Tuple						    =  rmtree
    _lowerCAmelCase		: Optional[Any]						    =  rmdir
    _lowerCAmelCase		: List[Any]						    =  chdir





@contextlib.contextmanager
def 							SCREAMING_SNAKE_CASE  (    _lowerCamelCase		: Any			) ->   Union[str, Any]:
  def signal_handler(_lowerCamelCase		: List[str]    ,_lowerCamelCase		: str			):
    raise TimeoutException("""Timed out!"""			)

  signal.setitimer(signal.ITIMER_REAL    ,_lowerCamelCase			)
  signal.signal(signal.SIGALRM    ,_lowerCamelCase			)
  try:
    yield
  finally:
    signal.setitimer(signal.ITIMER_REAL    ,0			)





@contextlib.contextmanager
def 							SCREAMING_SNAKE_CASE  (    ) ->   List[Any]:
  _lowerCAmelCase		: Optional[Any]						    =  WriteOnlyStringIO()
  with contextlib.redirect_stdout(_lowerCamelCase			):
    with contextlib.redirect_stderr(_lowerCamelCase			):
      with redirect_stdin(_lowerCamelCase			):
        yield





@contextlib.contextmanager
def 							SCREAMING_SNAKE_CASE  (    ) ->   List[Any]:
  with tempfile.TemporaryDirectory() as dirname:
    with chdir(_lowerCamelCase			):
      yield dirname
class 		__A							(				SCREAMING_SNAKE_CASE_	):
     pass







class 		__A							(				io.StringIO	):






     def 					__A						(	self       ,  *a__       ,  **a__						):
       raise OSError






     def 					__A						(	self       ,  *a__       ,  **a__						):
       raise OSError






     def 					__A						(	self       ,  *a__       ,  **a__						):
       raise OSError






     def 					__A						(	self       ,  *a__       ,  **a__						):
       return False







class 		__A							(				contextlib._RedirectStream	):  # type: ignore
     _UpperCamelCase							:    Dict	      =	"stdin"







@contextlib.contextmanager
def 							SCREAMING_SNAKE_CASE  (    _lowerCamelCase		: Dict			) ->   Tuple:
  if root == ".":
    yield
    return
  _lowerCAmelCase		: List[Any]						    =  os.getcwd()
  os.chdir(_lowerCamelCase			)
  try:
    yield
  except BaseException as exc:
    raise exc
  finally:
    os.chdir(_lowerCamelCase			)






def 							SCREAMING_SNAKE_CASE  (    _lowerCamelCase		: List[Any]=None			) ->   int:

  if maximum_memory_bytes is not None:
    import resource

    resource.setrlimit(resource.RLIMIT_AS    ,(maximum_memory_bytes, maximum_memory_bytes)			)
    resource.setrlimit(resource.RLIMIT_DATA    ,(maximum_memory_bytes, maximum_memory_bytes)			)
    if not platform.uname().system == "Darwin":
      resource.setrlimit(resource.RLIMIT_STACK    ,(maximum_memory_bytes, maximum_memory_bytes)			)

  faulthandler.disable()

  import builtins

  _lowerCAmelCase		: Any						    =  None
  _lowerCAmelCase		: Tuple						    =  None

  import os

  _lowerCAmelCase		: int						    =  """1"""

  _lowerCAmelCase		: Union[str, Any]						    =  None
  _lowerCAmelCase		: int						    =  None
  _lowerCAmelCase		: Optional[int]						    =  None
  _lowerCAmelCase		: Any						    =  None
  _lowerCAmelCase		: int						    =  None
  _lowerCAmelCase		: Union[str, Any]						    =  None
  _lowerCAmelCase		: str						    =  None
  _lowerCAmelCase		: Optional[Any]						    =  None
  _lowerCAmelCase		: Dict						    =  None
  _lowerCAmelCase		: Optional[int]						    =  None
  _lowerCAmelCase		: Optional[Any]						    =  None
  _lowerCAmelCase		: Optional[int]						    =  None
  _lowerCAmelCase		: Tuple						    =  None
  _lowerCAmelCase		: str						    =  None
  _lowerCAmelCase		: Dict						    =  None
  _lowerCAmelCase		: List[str]						    =  None
  _lowerCAmelCase		: Any						    =  None
  _lowerCAmelCase		: Any						    =  None
  _lowerCAmelCase		: str						    =  None
  _lowerCAmelCase		: Any						    =  None
  _lowerCAmelCase		: str						    =  None
  _lowerCAmelCase		: Dict						    =  None
  _lowerCAmelCase		: List[Any]						    =  None
  _lowerCAmelCase		: Dict						    =  None
  _lowerCAmelCase		: Any						    =  None
  _lowerCAmelCase		: Union[str, Any]						    =  None
  _lowerCAmelCase		: Optional[Any]						    =  None

  import shutil

  _lowerCAmelCase		: Optional[Any]						    =  None
  _lowerCAmelCase		: Tuple						    =  None
  _lowerCAmelCase		: Optional[int]						    =  None

  import subprocess

  _lowerCAmelCase		: List[Any]						    =  None  # type: ignore

  _lowerCAmelCase		: Tuple						    =  None

  import sys

  _lowerCAmelCase		: Optional[Any]						    =  None
  _lowerCAmelCase		: Tuple						    =  None
  _lowerCAmelCase		: List[str]						    =  None
  _lowerCAmelCase		: List[str]						    =  None
  _lowerCAmelCase		: Dict						    =  None





"""simple docstring"""




import os
import unittest

from transformers.models.cpmant.tokenization_cpmant import VOCAB_FILES_NAMES, CpmAntTokenizer
from transformers.testing_utils import require_jieba, tooslow

from ...test_tokenization_common import TokenizerTesterMixin
@require_jieba
class 		__A							(				SCREAMING_SNAKE_CASE_					,			unittest.TestCase	):
     _UpperCamelCase							:    str	      =	CpmAntTokenizer
     _UpperCamelCase							:    List[Any]	      =	False






     def 					__A						(	self						):
       super().setUp()

       _lowerCAmelCase		: Dict						    =  [
           """<d>""",
           """</d>""",
           """<s>""",
           """</s>""",
           """</_>""",
           """<unk>""",
           """<pad>""",
           """</n>""",
           """我""",
           """是""",
           """C""",
           """P""",
           """M""",
           """A""",
           """n""",
           """t""",
       ]
       _lowerCAmelCase		: int						    =  os.path.join(self.tmpdirname       ,  VOCAB_FILES_NAMES["""vocab_file"""]						)
       with open(self.vocab_file       ,  """w"""       ,  encoding="""utf-8"""						) as vocab_writer:
         vocab_writer.write("""""".join([x + """\n""" for x in vocab_tokens]						)						)






     @tooslow
     def 					__A						(	self						):
       _lowerCAmelCase		: Tuple						    =  CpmAntTokenizer.from_pretrained("""openbmb/cpm-ant-10b"""						)
       _lowerCAmelCase		: Optional[Any]						    =  """今天天气真好！"""
       _lowerCAmelCase		: Any						    =  ["""今天""", """天气""", """真""", """好""", """！"""]
       _lowerCAmelCase		: str						    =  tokenizer.tokenize(a__						)
       self.assertListEqual(a__       ,  a__						)
       _lowerCAmelCase		: Tuple						    =  """今天天气真好！"""
       _lowerCAmelCase		: Optional[Any]						    =  [tokenizer.bos_token] + tokens

       _lowerCAmelCase		: Optional[int]						    =  [6, 9802, 14962, 2082, 831, 244]
       self.assertListEqual(tokenizer.convert_tokens_to_ids(a__						)       ,  a__						)

       _lowerCAmelCase		: Tuple						    =  tokenizer.decode(a__						)
       self.assertEqual(a__       ,  a__						)




