
"""simple docstring"""






import os
import unittest

from transformers import BatchEncoding
from transformers.models.bert.tokenization_bert import (
    BasicTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.models.prophetnet.tokenization_prophetnet import VOCAB_FILES_NAMES, ProphetNetTokenizer
from transformers.testing_utils import require_torch, slow

from ...test_tokenization_common import TokenizerTesterMixin





class 				a__					(						A__   ,							unittest.TestCase       ):
     UpperCAmelCase__         =      ProphetNetTokenizer
     UpperCAmelCase__         =      False



     def  lowerCamelCase_						(							self :List[Any]   ):







      '''simple docstring'''



      super().setUp()

      UpperCamelCase_     :					Union[str, Any]   	=[
          '[UNK]',
          '[CLS]',
          '[SEP]',
          '[PAD]',
          '[MASK]',
          'want',
          '##want',
          '##ed',
          'wa',
          'un',
          'runn',
          '##ing',
          ',',
          'low',
          'lowest',
      ]
      UpperCamelCase_     :					Optional[Any]   	=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]   )   )



     def  lowerCamelCase_						(							self :Any      ,  _lowerCamelCase :str   ):







      '''simple docstring'''



      UpperCamelCase_     :					Dict   	='UNwant\u00E9d,running'
      UpperCamelCase_     :					Union[str, Any]   	='unwanted, running'
      return input_text, output_text



     def  lowerCamelCase_						(							self :Union[str, Any]   ):







      '''simple docstring'''



      UpperCamelCase_     :					Tuple   	=self.tokenizer_class(self.vocab_file   )

      UpperCamelCase_     :					Optional[int]   	=tokenizer.tokenize('UNwant\u00E9d,running'   )
      self.assertListEqual(_lowerCamelCase      ,  ['un', '##want', '##ed', ',', 'runn', '##ing']   )
      self.assertListEqual(tokenizer.convert_tokens_to_ids(_lowerCamelCase   )      ,  [9, 6, 7, 12, 10, 11]   )



     def  lowerCamelCase_						(							self :Any   ):







      '''simple docstring'''



      UpperCamelCase_     :					Tuple   	=BasicTokenizer()

      self.assertListEqual(tokenizer.tokenize('ah\u535A\u63A8zz'   )      ,  ['ah', '\u535A', '\u63A8', 'zz']   )



     def  lowerCamelCase_						(							self :Tuple   ):







      '''simple docstring'''



      UpperCamelCase_     :					int   	=BasicTokenizer(do_lower_case=_lowerCamelCase   )

      self.assertListEqual(
          tokenizer.tokenize(' \tHeLLo!how  \n Are yoU?  '   )      ,  ['hello', '!', 'how', 'are', 'you', '?']   )
      self.assertListEqual(tokenizer.tokenize('H\u00E9llo'   )      ,  ['hello']   )



     def  lowerCamelCase_						(							self :List[Any]   ):







      '''simple docstring'''



      UpperCamelCase_     :					Dict   	=BasicTokenizer(do_lower_case=_lowerCamelCase      ,  strip_accents=_lowerCamelCase   )

      self.assertListEqual(
          tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '   )      ,  ['hällo', '!', 'how', 'are', 'you', '?']   )
      self.assertListEqual(tokenizer.tokenize('H\u00E9llo'   )      ,  ['h\u00E9llo']   )



     def  lowerCamelCase_						(							self :List[str]   ):







      '''simple docstring'''



      UpperCamelCase_     :					Dict   	=BasicTokenizer(do_lower_case=_lowerCamelCase      ,  strip_accents=_lowerCamelCase   )

      self.assertListEqual(
          tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '   )      ,  ['hallo', '!', 'how', 'are', 'you', '?']   )
      self.assertListEqual(tokenizer.tokenize('H\u00E9llo'   )      ,  ['hello']   )



     def  lowerCamelCase_						(							self :Optional[int]   ):







      '''simple docstring'''



      UpperCamelCase_     :					Any   	=BasicTokenizer(do_lower_case=_lowerCamelCase   )

      self.assertListEqual(
          tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '   )      ,  ['hallo', '!', 'how', 'are', 'you', '?']   )
      self.assertListEqual(tokenizer.tokenize('H\u00E9llo'   )      ,  ['hello']   )



     def  lowerCamelCase_						(							self :Optional[Any]   ):







      '''simple docstring'''



      UpperCamelCase_     :					int   	=BasicTokenizer(do_lower_case=_lowerCamelCase   )

      self.assertListEqual(
          tokenizer.tokenize(' \tHeLLo!how  \n Are yoU?  '   )      ,  ['HeLLo', '!', 'how', 'Are', 'yoU', '?']   )



     def  lowerCamelCase_						(							self :Tuple   ):







      '''simple docstring'''



      UpperCamelCase_     :					List[Any]   	=BasicTokenizer(do_lower_case=_lowerCamelCase      ,  strip_accents=_lowerCamelCase   )

      self.assertListEqual(
          tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '   )      ,  ['HäLLo', '!', 'how', 'Are', 'yoU', '?']   )



     def  lowerCamelCase_						(							self :str   ):







      '''simple docstring'''



      UpperCamelCase_     :					List[str]   	=BasicTokenizer(do_lower_case=_lowerCamelCase      ,  strip_accents=_lowerCamelCase   )

      self.assertListEqual(
          tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '   )      ,  ['HaLLo', '!', 'how', 'Are', 'yoU', '?']   )



     def  lowerCamelCase_						(							self :Any   ):







      '''simple docstring'''



      UpperCamelCase_     :					Tuple   	=BasicTokenizer(do_lower_case=_lowerCamelCase      ,  never_split=['[UNK]']   )

      self.assertListEqual(
          tokenizer.tokenize(' \tHeLLo!how  \n Are yoU? [UNK]'   )      ,  ['HeLLo', '!', 'how', 'Are', 'yoU', '?', '[UNK]']   )



     def  lowerCamelCase_						(							self :str   ):







      '''simple docstring'''



      UpperCamelCase_     :					Tuple   	=['[UNK]', '[CLS]', '[SEP]', 'want', '##want', '##ed', 'wa', 'un', 'runn', '##ing']

      UpperCamelCase_     :					Union[str, Any]   	={}
      for i, token in enumerate(_lowerCamelCase   ):
       UpperCamelCase_     :					List[str]   	=i
      UpperCamelCase_     :					Dict   	=WordpieceTokenizer(vocab=_lowerCamelCase      ,  unk_token='[UNK]'   )

      self.assertListEqual(tokenizer.tokenize(''   )      ,  []   )

      self.assertListEqual(tokenizer.tokenize('unwanted running'   )      ,  ['un', '##want', '##ed', 'runn', '##ing']   )

      self.assertListEqual(tokenizer.tokenize('unwantedX running'   )      ,  ['[UNK]', 'runn', '##ing']   )



     @require_torch
     def  lowerCamelCase_						(							self :str   ):







      '''simple docstring'''



      UpperCamelCase_     :					Union[str, Any]   	=self.tokenizer_class.from_pretrained('microsoft/prophetnet-large-uncased'   )

      UpperCamelCase_     :					List[Any]   	=['A long paragraph for summarization.', 'Another paragraph for summarization.']
      UpperCamelCase_     :					Union[str, Any]   	=[1_037, 2_146, 20_423, 2_005, 7_680, 7_849, 3_989, 1_012, 102]
      UpperCamelCase_     :					str   	=tokenizer(_lowerCamelCase      ,  padding=_lowerCamelCase      ,  return_tensors='pt'   )
      self.assertIsInstance(_lowerCamelCase      ,  _lowerCamelCase   )
      UpperCamelCase_     :					int   	=list(batch.input_ids.numpy()[0]   )
      self.assertListEqual(_lowerCamelCase      ,  _lowerCamelCase   )

      self.assertEqual((2, 9)      ,  batch.input_ids.shape   )
      self.assertEqual((2, 9)      ,  batch.attention_mask.shape   )



     def  lowerCamelCase_						(							self :int   ):







      '''simple docstring'''



      self.assertTrue(_is_whitespace(' '   )   )
      self.assertTrue(_is_whitespace('\t'   )   )
      self.assertTrue(_is_whitespace('\r'   )   )
      self.assertTrue(_is_whitespace('\n'   )   )
      self.assertTrue(_is_whitespace('\u00A0'   )   )

      self.assertFalse(_is_whitespace('A'   )   )
      self.assertFalse(_is_whitespace('-'   )   )



     def  lowerCamelCase_						(							self :Any   ):







      '''simple docstring'''



      self.assertTrue(_is_control('\u0005'   )   )

      self.assertFalse(_is_control('A'   )   )
      self.assertFalse(_is_control(' '   )   )
      self.assertFalse(_is_control('\t'   )   )
      self.assertFalse(_is_control('\r'   )   )



     def  lowerCamelCase_						(							self :Dict   ):







      '''simple docstring'''



      self.assertTrue(_is_punctuation('-'   )   )
      self.assertTrue(_is_punctuation('$'   )   )
      self.assertTrue(_is_punctuation('`'   )   )
      self.assertTrue(_is_punctuation('.'   )   )

      self.assertFalse(_is_punctuation('A'   )   )
      self.assertFalse(_is_punctuation(' '   )   )




     @slow
     def  lowerCamelCase_						(							self :Dict   ):







      '''simple docstring'''



      UpperCamelCase_     :					Union[str, Any]   	=self.tokenizer_class.from_pretrained('microsoft/prophetnet-large-uncased'   )

      UpperCamelCase_     :					Any   	=tokenizer.encode('sequence builders'      ,  add_special_tokens=_lowerCamelCase   )
      UpperCamelCase_     :					Dict   	=tokenizer.encode('multi-sequence build'      ,  add_special_tokens=_lowerCamelCase   )

      UpperCamelCase_     :					Any   	=tokenizer.build_inputs_with_special_tokens(_lowerCamelCase   )
      UpperCamelCase_     :					List[str]   	=tokenizer.build_inputs_with_special_tokens(_lowerCamelCase      ,  _lowerCamelCase   )

      assert encoded_sentence == text + [102]
      assert encoded_pair == text + [102] + text_a + [102]


"""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       A_  (				__lowercase						,	__lowercase						,	__lowercase						,	__lowercase	):
 UpperCamelCase_     :					Tuple   	=multiprocessing.Manager()
 UpperCamelCase_     :					Dict   	=manager.list()

 UpperCamelCase_     :					Union[str, Any]   	=multiprocessing.Process(target=__lowercase						,	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       A_  (				__lowercase						,	__lowercase						,	__lowercase	):
 with create_tempdir():
  # These system calls are needed when cleaning up tempdir.
  import os
  import shutil

  UpperCamelCase_     :					Tuple   	=shutil.rmtree
  UpperCamelCase_     :					List[str]   	=os.rmdir
  UpperCamelCase_     :					Any   	=os.chdir

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

  # Run program.
  try:
   UpperCamelCase_     :					List[str]   	={}
   with swallow_io():
    with time_limit(__lowercase	):
     exec(__lowercase						,	__lowercase	)
   result.append('passed'	)
  except TimeoutException:
   result.append('timed out'	)
  except BaseException as e:
   result.append(F'''failed: {e}'''	)

  # Needed for cleaning up.
  UpperCamelCase_     :					Optional[Any]   	=rmtree
  UpperCamelCase_     :					str   	=rmdir
  UpperCamelCase_     :					Dict   	=chdir




@contextlib.contextmanager
def       A_  (				__lowercase	):
 def signal_handler(__lowercase						,	__lowercase	):
  raise TimeoutException('Timed out!'	)

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




@contextlib.contextmanager
def       A_  (				):
 UpperCamelCase_     :					str   	=WriteOnlyStringIO()
 with contextlib.redirect_stdout(__lowercase	):
  with contextlib.redirect_stderr(__lowercase	):
   with redirect_stdin(__lowercase	):
    yield




@contextlib.contextmanager
def       A_  (				):
 with tempfile.TemporaryDirectory() as dirname:
  with chdir(__lowercase	):
   yield dirname





class 				a__					(						A__       ):
     pass





class 				a__					(						io.StringIO       ):



     def  lowerCamelCase_						(							self :Any      ,  *_lowerCamelCase :Any      ,  **_lowerCamelCase :Tuple   ):







      '''simple docstring'''



      raise OSError



     def  lowerCamelCase_						(							self :Union[str, Any]      ,  *_lowerCamelCase :Any      ,  **_lowerCamelCase :Tuple   ):







      '''simple docstring'''



      raise OSError



     def  lowerCamelCase_						(							self :Tuple      ,  *_lowerCamelCase :str      ,  **_lowerCamelCase :List[str]   ):







      '''simple docstring'''



      raise OSError




     def  lowerCamelCase_						(							self :List[str]      ,  *_lowerCamelCase :Optional[int]      ,  **_lowerCamelCase :str   ):







      '''simple docstring'''



      return False





class 				a__					(						contextlib._RedirectStream       ):  # type: ignore
     UpperCAmelCase__         =      '''stdin'''




@contextlib.contextmanager
def       A_  (				__lowercase	):
 if root == ".":
  yield
  return
 UpperCamelCase_     :					List[str]   	=os.getcwd()
 os.chdir(__lowercase	)
 try:
  yield
 except BaseException as exc:
  raise exc
 finally:
  os.chdir(__lowercase	)





def       A_  (				__lowercase=None	):

 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

 UpperCamelCase_     :					Any   	=None
 UpperCamelCase_     :					Any   	=None

 import os

 UpperCamelCase_     :					Union[str, Any]   	='1'

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

 import shutil

 UpperCamelCase_     :					List[str]   	=None
 UpperCamelCase_     :					Optional[Any]   	=None
 UpperCamelCase_     :					Dict   	=None

 import subprocess

 UpperCamelCase_     :					Optional[int]   	=None  # type: ignore

 UpperCamelCase_     :					Union[str, Any]   	=None

 import sys

 UpperCamelCase_     :					Union[str, Any]   	=None
 UpperCamelCase_     :					Tuple   	=None
 UpperCamelCase_     :					Union[str, Any]   	=None
 UpperCamelCase_     :					Dict   	=None
 UpperCamelCase_     :					Any   	=None
