


'''simple docstring'''
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_			:  str										=   get_tests_dir('fixtures')
UpperCAmelCase_			:  Tuple										=   get_tests_dir('fixtures/dummy_feature_extractor_config.json')
UpperCAmelCase_			:  Tuple										=   get_tests_dir('fixtures/dummy-config.json')

class     _lowerCamelCase       (     unittest.TestCase					):




 '''simple docstring'''


 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		Optional[int]	  =      0


 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		Union[str, Any]	  =      AutoFeatureExtractor.from_pretrained('facebook/wav2vec2-base-960h'    )
  self.assertIsInstance(__lowercase   ,   __lowercase    )


 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		Tuple	  =      AutoFeatureExtractor.from_pretrained(__lowercase    )
  self.assertIsInstance(__lowercase   ,   __lowercase    )


 def 			snake_case__ (   self    ):

  """simple docstring"""







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

   # remove feature_extractor_type to make sure config.json alone is enough to load feature processor locally
   __A	:		Tuple	  =      AutoFeatureExtractor.from_pretrained(__lowercase    ).to_dict()

   config_dict.pop('feature_extractor_type'    )
   __A	:		List[Any]	  =      WavaVecaFeatureExtractor(**__lowercase    )

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

   __A	:		List[Any]	  =      AutoFeatureExtractor.from_pretrained(__lowercase    )

   # make sure private variable is not incorrectly saved
   __A	:		str	  =      json.loads(config.to_json_string()    )
   self.assertTrue('_processor_class' not in dict_as_saved    )

  self.assertIsInstance(__lowercase   ,   __lowercase    )


 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		List[Any]	  =      AutoFeatureExtractor.from_pretrained(__lowercase    )
  self.assertIsInstance(__lowercase   ,   __lowercase    )


 def 			snake_case__ (   self    ):

  """simple docstring"""







  with self.assertRaisesRegex(
      __lowercase   ,   'bert-base is not a local folder and is not a valid model identifier'    ):
   __A	:		Tuple	  =      AutoFeatureExtractor.from_pretrained('bert-base'    )


 def 			snake_case__ (   self    ):

  """simple docstring"""







  with self.assertRaisesRegex(
      __lowercase   ,   R'aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'    ):
   __A	:		Dict	  =      AutoFeatureExtractor.from_pretrained(__lowercase   ,   revision='aaaaaa'    )


 def 			snake_case__ (   self    ):

  """simple docstring"""







  with self.assertRaisesRegex(
      __lowercase   ,   'hf-internal-testing/config-no-model does not appear to have a file named preprocessor_config.json.'   ,   ):
   __A	:		Optional[int]	  =      AutoFeatureExtractor.from_pretrained('hf-internal-testing/config-no-model'    )


 def 			snake_case__ (   self    ):

  """simple docstring"""







  with self.assertRaises(__lowercase    ):
   __A	:		Optional[int]	  =      AutoFeatureExtractor.from_pretrained(
       'hf-internal-testing/test_dynamic_feature_extractor'    )
  # If remote code is disabled, we can't load this config.
  with self.assertRaises(__lowercase    ):
   __A	:		Dict	  =      AutoFeatureExtractor.from_pretrained(
       'hf-internal-testing/test_dynamic_feature_extractor'   ,   trust_remote_code=__lowercase    )

  __A	:		str	  =      AutoFeatureExtractor.from_pretrained(
      'hf-internal-testing/test_dynamic_feature_extractor'   ,   trust_remote_code=__lowercase    )
  self.assertEqual(feature_extractor.__class__.__name__   ,   'NewFeatureExtractor'    )

  # Test feature extractor can be reloaded.
  with tempfile.TemporaryDirectory() as tmp_dir:
   feature_extractor.save_pretrained(__lowercase    )
   __A	:		List[Any]	  =      AutoFeatureExtractor.from_pretrained(__lowercase   ,   trust_remote_code=__lowercase    )
  self.assertEqual(reloaded_feature_extractor.__class__.__name__   ,   'NewFeatureExtractor'    )


 def 			snake_case__ (   self    ):

  """simple docstring"""







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

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

  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    ):

  """simple docstring"""







  class     _lowerCamelCase       (     snake_case_					):




   '''simple docstring'''
   __lowercase					:		Any     				=    True

  try:
   AutoConfig.register('custom'   ,   __lowercase    )
   AutoFeatureExtractor.register(__lowercase   ,   __lowercase    )
   # If remote code is not set, the default is to use local
   __A	:		List[Any]	  =      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.
   __A	:		int	  =      AutoFeatureExtractor.from_pretrained(
       'hf-internal-testing/test_dynamic_feature_extractor'   ,   trust_remote_code=__lowercase    )
   self.assertEqual(feature_extractor.__class__.__name__   ,   'NewFeatureExtractor'    )
   self.assertTrue(feature_extractor.is_local    )

   # If remote is enabled, we load from the Hub
   __A	:		List[Any]	  =      AutoFeatureExtractor.from_pretrained(
       'hf-internal-testing/test_dynamic_feature_extractor'   ,   trust_remote_code=__lowercase    )
   self.assertEqual(feature_extractor.__class__.__name__   ,   'NewFeatureExtractor'    )
   self.assertTrue(not hasattr(__lowercase   ,   '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]










'''simple docstring'''
from math import factorial

UpperCAmelCase_			:  List[str]										=   {str(d): factorial(d) for d in range(1_0)}


def       _lowercase							(					UpperCamelCase__							:       int      ):
 return sum(DIGIT_FACTORIAL[d] for d in str(UpperCamelCase__      )      )


def       _lowercase							(					):
 __A	:		Union[str, Any]	  =      7 * factorial(9      ) + 1
 return sum(i for i in range(3,					UpperCamelCase__      ) if sum_of_digit_factorial(UpperCamelCase__      ) == i      )


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






