





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


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




class 			_a						(				unittest.TestCase    ):






				def     snake_case     (			self		:   Tuple							)     ->				str:




										'''simple docstring'''



										_UpperCamelCase      : Dict         =   0






				def     snake_case     (			self		:   Dict							)     ->				List[str]:




										'''simple docstring'''



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






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




										'''simple docstring'''



										_UpperCamelCase      : Optional[Any]         =   AutoConfig.from_pretrained('''bert-base-uncased'''							)
										self.assertIsInstance(__a,			__a							)






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




										'''simple docstring'''



										_UpperCamelCase      : str         =   AutoConfig.from_pretrained(__a							)
										self.assertIsInstance(__a,			__a							)






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




										'''simple docstring'''



										_UpperCamelCase      : Optional[Any]         =   AutoConfig.from_pretrained(__a							)
										self.assertIsInstance(__a,			__a							)






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




										'''simple docstring'''



										_UpperCamelCase      : List[str]         =   AutoConfig.for_model('''roberta'''							)
										self.assertIsInstance(__a,			__a							)






				def     snake_case     (			self		:   List[Any]							)     ->				Dict:




										'''simple docstring'''



										with tempfile.TemporaryDirectory() as tmp_dir:
																# This model name contains bert and roberta, but roberta ends up being picked.
																_UpperCamelCase      : Tuple         =   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      : List[str]         =   AutoConfig.from_pretrained(__a							)
																self.assertEqual(type(__a							),			__a							)






				def     snake_case     (			self		:   List[str]							)     ->				Tuple:




										'''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      : Any         =   CustomConfig()
																with tempfile.TemporaryDirectory() as tmp_dir:
																						config.save_pretrained(__a							)
																						_UpperCamelCase      : Any         =   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		:   Union[str, Any]							)     ->				List[Any]:




										'''simple docstring'''



										with self.assertRaisesRegex(
										    __a,			'''bert-base is not a local folder and is not a valid model identifier'''							):
																_UpperCamelCase      : List[Any]         =   AutoConfig.from_pretrained('''bert-base'''							)






				def     snake_case     (			self		:   List[Any]							)     ->				List[Any]:




										'''simple docstring'''



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






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




										'''simple docstring'''



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






				def     snake_case     (			self		:   int							)     ->				int:




										'''simple docstring'''



										with self.assertRaises(__a							):
																_UpperCamelCase      : Optional[Any]         =   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      : Union[str, Any]         =   AutoConfig.from_pretrained('''hf-internal-testing/test_dynamic_model''',			trust_remote_code=__a							)

										_UpperCamelCase      : int         =   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      : int         =   AutoConfig.from_pretrained(__a,			trust_remote_code=__a							)
										self.assertEqual(reloaded_config.__class__.__name__,			'''NewModelConfig'''							)






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




										'''simple docstring'''



										class 			_a						(				_lowerCAmelCase    ):
														UpperCamelCase								=   '''new-model'''

										try:
																AutoConfig.register('''new-model''',			__a							)
																# If remote code is not set, the default is to use local
																_UpperCamelCase      : List[str]         =   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      : str         =   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      : Union[str, Any]         =   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"]










"""simple docstring"""




def 	a_    (							_lowercase	,						_lowercase       ):
						if discount_rate < 0:
												raise ValueError('''Discount rate cannot be negative'''       )
						if not cash_flows:
												raise ValueError('''Cash flows list cannot be empty'''       )
						_UpperCamelCase      : Optional[int]         =   sum(
						    cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(_lowercase       )       )
						return round(_lowercase	,						ndigits=2       )


if __name__ == "__main__":
						import doctest

						doctest.testmod()



