


'''simple docstring'''







import os
import unittest

from huggingface_hub.utils import are_progress_bars_disabled

import transformers.models.bart.tokenization_bart
from transformers import logging
from transformers.testing_utils import CaptureLogger, mockenv, mockenv_context
from transformers.utils.logging import disable_progress_bar, enable_progress_bar


class 			__lowerCamelCase			(	unittest.TestCase	):
    """simple docstring"""


    def        A   (  self      :							Any):
           _A					:     int     = logging.get_logger()

           # the current default level is logging.WARNING
           _A					:     List[str]     = logging.get_verbosity()

           logging.set_verbosity_error()
           self.assertEqual(logger.getEffectiveLevel()				,							logging.get_verbosity())

           logging.set_verbosity_warning()
           self.assertEqual(logger.getEffectiveLevel()				,							logging.get_verbosity())

           logging.set_verbosity_info()
           self.assertEqual(logger.getEffectiveLevel()				,							logging.get_verbosity())

           logging.set_verbosity_debug()
           self.assertEqual(logger.getEffectiveLevel()				,							logging.get_verbosity())

           # restore to the original level
           logging.set_verbosity(SCREAMING_SNAKE_CASE)


    def        A   (  self      :							Union[str, Any]):
           _A					:     List[str]     = logging.get_verbosity()

           _A					:     Optional[Any]     = logging.get_logger('transformers.models.bart.tokenization_bart')
           _A					:     List[Any]     = 'Testing 1, 2, 3'

           # should be able to log warnings (if default settings weren't overridden by `pytest --log-level-all`)
           if level_origin <= logging.WARNING:
                  with CaptureLogger(SCREAMING_SNAKE_CASE) as cl:
                         logger.warning(SCREAMING_SNAKE_CASE)
                  self.assertEqual(cl.out				,							msg + '\n')

           # this is setting the level for all of `transformers.*` loggers
           logging.set_verbosity_error()

           # should not be able to log warnings
           with CaptureLogger(SCREAMING_SNAKE_CASE) as cl:
                  logger.warning(SCREAMING_SNAKE_CASE)
           self.assertEqual(cl.out				,							'')

           # should be able to log warnings again
           logging.set_verbosity_warning()
           with CaptureLogger(SCREAMING_SNAKE_CASE) as cl:
                  logger.warning(SCREAMING_SNAKE_CASE)
           self.assertEqual(cl.out				,							msg + '\n')

           # restore to the original level
           logging.set_verbosity(SCREAMING_SNAKE_CASE)


    @mockenv(TRANSFORMERS_VERBOSITY='error')
    def        A   (  self      :							Tuple):
           # reset for the env var to take effect, next time some logger call is made
           transformers.utils.logging._reset_library_root_logger()
           # this action activates the env var
           _A					:     Dict     = logging.get_logger('transformers.models.bart.tokenization_bart')

           _A					:     str     = os.getenv('TRANSFORMERS_VERBOSITY'				,							SCREAMING_SNAKE_CASE)
           _A					:     Optional[int]     = logging.log_levels[env_level_str]

           _A					:     Optional[int]     = logging.get_verbosity()
           self.assertEqual(
               SCREAMING_SNAKE_CASE				,							SCREAMING_SNAKE_CASE				,							F'TRANSFORMERS_VERBOSITY={env_level_str}/{env_level}, but internal verbosity is {current_level}'				,							)

           # restore to the original level
           _A					:     List[Any]     = ''
           transformers.utils.logging._reset_library_root_logger()


    @mockenv(TRANSFORMERS_VERBOSITY='super-error')
    def        A   (  self      :							List[Any]):
           # reset for the env var to take effect, next time some logger call is made
           transformers.utils.logging._reset_library_root_logger()
           _A					:     int     = logging.logging.getLogger()
           with CaptureLogger(SCREAMING_SNAKE_CASE) as cl:
                  # this action activates the env var
                  logging.get_logger('transformers.models.bart.tokenization_bart')
           self.assertIn('Unknown option TRANSFORMERS_VERBOSITY=super-error'				,							cl.out)

           # no need to restore as nothing was changed


    def        A   (  self      :							Optional[int]):
           # testing `logger.warning_advice()`
           transformers.utils.logging._reset_library_root_logger()

           _A					:     Tuple     = logging.get_logger('transformers.models.bart.tokenization_bart')
           _A					:     Optional[Any]     = 'Testing 1, 2, 3'

           with mockenv_context(TRANSFORMERS_NO_ADVISORY_WARNINGS='1'):
                  # nothing should be logged as env var disables this method
                  with CaptureLogger(SCREAMING_SNAKE_CASE) as cl:
                         logger.warning_advice(SCREAMING_SNAKE_CASE)
                  self.assertEqual(cl.out				,							'')

           with mockenv_context(TRANSFORMERS_NO_ADVISORY_WARNINGS=''):
                  # should log normally as TRANSFORMERS_NO_ADVISORY_WARNINGS is unset
                  with CaptureLogger(SCREAMING_SNAKE_CASE) as cl:
                         logger.warning_advice(SCREAMING_SNAKE_CASE)
                  self.assertEqual(cl.out				,							msg + '\n')






