
'''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  A				(							unittest.TestCase						):





     def 				__lowerCAmelCase							(							self	) ->				Union[str, Any]:






         """simple docstring"""






         A       :   Optional[Any]					=						logging.get_logger()

         # the current default level is logging.WARNING
         A       :   Tuple					=						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 				__lowerCAmelCase							(							self	) ->				Optional[Any]:






         """simple docstring"""






         A       :   Any					=						logging.get_verbosity()

         A       :   str					=						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 				__lowerCAmelCase							(							self	) ->				Optional[int]:






         """simple docstring"""






         transformers.utils.logging._reset_library_root_logger()
         # this action activates the env var
         A       :   List[Any]					=						logging.get_logger('''transformers.models.bart.tokenization_bart'''	)

         A       :   str					=						os.getenv('''TRANSFORMERS_VERBOSITY'''						,			__SCREAMING_SNAKE_CASE	)
         A       :   Dict					=						logging.log_levels[env_level_str]

         A       :   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 				__lowerCAmelCase							(							self	) ->				Dict:






         """simple docstring"""






         transformers.utils.logging._reset_library_root_logger()
         A       :   Optional[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 				__lowerCAmelCase							(							self	) ->				Any:






         """simple docstring"""






         transformers.utils.logging._reset_library_root_logger()

         A       :   Optional[Any]					=						logging.get_logger('''transformers.models.bart.tokenization_bart'''	)
         A       :   List[str]					=						'''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_				(   ):




    '''simple docstring'''



    disable_progress_bar()
    assert are_progress_bars_disabled()

    enable_progress_bar()
    assert not are_progress_bars_disabled()







'''simple docstring'''



# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse

from ...utils.dataclasses import (
    ComputeEnvironment,
    DistributedType,
    DynamoBackend,
    PrecisionType,
    SageMakerDistributedType,
)
from ..menu import BulletMenu


UpperCAmelCase :       Any			   =     [
    'EAGER',
    'AOT_EAGER',
    'INDUCTOR',
    'NVFUSER',
    'AOT_NVFUSER',
    'AOT_CUDAGRAPHS',
    'OFI',
    'FX2TRT',
    'ONNXRT',
    'IPEX',
]







def    a__       (  a__      ,    a__=None      ,    a__=None      ,    a__=None						):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE     =      True
     while ask_again:
          __SCREAMING_SNAKE_CASE     =      input(a__						)
          try:
               if default is not None and len(a__						) == 0:
                    return default
               return convert_value(a__						) if convert_value is not None else result
          except Exception:
               if error_message is not None:
                    print(a__						)







def    a__       (  a__      ,    a__=[]      ,    a__=None      ,    a__=0						):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE     =      BulletMenu(a__      ,    a__						)
     __SCREAMING_SNAKE_CASE     =      menu.run(default_choice=a__						)
     return convert_value(a__						) if convert_value is not None else result







def    a__       (  a__						):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE     =      int(a__						)
     return ComputeEnvironment(["""LOCAL_MACHINE""", """AMAZON_SAGEMAKER"""][value]						)







def    a__       (  a__						):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE     =      int(a__						)
     return DistributedType(["""NO""", """MULTI_CPU""", """MULTI_XPU""", """MULTI_GPU""", """MULTI_NPU""", """TPU"""][value]						)







def    a__       (  a__						):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE     =      int(a__						)
     return DynamoBackend(DYNAMO_BACKENDS[value]						).value







def    a__       (  a__						):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE     =      int(a__						)
     return PrecisionType(["""no""", """fp16""", """bf16""", """fp8"""][value]						)







def    a__       (  a__						):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE     =      int(a__						)
     return SageMakerDistributedType(["""NO""", """DATA_PARALLEL""", """MODEL_PARALLEL"""][value]						)







def    a__       (  a__						):




     """simple docstring"""


     return {"yes": True, "no": False}[value.lower()]







class 						lowerCAmelCase__   (      argparse.RawDescriptionHelpFormatter					):



 """simple docstring"""



 def       UpperCAmelCase__		(		self					:       str					,							__SCREAMING_SNAKE_CASE					:       Optional[Any]					,							__SCREAMING_SNAKE_CASE					:       Dict					,							__SCREAMING_SNAKE_CASE					:       Optional[int]					,							__SCREAMING_SNAKE_CASE					:       List[Any]			)  -> Dict:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE     =      super()._format_usage(__SCREAMING_SNAKE_CASE					,							__SCREAMING_SNAKE_CASE					,							__SCREAMING_SNAKE_CASE					,							__SCREAMING_SNAKE_CASE			)
      __SCREAMING_SNAKE_CASE     =      usage.replace("""<command> [<args>] """					,							""""""			)
      return usage






