


"""simple docstring"""
import importlib
import json
import os
import sys
import tempfile
import unittest
from pathlib import Path

import transformers
import transformers.models.auto
from transformers.models.auto.configuration_auto import CONFIG_MAPPING, AutoConfig
from transformers.models.bert.configuration_bert import BertConfig
from transformers.models.roberta.configuration_roberta import RobertaConfig
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


__SCREAMING_SNAKE_CASE							:      Optional[int]						=      get_tests_dir('fixtures/dummy-config.json')





class        __A       (unittest.TestCase):





							'''simple docstring'''

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



														"""simple docstring"""



														snake_case_          =						0



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



														"""simple docstring"""



														self.assertIsNotNone(transformers.models.auto.__spec__    )
														self.assertIsNotNone(importlib.util.find_spec("""transformers.models.auto"""    )    )



							def 						lowerCAmelCase    (			self							: int    )   ->Any:



														"""simple docstring"""



														snake_case_          =						AutoConfig.from_pretrained("""bert-base-uncased"""    )
														self.assertIsInstance(lowerCamelCase_						,    lowerCamelCase_    )



							def 						lowerCAmelCase    (			self							: Tuple    )   ->Dict:



														"""simple docstring"""



														snake_case_          =						AutoConfig.from_pretrained(lowerCamelCase_    )
														self.assertIsInstance(lowerCamelCase_						,    lowerCamelCase_    )



							def 						lowerCAmelCase    (			self							: Any    )   ->Dict:



														"""simple docstring"""



														snake_case_          =						AutoConfig.from_pretrained(lowerCamelCase_    )
														self.assertIsInstance(lowerCamelCase_						,    lowerCamelCase_    )



							def 						lowerCAmelCase    (			self							: Tuple    )   ->Any:



														"""simple docstring"""



														snake_case_          =						AutoConfig.for_model("""roberta"""    )
														self.assertIsInstance(lowerCamelCase_						,    lowerCamelCase_    )



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



														"""simple docstring"""



														with tempfile.TemporaryDirectory() as tmp_dir:
																					# This model name contains bert and roberta, but roberta ends up being picked.
																					snake_case_          =						os.path.join(lowerCamelCase_						,    """fake-roberta"""    )
																					os.makedirs(lowerCamelCase_						,    exist_ok=lowerCamelCase_    )
																					with open(os.path.join(lowerCamelCase_						,    """config.json"""    )						,    """w"""    ) as f:
																												f.write(json.dumps({}    )    )
																					snake_case_          =						AutoConfig.from_pretrained(lowerCamelCase_    )
																					self.assertEqual(type(lowerCamelCase_    )						,    lowerCamelCase_    )



							def 						lowerCAmelCase    (			self							: int    )   ->Any:



														"""simple docstring"""



														try:
																					AutoConfig.register("""custom"""						,    lowerCamelCase_    )
																					# Wrong model type will raise an error
																					with self.assertRaises(lowerCamelCase_    ):
																												AutoConfig.register("""model"""						,    lowerCamelCase_    )
																					# Trying to register something existing in the Transformers library will raise an error
																					with self.assertRaises(lowerCamelCase_    ):
																												AutoConfig.register("""bert"""						,    lowerCamelCase_    )

																					# Now that the config is registered, it can be used as any other config with the auto-API
																					snake_case_          =						CustomConfig()
																					with tempfile.TemporaryDirectory() as tmp_dir:
																												config.save_pretrained(lowerCamelCase_    )
																												snake_case_          =						AutoConfig.from_pretrained(lowerCamelCase_    )
																												self.assertIsInstance(lowerCamelCase_						,    lowerCamelCase_    )

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



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



														"""simple docstring"""



														with self.assertRaisesRegex(
														    lowerCamelCase_						,    """bert-base is not a local folder and is not a valid model identifier"""    ):
																					snake_case_          =						AutoConfig.from_pretrained("""bert-base"""    )



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



														"""simple docstring"""



														with self.assertRaisesRegex(
														    lowerCamelCase_						,    R"""aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"""    ):
																					snake_case_          =						AutoConfig.from_pretrained(lowerCamelCase_						,    revision="""aaaaaa"""    )



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



														"""simple docstring"""



														with self.assertRaisesRegex(
														    lowerCamelCase_						,    """hf-internal-testing/no-config-test-repo does not appear to have a file named config.json."""						,    ):
																					snake_case_          =						AutoConfig.from_pretrained("""hf-internal-testing/no-config-test-repo"""    )



							def 						lowerCAmelCase    (			self							: Tuple    )   ->str:



														"""simple docstring"""



														with self.assertRaises(lowerCamelCase_    ):
																					snake_case_          =						AutoConfig.from_pretrained("""hf-internal-testing/test_dynamic_model"""    )
														# If remote code is disabled, we can't load this config.
														with self.assertRaises(lowerCamelCase_    ):
																					snake_case_          =						AutoConfig.from_pretrained("""hf-internal-testing/test_dynamic_model"""						,    trust_remote_code=lowerCamelCase_    )

														snake_case_          =						AutoConfig.from_pretrained("""hf-internal-testing/test_dynamic_model"""						,    trust_remote_code=lowerCamelCase_    )
														self.assertEqual(config.__class__.__name__						,    """NewModelConfig"""    )

														# Test config can be reloaded.
														with tempfile.TemporaryDirectory() as tmp_dir:
																					config.save_pretrained(lowerCamelCase_    )
																					snake_case_          =						AutoConfig.from_pretrained(lowerCamelCase_						,    trust_remote_code=lowerCamelCase_    )
														self.assertEqual(reloaded_config.__class__.__name__						,    """NewModelConfig"""    )



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



														"""simple docstring"""



														class        __A       (snake_case__):





																					'''simple docstring'''

																					__lowercase:						Tuple							 =      """new-model"""

														try:
																					AutoConfig.register("""new-model"""						,    lowerCamelCase_    )
																					# If remote code is not set, the default is to use local
																					snake_case_          =						AutoConfig.from_pretrained("""hf-internal-testing/test_dynamic_model"""    )
																					self.assertEqual(config.__class__.__name__						,    """NewModelConfigLocal"""    )

																					# If remote code is disabled, we load the local one.
																					snake_case_          =						AutoConfig.from_pretrained("""hf-internal-testing/test_dynamic_model"""						,    trust_remote_code=lowerCamelCase_    )
																					self.assertEqual(config.__class__.__name__						,    """NewModelConfigLocal"""    )

																					# If remote is enabled, we load from the Hub
																					snake_case_          =						AutoConfig.from_pretrained("""hf-internal-testing/test_dynamic_model"""						,    trust_remote_code=lowerCamelCase_    )
																					self.assertEqual(config.__class__.__name__						,    """NewModelConfig"""    )

														finally:
																					if "new-model" in CONFIG_MAPPING._extra_content:
																												del CONFIG_MAPPING._extra_content["new-model"]







"""simple docstring"""
def   _a			( _SCREAMING_SNAKE_CASE			)      ->			int:
							assert column_title.isupper()
							snake_case_          =						0
							snake_case_          =						len(_SCREAMING_SNAKE_CASE			) - 1
							snake_case_          =						0

							while index >= 0:
														snake_case_          =						(ord(column_title[index]			) - 64) * pow(26			,	_SCREAMING_SNAKE_CASE			)
														answer += value
														power += 1
														index -= 1

							return answer


if __name__ == "__main__":
				from doctest import testmod

				testmod()



