



import functools
import logging
import os
import sys
import threading
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

import huggingface_hub.utils as hf_hub_utils
from tqdm import auto as tqdm_lib


_snake_case		=  threading.Lock()
_snake_case		=  None

_snake_case		=  {
    "debug": logging.DEBUG,
    "info": logging.INFO,
    "warning": logging.WARNING,
    "error": logging.ERROR,
    "critical": logging.CRITICAL,
}

_snake_case		=  logging.WARNING

_snake_case		=  True






def 				A				(					):





							'''simple docstring'''




							_lowerCAmelCase     :							Tuple    =    os.getenv("TRANSFORMERS_VERBOSITY"				, _lowerCamelCase  )
							if env_level_str:
														if env_level_str in log_levels:
																					return log_levels[env_level_str]
														else:
																					logging.getLogger().warning(
																					    F"Unknown option TRANSFORMERS_VERBOSITY={env_level_str}, "
																					    F"has to be one of: { ', '.join(log_levels.keys()  ) }"  )
							return _default_log_level






def 				A				(					):





							'''simple docstring'''




							return __name__.split("."  )[0]






def 				A				(					):





							'''simple docstring'''




							return logging.getLogger(_get_library_name()  )






def 				A				(					):





							'''simple docstring'''




							global _default_handler

							with _lock:
														if _default_handler:
																					# This library has already configured the library root logger.
																					return
														_lowerCAmelCase     :							Union[str, Any]    =    logging.StreamHandler()  # Set sys.stderr as stream.
														_lowerCAmelCase     :							Tuple    =    sys.stderr.flush

														# Apply our default configuration to the library root logger.
														_lowerCAmelCase     :							Tuple    =    _get_library_root_logger()
														library_root_logger.addHandler(_default_handler  )
														library_root_logger.setLevel(_get_default_logging_level()  )
														_lowerCAmelCase     :							List[Any]    =    False






def 				A				(					):





							'''simple docstring'''




							global _default_handler

							with _lock:
														if not _default_handler:
																					return

														_lowerCAmelCase     :							Tuple    =    _get_library_root_logger()
														library_root_logger.removeHandler(_default_handler  )
														library_root_logger.setLevel(logging.NOTSET  )
														_lowerCAmelCase     :							List[str]    =    None






def 				A				(					):





							'''simple docstring'''




							return log_levels






def 				A				(					_lowerCamelCase = None  ):





							'''simple docstring'''




							if name is None:
														_lowerCAmelCase     :							Union[str, Any]    =    _get_library_name()

							_configure_library_root_logger()
							return logging.getLogger(_lowerCamelCase  )






def 				A				(					):





							'''simple docstring'''




							_configure_library_root_logger()
							return _get_library_root_logger().getEffectiveLevel()






def 				A				(					_lowerCamelCase  ):





							'''simple docstring'''




							_configure_library_root_logger()
							_get_library_root_logger().setLevel(_lowerCamelCase  )






def 				A				(					):





							'''simple docstring'''




							return set_verbosity(_lowerCamelCase  )






def 				A				(					):





							'''simple docstring'''




							return set_verbosity(_lowerCamelCase  )






def 				A				(					):





							'''simple docstring'''




							return set_verbosity(_lowerCamelCase  )






def 				A				(					):





							'''simple docstring'''




							return set_verbosity(_lowerCamelCase  )






def 				A				(					):





							'''simple docstring'''




							_configure_library_root_logger()

							assert _default_handler is not None
							_get_library_root_logger().removeHandler(_default_handler  )






def 				A				(					):





							'''simple docstring'''




							_configure_library_root_logger()

							assert _default_handler is not None
							_get_library_root_logger().addHandler(_default_handler  )






def 				A				(					_lowerCamelCase  ):





							'''simple docstring'''




							_configure_library_root_logger()

							assert handler is not None
							_get_library_root_logger().addHandler(_lowerCamelCase  )






