






'''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


lowerCamelCase_				: List[Any]    	=							get_tests_dir('''fixtures''')
lowerCamelCase_				: Optional[Any]    	=							get_tests_dir('''fixtures/dummy_feature_extractor_config.json''')
lowerCamelCase_				: Optional[Any]    	=							get_tests_dir('''fixtures/dummy-config.json''')
class    _SCREAMING_SNAKE_CASE							(		unittest.TestCase	):


			'''simple docstring'''





			def 				A      (   self							:						Optional[Any]			)							->    Optional[int]:

									'''simple docstring'''







									UpperCamelCase__         = 0






			def 				A      (   self							:						str			)							->    Optional[int]:

									'''simple docstring'''







									UpperCamelCase__         = AutoFeatureExtractor.from_pretrained("""facebook/wav2vec2-base-960h"""			)
									self.assertIsInstance(lowercase ,      lowercase			)






			def 				A      (   self							:						int			)							->    Tuple:

									'''simple docstring'''







									UpperCamelCase__         = AutoFeatureExtractor.from_pretrained(lowercase			)
									self.assertIsInstance(lowercase ,      lowercase			)






			def 				A      (   self							:						str			)							->    Tuple:

									'''simple docstring'''







									with tempfile.TemporaryDirectory() as tmpdirname:
															UpperCamelCase__         = WavaVecaConfig()

															# remove feature_extractor_type to make sure config.json alone is enough to load feature processor locally
															UpperCamelCase__         = AutoFeatureExtractor.from_pretrained(lowercase			).to_dict()

															config_dict.pop("""feature_extractor_type"""			)
															UpperCamelCase__         = WavaVecaFeatureExtractor(**lowercase			)

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

															UpperCamelCase__         = AutoFeatureExtractor.from_pretrained(lowercase			)

															# make sure private variable is not incorrectly saved
															UpperCamelCase__         = json.loads(config.to_json_string()			)
															self.assertTrue("""_processor_class""" not in dict_as_saved			)

									self.assertIsInstance(lowercase ,      lowercase			)






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

									'''simple docstring'''







									UpperCamelCase__         = AutoFeatureExtractor.from_pretrained(lowercase			)
									self.assertIsInstance(lowercase ,      lowercase			)






			def 				A      (   self							:						str			)							->    int:

									'''simple docstring'''







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






			def 				A      (   self							:						Optional[int]			)							->    Optional[int]:

									'''simple docstring'''







									with self.assertRaisesRegex(
									    lowercase ,      r"""aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"""			):
															UpperCamelCase__         = AutoFeatureExtractor.from_pretrained(lowercase ,      revision="""aaaaaa"""			)






			def 				A      (   self							:						Optional[Any]			)							->    str:

									'''simple docstring'''







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






			def 				A      (   self							:						Tuple			)							->    Tuple:

									'''simple docstring'''







									with self.assertRaises(lowercase			):
															UpperCamelCase__         = 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			):
															UpperCamelCase__         = AutoFeatureExtractor.from_pretrained(
															    """hf-internal-testing/test_dynamic_feature_extractor""" ,      trust_remote_code=lowercase			)

									UpperCamelCase__         = 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			)
															UpperCamelCase__         = AutoFeatureExtractor.from_pretrained(lowercase ,      trust_remote_code=lowercase			)
									self.assertEqual(reloaded_feature_extractor.__class__.__name__ ,      """NewFeatureExtractor"""			)






			def 				A      (   self							:						int			)							->    List[Any]:

									'''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
															UpperCamelCase__         = CustomFeatureExtractor.from_pretrained(lowercase			)
															with tempfile.TemporaryDirectory() as tmp_dir:
																					feature_extractor.save_pretrained(lowercase			)
																					UpperCamelCase__         = 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 				A      (   self							:						Any			)							->    Optional[int]:

									'''simple docstring'''







									class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


												'''simple docstring'''





												__a							:							List[str]					     =					True

									try:
															AutoConfig.register("""custom""" ,      lowercase			)
															AutoFeatureExtractor.register(lowercase ,      lowercase			)
															# If remote code is not set, the default is to use local
															UpperCamelCase__         = 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.
															UpperCamelCase__         = 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
															UpperCamelCase__         = 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'''


import math







def 	__magic_name__( _A					):
						'''simple docstring'''





						assert isinstance(_A						,      _A					) and (
						    number >= 0
						), "'number' must been an int and positive"

						if 1 < number < 4:
												# 2 and 3 are primes
												return True
						elif number < 2 or not number % 2:
												# Negatives, 0, 1 and all even numbers are not primes
												return False

						UpperCamelCase__         = range(3						,      int(math.sqrt(_A					) + 1					)						,      2					)
						return not any(not number % i for i in odd_numbers					)







def 	__magic_name__( _A						,      _A=1						,      **_A					):
						'''simple docstring'''





						UpperCamelCase__         = factor * value
						UpperCamelCase__         = value

						while not is_prime(_A					):
												value += 1 if not ("desc" in kwargs and kwargs["desc"] is True) else -1

						if value == first_value_val:
												return next_prime(value + 1						,      **_A					)
						return value
