


"""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_       :       int      						=  get_tests_dir("""fixtures""")
lowerCamelCase_       :       str      						=  get_tests_dir("""fixtures/dummy_feature_extractor_config.json""")
lowerCamelCase_       :       Optional[int]      						=  get_tests_dir("""fixtures/dummy-config.json""")






class 				__A    (	unittest.TestCase      ):






	"""simple docstring"""




	def 				SCREAMING_SNAKE_CASE							(		self						) ->					Optional[Any]:
					a					=0


	def 				SCREAMING_SNAKE_CASE							(		self						) ->					int:
					a					=AutoFeatureExtractor.from_pretrained('''facebook/wav2vec2-base-960h'''						)
					self.assertIsInstance(__A			,   __A						)


	def 				SCREAMING_SNAKE_CASE							(		self						) ->					Any:
					a					=AutoFeatureExtractor.from_pretrained(__A						)
					self.assertIsInstance(__A			,   __A						)


	def 				SCREAMING_SNAKE_CASE							(		self						) ->					int:
					with tempfile.TemporaryDirectory() as tmpdirname:
									a					=WavaVecaConfig()

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

									config_dict.pop('''feature_extractor_type'''						)
									a					=WavaVecaFeatureExtractor(**__A						)

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

									a					=AutoFeatureExtractor.from_pretrained(__A						)

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

					self.assertIsInstance(__A			,   __A						)


	def 				SCREAMING_SNAKE_CASE							(		self						) ->					Tuple:
					a					=AutoFeatureExtractor.from_pretrained(__A						)
					self.assertIsInstance(__A			,   __A						)


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


	def 				SCREAMING_SNAKE_CASE							(		self						) ->					Optional[int]:
					with self.assertRaisesRegex(
					    __A			,   r'''aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'''						):
									a					=AutoFeatureExtractor.from_pretrained(__A			,   revision='''aaaaaa'''						)


	def 				SCREAMING_SNAKE_CASE							(		self						) ->					Any:
					with self.assertRaisesRegex(
					    __A			,   '''hf-internal-testing/config-no-model does not appear to have a file named preprocessor_config.json.'''			,   ):
									a					=AutoFeatureExtractor.from_pretrained('''hf-internal-testing/config-no-model'''						)


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

					a					=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						)
									a					=AutoFeatureExtractor.from_pretrained(__A			,   trust_remote_code=__A						)
					self.assertEqual(reloaded_feature_extractor.__class__.__name__			,   '''NewFeatureExtractor'''						)


	def 				SCREAMING_SNAKE_CASE							(		self						) ->					Optional[int]:
					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
									a					=CustomFeatureExtractor.from_pretrained(__A						)
									with tempfile.TemporaryDirectory() as tmp_dir:
													feature_extractor.save_pretrained(__A						)
													a					=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 				SCREAMING_SNAKE_CASE							(		self						) ->					Union[str, Any]:






					class 				__A    (	A__      ):






						"""simple docstring"""




						__lowerCAmelCase			 =  True

					try:
									AutoConfig.register('''custom'''			,   __A						)
									AutoFeatureExtractor.register(__A			,   __A						)
									# If remote code is not set, the default is to use local
									a					=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					=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
									a					=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 __future__ import annotations
def _A						(						lowercase	,   lowercase	,   lowercase	,   ):







    """simple docstring"""
    if (electron_conc, hole_conc, intrinsic_conc).count(0		) != 1:
        raise ValueError('''You cannot supply more or less than 2 values'''		)
    elif electron_conc < 0:
        raise ValueError('''Electron concentration cannot be negative in a semiconductor'''		)
    elif hole_conc < 0:
        raise ValueError('''Hole concentration cannot be negative in a semiconductor'''		)
    elif intrinsic_conc < 0:
        raise ValueError(
            '''Intrinsic concentration cannot be negative in a semiconductor'''		)
    elif electron_conc == 0:
        return (
            "electron_conc",
            intrinsic_conc**2 / hole_conc,
        )
    elif hole_conc == 0:
        return (
            "hole_conc",
            intrinsic_conc**2 / electron_conc,
        )
    elif intrinsic_conc == 0:
        return (
            "intrinsic_conc",
            (electron_conc * hole_conc) ** 0.5,
        )
    else:
        return (-1, -1)


if __name__ == "__main__":
       import doctest

       doctest.testmod()