def 				lowerCAmelCase__	(    ):
       disable_progress_bar()
       assert are_progress_bars_disabled()

       enable_progress_bar()
       assert not are_progress_bars_disabled()










'''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 				lowerCAmelCase__	(    lowerCamelCase					:      Optional[int]  ,lowerCamelCase					:      List[Any]  ,lowerCamelCase					:      Tuple  ,lowerCamelCase					:      List[str]       ):
       _A					:     Dict     = multiprocessing.Manager()
       _A					:     List[Any]     = manager.list()

       _A					:     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 				lowerCAmelCase__	(    lowerCamelCase					:      Optional[int]  ,lowerCamelCase					:      Union[str, Any]  ,lowerCamelCase					:      Optional[Any]       ):
       with create_tempdir():
              # These system calls are needed when cleaning up tempdir.
              import os
              import shutil

              _A					:     Any     = shutil.rmtree
              _A					:     Optional[int]     = os.rmdir
              _A					:     str     = os.chdir

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

              # Run program.
              try:
                     _A					:     str     = {}
                     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.
              _A					:     Optional[int]     = rmtree
              _A					:     Optional[Any]     = rmdir
              _A					:     Dict     = chdir






@contextlib.contextmanager
def 				lowerCAmelCase__	(    lowerCamelCase					:      int       ):
       def signal_handler(lowerCamelCase					:      str  ,lowerCamelCase					:      Any       ):
              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 				lowerCAmelCase__	(    ):
       _A					:     Any     = WriteOnlyStringIO()
       with contextlib.redirect_stdout(lowerCamelCase       ):
              with contextlib.redirect_stderr(lowerCamelCase       ):
                     with redirect_stdin(lowerCamelCase       ):
                            yield






@contextlib.contextmanager
def 				lowerCAmelCase__	(    ):
       with tempfile.TemporaryDirectory() as dirname:
              with chdir(lowerCamelCase       ):
                     yield dirname


class 			__lowerCamelCase			(	a_	):
    """simple docstring"""
    pass




class 			__lowerCamelCase			(	io.StringIO	):
    """simple docstring"""


    def        A   (  self      :							Tuple				,							*SCREAMING_SNAKE_CASE      :							Any				,							**SCREAMING_SNAKE_CASE      :							Dict):
           raise OSError


    def        A   (  self      :							Optional[int]				,							*SCREAMING_SNAKE_CASE      :							List[str]				,							**SCREAMING_SNAKE_CASE      :							Optional[Any]):
           raise OSError


    def        A   (  self      :							Optional[int]				,							*SCREAMING_SNAKE_CASE      :							str				,							**SCREAMING_SNAKE_CASE      :							Optional[int]):
           raise OSError


    def        A   (  self      :							Union[str, Any]				,							*SCREAMING_SNAKE_CASE      :							Optional[int]				,							**SCREAMING_SNAKE_CASE      :							Tuple):
           return False




class 			__lowerCamelCase			(	contextlib._RedirectStream	):  # type: ignore
    """simple docstring"""
    a													=   "stdin"






@contextlib.contextmanager
def 				lowerCAmelCase__	(    lowerCamelCase					:      Tuple       ):
       if root == ".":
              yield
              return
       _A					:     Any     = os.getcwd()
       os.chdir(lowerCamelCase       )
       try:
              yield
       except BaseException as exc:
              raise exc
       finally:
              os.chdir(lowerCamelCase       )






def 				lowerCAmelCase__	(    lowerCamelCase					:      List[Any]=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

       _A					:     List[Any]     = None
       _A					:     Dict     = None

       import os

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

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

       import shutil

       _A					:     int     = None
       _A					:     Any     = None
       _A					:     List[Any]     = None

       import subprocess

       _A					:     Optional[Any]     = None  # type: ignore

       _A					:     List[Any]     = None

       import sys

       _A					:     Any     = None
       _A					:     Tuple     = None
       _A					:     str     = None
       _A					:     Tuple     = None
       _A					:     List[str]     = None






