


import json
import sys
import tempfile
import unittest
from pathlib import Path

import transformers
from transformers import (
    CONFIG_MAPPING,
    FEATURE_EXTRACTOR_MAPPING,
    AutoConfig,
    AutoFeatureExtractor,
    WavaVecaConfig,
    WavaVecaFeatureExtractor,
)
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, get_tests_dir


sys.path.append(str(Path(__file__).parent.parent.parent.parent / 'utils'))

from test_module.custom_configuration import CustomConfig  # noqa E402
from test_module.custom_feature_extraction import CustomFeatureExtractor  # noqa E402


__UpperCamelCase    :						Tuple     =							get_tests_dir('fixtures')
__UpperCamelCase    :						Optional[int]     =							get_tests_dir('fixtures/dummy_feature_extractor_config.json')
__UpperCamelCase    :						str     =							get_tests_dir('fixtures/dummy-config.json')



class 							_UpperCamelCase (						unittest.TestCase						):

   '''simple docstring'''







   def   _snake_case    (  self  : Dict							):






         '''simple docstring'''



         __lowerCamelCase     :      Dict       						=						0

   def   _snake_case    (  self  : Optional[Any]							):






         '''simple docstring'''



         __lowerCamelCase     :      Optional[Any]       						=						AutoFeatureExtractor.from_pretrained("""facebook/wav2vec2-base-960h"""							)
         self.assertIsInstance(_lowerCamelCase       ,  _lowerCamelCase							)

   def   _snake_case    (  self  : str							):






         '''simple docstring'''



         __lowerCamelCase     :      Optional[Any]       						=						AutoFeatureExtractor.from_pretrained(_lowerCamelCase							)
         self.assertIsInstance(_lowerCamelCase       ,  _lowerCamelCase							)

   def   _snake_case    (  self  : Tuple							):






         '''simple docstring'''



         with tempfile.TemporaryDirectory() as tmpdirname:
               __lowerCamelCase     :      str       						=						WavaVecaConfig()

               # remove feature_extractor_type to make sure config.json alone is enough to load feature processor locally
               __lowerCamelCase     :      Dict       						=						AutoFeatureExtractor.from_pretrained(_lowerCamelCase							).to_dict()

               config_dict.pop("""feature_extractor_type"""							)
               __lowerCamelCase     :      List[Any]       						=						WavaVecaFeatureExtractor(**_lowerCamelCase							)

               # save in new folder
               model_config.save_pretrained(_lowerCamelCase							)
               config.save_pretrained(_lowerCamelCase							)

               __lowerCamelCase     :      int       						=						AutoFeatureExtractor.from_pretrained(_lowerCamelCase							)

               # make sure private variable is not incorrectly saved
               __lowerCamelCase     :      List[Any]       						=						json.loads(config.to_json_string()							)
               self.assertTrue("""_processor_class""" not in dict_as_saved							)

         self.assertIsInstance(_lowerCamelCase       ,  _lowerCamelCase							)

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






         '''simple docstring'''



         __lowerCamelCase     :      List[Any]       						=						AutoFeatureExtractor.from_pretrained(_lowerCamelCase							)
         self.assertIsInstance(_lowerCamelCase       ,  _lowerCamelCase							)

   def   _snake_case    (  self  : List[Any]							):






         '''simple docstring'''



         with self.assertRaisesRegex(
             _lowerCamelCase       ,  """bert-base is not a local folder and is not a valid model identifier"""							):
               __lowerCamelCase     :      int       						=						AutoFeatureExtractor.from_pretrained("""bert-base"""							)

   def   _snake_case    (  self  : int							):






         '''simple docstring'''



         with self.assertRaisesRegex(
             _lowerCamelCase       ,  R"""aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"""							):
               __lowerCamelCase     :      Tuple       						=						AutoFeatureExtractor.from_pretrained(_lowerCamelCase       ,  revision="""aaaaaa"""							)

   def   _snake_case    (  self  : Optional[int]							):






         '''simple docstring'''



         with self.assertRaisesRegex(
             _lowerCamelCase       ,  """hf-internal-testing/config-no-model does not appear to have a file named preprocessor_config.json."""       ,  ):
               __lowerCamelCase     :      Tuple       						=						AutoFeatureExtractor.from_pretrained("""hf-internal-testing/config-no-model"""							)

   def   _snake_case    (  self  : Optional[int]							):






         '''simple docstring'''



         with self.assertRaises(_lowerCamelCase							):
               __lowerCamelCase     :      List[Any]       						=						AutoFeatureExtractor.from_pretrained(
                   """hf-internal-testing/test_dynamic_feature_extractor"""							)
         # If remote code is disabled, we can't load this config.
         with self.assertRaises(_lowerCamelCase							):
               __lowerCamelCase     :      str       						=						AutoFeatureExtractor.from_pretrained(
                   """hf-internal-testing/test_dynamic_feature_extractor"""       ,  trust_remote_code=_lowerCamelCase							)

         __lowerCamelCase     :      Any       						=						AutoFeatureExtractor.from_pretrained(
             """hf-internal-testing/test_dynamic_feature_extractor"""       ,  trust_remote_code=_lowerCamelCase							)
         self.assertEqual(feature_extractor.__class__.__name__       ,  """NewFeatureExtractor"""							)

         # Test feature extractor can be reloaded.
         with tempfile.TemporaryDirectory() as tmp_dir:
               feature_extractor.save_pretrained(_lowerCamelCase							)
               __lowerCamelCase     :      Tuple       						=						AutoFeatureExtractor.from_pretrained(_lowerCamelCase       ,  trust_remote_code=_lowerCamelCase							)
         self.assertEqual(reloaded_feature_extractor.__class__.__name__       ,  """NewFeatureExtractor"""							)

   def   _snake_case    (  self  : str							):






         '''simple docstring'''



         try:
               AutoConfig.register("""custom"""       ,  _lowerCamelCase							)
               AutoFeatureExtractor.register(_lowerCamelCase       ,  _lowerCamelCase							)
               # Trying to register something existing in the Transformers library will raise an error
               with self.assertRaises(_lowerCamelCase							):
                     AutoFeatureExtractor.register(_lowerCamelCase       ,  _lowerCamelCase							)

               # Now that the config is registered, it can be used as any other config with the auto-API
               __lowerCamelCase     :      Union[str, Any]       						=						CustomFeatureExtractor.from_pretrained(_lowerCamelCase							)
               with tempfile.TemporaryDirectory() as tmp_dir:
                     feature_extractor.save_pretrained(_lowerCamelCase							)
                     __lowerCamelCase     :      str       						=						AutoFeatureExtractor.from_pretrained(_lowerCamelCase							)
                     self.assertIsInstance(_lowerCamelCase       ,  _lowerCamelCase							)

         finally:
               if "custom" in CONFIG_MAPPING._extra_content:
                     del CONFIG_MAPPING._extra_content["custom"]
               if CustomConfig in FEATURE_EXTRACTOR_MAPPING._extra_content:
                     del FEATURE_EXTRACTOR_MAPPING._extra_content[CustomConfig]


   def   _snake_case    (  self  : Any							):






         '''simple docstring'''



         class 							_UpperCamelCase (						A						):

            '''simple docstring'''







            a_				:							Dict    = True

         try:
               AutoConfig.register("""custom"""       ,  _lowerCamelCase							)
               AutoFeatureExtractor.register(_lowerCamelCase       ,  _lowerCamelCase							)
               # If remote code is not set, the default is to use local
               __lowerCamelCase     :      Optional[int]       						=						AutoFeatureExtractor.from_pretrained(
                   """hf-internal-testing/test_dynamic_feature_extractor"""							)
               self.assertEqual(feature_extractor.__class__.__name__       ,  """NewFeatureExtractor"""							)
               self.assertTrue(feature_extractor.is_local							)

               # If remote code is disabled, we load the local one.
               __lowerCamelCase     :      List[Any]       						=						AutoFeatureExtractor.from_pretrained(
                   """hf-internal-testing/test_dynamic_feature_extractor"""       ,  trust_remote_code=_lowerCamelCase							)
               self.assertEqual(feature_extractor.__class__.__name__       ,  """NewFeatureExtractor"""							)
               self.assertTrue(feature_extractor.is_local							)

               # If remote is enabled, we load from the Hub
               __lowerCamelCase     :      Tuple       						=						AutoFeatureExtractor.from_pretrained(
                   """hf-internal-testing/test_dynamic_feature_extractor"""       ,  trust_remote_code=_lowerCamelCase							)
               self.assertEqual(feature_extractor.__class__.__name__       ,  """NewFeatureExtractor"""							)
               self.assertTrue(not hasattr(_lowerCamelCase       ,  """is_local"""							)							)

         finally:
               if "custom" in CONFIG_MAPPING._extra_content:
                     del CONFIG_MAPPING._extra_content["custom"]
               if CustomConfig in FEATURE_EXTRACTOR_MAPPING._extra_content:
                     del FEATURE_EXTRACTOR_MAPPING._extra_content[CustomConfig]







def   _UpperCAmelCase       (     UpperCAmelCase      :			int = 4_000_000      ):
      """simple docstring"""




      __lowerCamelCase     :      Union[str, Any]       						=						[0, 1]
      __lowerCamelCase     :      Dict       						=						0
      while fib[i] <= n:
            fib.append(fib[i] + fib[i + 1]      )
            if fib[i + 2] > n:
                  break
            i += 1
      __lowerCamelCase     :      Any       						=						0
      for j in range(len(UpperCAmelCase      ) - 1      ):
            if fib[j] % 2 == 0:
                  total += fib[j]

      return total


if __name__ == "__main__":
    print(F'''{solution() = }''')