def 				A				(					_lowerCamelCase  ):





							'''simple docstring'''




							_configure_library_root_logger()

							assert handler is not None and handler not in _get_library_root_logger().handlers
							_get_library_root_logger().removeHandler(_lowerCamelCase  )






def 				A				(					):





							'''simple docstring'''




							_configure_library_root_logger()
							_lowerCAmelCase     :							Union[str, Any]    =    False






def 				A				(					):





							'''simple docstring'''




							_configure_library_root_logger()
							_lowerCAmelCase     :							int    =    True






def 				A				(					):





							'''simple docstring'''




							_lowerCAmelCase     :							str    =    _get_library_root_logger().handlers

							for handler in handlers:
														_lowerCAmelCase     :							Union[str, Any]    =    logging.Formatter("[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s"  )
														handler.setFormatter(_lowerCamelCase  )






def 				A				(					):





							'''simple docstring'''




							_lowerCAmelCase     :							int    =    _get_library_root_logger().handlers

							for handler in handlers:
														handler.setFormatter(_lowerCamelCase  )






def 				A				(					self				, *_lowerCamelCase				, **_lowerCamelCase  ):





							'''simple docstring'''




							_lowerCAmelCase     :							Union[str, Any]    =    os.getenv("TRANSFORMERS_NO_ADVISORY_WARNINGS"				, _lowerCamelCase  )
							if no_advisory_warnings:
														return
							self.warning(*_lowerCamelCase				, **_lowerCamelCase  )


_snake_case		=  warning_advice






@functools.lru_cache(_lowerCamelCase  )
def 				A				(					self				, *_lowerCamelCase				, **_lowerCamelCase  ):





							'''simple docstring'''




							self.warning(*_lowerCamelCase				, **_lowerCamelCase  )


_snake_case		=  warning_once



class   UpperCAmelCase_    :







							def __init__(   self,			*__a,			**__a):  # pylint: disable=unused-argument

														'''simple docstring'''

														_lowerCAmelCase     :							Union[str, Any]    =    args[0] if args else None







							def __iter__(   self):

														'''simple docstring'''

														return iter(self._iterator)







							def __getattr__(   self,			__a):

														'''simple docstring'''

														def empty_fn(*__a,			**__a):  # pylint: disable=unused-argument
																					return

														return empty_fn







							def __enter__(   self):

														'''simple docstring'''

														return self







							def __exit__(   self,			__a,			__a,			__a):

														'''simple docstring'''

														return



class   UpperCAmelCase_    :







							def __call__(   self,			*__a,			**__a):

														'''simple docstring'''

														if _tqdm_active:
																					return tqdm_lib.tqdm(*__a,			**__a)
														else:
																					return EmptyTqdm(*__a,			**__a)







							def    snake_case__      (   self,			*__a,			**__a):

														'''simple docstring'''

														_lowerCAmelCase     :							List[str]    =    None
														if _tqdm_active:
																					return tqdm_lib.tqdm.set_lock(*__a,			**__a)







							def    snake_case__      (   self):

														'''simple docstring'''

														if _tqdm_active:
																					return tqdm_lib.tqdm.get_lock()



_snake_case		=  _tqdm_cls()






def 				A				(					):





							'''simple docstring'''




							global _tqdm_active
							return bool(_tqdm_active  )






def 				A				(					):





							'''simple docstring'''




							global _tqdm_active
							_lowerCAmelCase     :							int    =    True
							hf_hub_utils.enable_progress_bars()






def 				A				(					):





							'''simple docstring'''




							global _tqdm_active
							_lowerCAmelCase     :							Optional[Any]    =    False
							hf_hub_utils.disable_progress_bars()




'''simple docstring'''

import json
import os
import unittest

from transformers.models.blenderbot_small.tokenization_blenderbot_small import (
    VOCAB_FILES_NAMES,
    BlenderbotSmallTokenizer,
)

from ...test_tokenization_common import TokenizerTesterMixin





