


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


__snake_case   							=						get_tests_dir('''fixtures/dummy-config.json''')



class 	__lowerCamelCase			(unittest.TestCase						):







       def 		snake_case_	(			self: Any					):






            '''simple docstring'''




            __UpperCamelCase =			0







       def 		snake_case_	(			self: str					):






            '''simple docstring'''




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







       def 		snake_case_	(			self: List[Any]					):






            '''simple docstring'''




            __UpperCamelCase =			AutoConfig.from_pretrained('bert-base-uncased'					)
            self.assertIsInstance(A_,A_					)







       def 		snake_case_	(			self: Any					):






            '''simple docstring'''




            __UpperCamelCase =			AutoConfig.from_pretrained(A_					)
            self.assertIsInstance(A_,A_					)







       def 		snake_case_	(			self: Any					):






            '''simple docstring'''




            __UpperCamelCase =			AutoConfig.from_pretrained(A_					)
            self.assertIsInstance(A_,A_					)







       def 		snake_case_	(			self: Optional[int]					):






            '''simple docstring'''




            __UpperCamelCase =			AutoConfig.for_model('roberta'					)
            self.assertIsInstance(A_,A_					)







       def 		snake_case_	(			self: Union[str, Any]					):






            '''simple docstring'''




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







       def 		snake_case_	(			self: List[str]					):






            '''simple docstring'''




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

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

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







       def 		snake_case_	(			self: Dict					):






            '''simple docstring'''




            with self.assertRaisesRegex(
                A_,'bert-base is not a local folder and is not a valid model identifier'					):
                 __UpperCamelCase =			AutoConfig.from_pretrained('bert-base'					)







       def 		snake_case_	(			self: Dict					):






            '''simple docstring'''




            with self.assertRaisesRegex(
                A_,r'aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'					):
                 __UpperCamelCase =			AutoConfig.from_pretrained(A_,revision='aaaaaa'					)







       def 		snake_case_	(			self: Dict					):






            '''simple docstring'''




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







       def 		snake_case_	(			self: List[str]					):






            '''simple docstring'''




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

            __UpperCamelCase =			AutoConfig.from_pretrained('hf-internal-testing/test_dynamic_model',trust_remote_code=A_					)
            self.assertEqual(config.__class__.__name__,'NewModelConfig'					)

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







       def 		snake_case_	(			self: str					):






            '''simple docstring'''




            class 	__lowerCamelCase			(_a						):
                   _lowercase											=     """new-model"""

            try:
                 AutoConfig.register('new-model',A_					)
                 # If remote code is not set, the default is to use local
                 __UpperCamelCase =			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.
                 __UpperCamelCase =			AutoConfig.from_pretrained('hf-internal-testing/test_dynamic_model',trust_remote_code=A_					)
                 self.assertEqual(config.__class__.__name__,'NewModelConfigLocal'					)

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

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






def 		_A		(		_lowercase )					-> int:


     """simple docstring"""


     assert column_title.isupper()
     __UpperCamelCase =			0
     __UpperCamelCase =			len(_lowercase ) - 1
     __UpperCamelCase =			0

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

     return answer


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

    testmod()


