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


_a														=		get_tests_dir("""fixtures""")
_a														=		get_tests_dir("""fixtures/dummy_feature_extractor_config.json""")
_a														=		get_tests_dir("""fixtures/dummy-config.json""")






class     _UpperCAmelCase(    unittest.TestCase	):



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






							'''simple docstring'''
							_UpperCamelCase							 =  0



		def 						UpperCAmelCase							(					self)       ->       Dict:






							'''simple docstring'''
							_UpperCamelCase							 =  AutoFeatureExtractor.from_pretrained('''facebook/wav2vec2-base-960h''')
							self.assertIsInstance(__a				,		__a)



		def 						UpperCAmelCase							(					self)       ->       Optional[Any]:






							'''simple docstring'''
							_UpperCamelCase							 =  AutoFeatureExtractor.from_pretrained(__a)
							self.assertIsInstance(__a				,		__a)



		def 						UpperCAmelCase							(					self)       ->       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(__a).to_dict()

												config_dict.pop('''feature_extractor_type''')
												_UpperCamelCase							 =  WavaVecaFeatureExtractor(**__a)

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

												_UpperCamelCase							 =  AutoFeatureExtractor.from_pretrained(__a)

												# 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(__a				,		__a)



		def 						UpperCAmelCase							(					self)       ->       Any:






							'''simple docstring'''
							_UpperCamelCase							 =  AutoFeatureExtractor.from_pretrained(__a)
							self.assertIsInstance(__a				,		__a)



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






							'''simple docstring'''
							with self.assertRaisesRegex(
							    __a				,		'''bert-base is not a local folder and is not a valid model identifier'''):
												_UpperCamelCase							 =  AutoFeatureExtractor.from_pretrained('''bert-base''')



		def 						UpperCAmelCase							(					self)       ->       str:






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



		def 						UpperCAmelCase							(					self)       ->       Any:






							'''simple docstring'''
							with self.assertRaisesRegex(
							    __a				,		'''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 						UpperCAmelCase							(					self)       ->       List[Any]:






							'''simple docstring'''
							# If remote code is not set, we will time out when asking whether to load the model.
							with self.assertRaises(__a):
												_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(__a):
												_UpperCamelCase							 =  AutoFeatureExtractor.from_pretrained(
												    '''hf-internal-testing/test_dynamic_feature_extractor'''				,		trust_remote_code=__a)

							_UpperCamelCase							 =  AutoFeatureExtractor.from_pretrained(
							    '''hf-internal-testing/test_dynamic_feature_extractor'''				,		trust_remote_code=__a)
							self.assertEqual(feature_extractor.__class__.__name__				,		'''NewFeatureExtractor''')

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



		def 						UpperCAmelCase							(					self)       ->       List[str]:






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

												# Now that the config is registered, it can be used as any other config with the auto-API
												_UpperCamelCase							 =  CustomFeatureExtractor.from_pretrained(__a)
												with tempfile.TemporaryDirectory() as tmp_dir:
																	feature_extractor.save_pretrained(__a)
																	_UpperCamelCase							 =  AutoFeatureExtractor.from_pretrained(__a)
																	self.assertIsInstance(__a				,		__a)

							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							(					self)       ->       Union[str, Any]:






							'''simple docstring'''






							class     _UpperCAmelCase(    lowerCamelCase	):
									lowercase__						=      True

							try:
												AutoConfig.register('''custom'''				,		__a)
												AutoFeatureExtractor.register(__a				,		__a)
												# 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=__a)
												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=__a)
												self.assertEqual(feature_extractor.__class__.__name__				,		'''NewFeatureExtractor''')
												self.assertTrue(not hasattr(__a				,		'''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 graphs.minimum_spanning_tree_kruskal import kruskal



def       lowerCamelCase__		(			)							->		List[Any]:


					"""simple docstring"""





					_UpperCamelCase							 =  9
					_UpperCamelCase							 =  [
					    [0, 1, 4],
					    [0, 7, 8],
					    [1, 2, 8],
					    [7, 8, 7],
					    [7, 6, 1],
					    [2, 8, 2],
					    [8, 6, 6],
					    [2, 3, 7],
					    [2, 5, 4],
					    [6, 5, 2],
					    [3, 5, 14],
					    [3, 4, 9],
					    [5, 4, 10],
					    [1, 7, 11],
					]

					_UpperCamelCase							 =  kruskal(__snake_case,     __snake_case	)

					_UpperCamelCase							 =  [
					    [7, 6, 1],
					    [2, 8, 2],
					    [6, 5, 2],
					    [0, 1, 4],
					    [2, 5, 4],
					    [2, 3, 7],
					    [0, 7, 8],
					    [3, 4, 9],
					]

					assert sorted(__snake_case	) == sorted(__snake_case	)