class      snake_case    (    lowercase			,						unittest.TestCase			):





  """simple docstring"""




  _lowerCamelCase		    =  BlenderbotSmallTokenizer
  _lowerCamelCase		    =  False






  def   snake_case		(    self     ):







   """simple docstring"""
   super().setUp()

   lowerCamelCase_      =  ["__start__", "adapt", "act", "ap@@", "te", "__end__", "__unk__"]
   lowerCamelCase_      =  dict(zip(UpperCamelCase			,  range(len(UpperCamelCase     )     )     )     )

   lowerCamelCase_      =  ["#version: 0.2", "a p", "t e</w>", "ap t</w>", "a d", "ad apt</w>", "a c", "ac t</w>", ""]
   lowerCamelCase_      =  {"unk_token": "__unk__", "bos_token": "__start__", "eos_token": "__end__"}

   lowerCamelCase_      =  os.path.join(self.tmpdirname			,  VOCAB_FILES_NAMES["vocab_file"]     )
   lowerCamelCase_      =  os.path.join(self.tmpdirname			,  VOCAB_FILES_NAMES["merges_file"]     )
   with open(self.vocab_file			,  "w"			,  encoding="utf-8"     ) as fp:
    fp.write(json.dumps(UpperCamelCase     ) + "\n"     )
   with open(self.merges_file			,  "w"			,  encoding="utf-8"     ) as fp:
    fp.write("\n".join(UpperCamelCase     )     )






  def   snake_case		(    self			,  **UpperCamelCase     ):







   """simple docstring"""
   kwargs.update(self.special_tokens_map     )
   return BlenderbotSmallTokenizer.from_pretrained(self.tmpdirname			,  **UpperCamelCase     )






  def   snake_case		(    self			,  UpperCamelCase     ):







   """simple docstring"""
   lowerCamelCase_      =  "adapt act apte"
   lowerCamelCase_      =  "adapt act apte"
   return input_text, output_text






  def   snake_case		(    self     ):







   """simple docstring"""
   lowerCamelCase_      =  BlenderbotSmallTokenizer(self.vocab_file			,  self.merges_file			,  **self.special_tokens_map     )
   lowerCamelCase_      =  "adapt act apte"
   lowerCamelCase_      =  ["adapt", "act", "ap@@", "te"]
   lowerCamelCase_      =  tokenizer.tokenize(UpperCamelCase     )
   self.assertListEqual(UpperCamelCase			,  UpperCamelCase     )

   lowerCamelCase_      =  [tokenizer.bos_token] + tokens + [tokenizer.eos_token]

   lowerCamelCase_      =  [0, 1, 2, 3, 4, 5]
   self.assertListEqual(tokenizer.convert_tokens_to_ids(UpperCamelCase     )			,  UpperCamelCase     )






  def   snake_case		(    self     ):







   """simple docstring"""
   lowerCamelCase_      =  BlenderbotSmallTokenizer.from_pretrained("facebook/blenderbot-90M"     )
   assert tok("sam"     ).input_ids == [1384]
   lowerCamelCase_      =  "I am a small frog."
   lowerCamelCase_      =  tok([src_text]			,  padding=UpperCamelCase			,  truncation=UpperCamelCase     )["input_ids"]
   lowerCamelCase_      =  tok.batch_decode(UpperCamelCase			,  skip_special_tokens=UpperCamelCase			,  clean_up_tokenization_spaces=UpperCamelCase     )[0]
   assert src_text != decoded  # I wish it did!
   assert decoded == "i am a small frog ."







  def   snake_case		(    self     ):







   """simple docstring"""
   lowerCamelCase_      =  BlenderbotSmallTokenizer.from_pretrained("facebook/blenderbot-90M"     )
   lowerCamelCase_      =  "I am a small frog ."
   lowerCamelCase_      =  "."
   lowerCamelCase_      =  tok(UpperCamelCase     )["input_ids"]
   lowerCamelCase_      =  tok(UpperCamelCase     )["input_ids"]

   assert encoded[-1] == encoded_dot[0]



