'''simple docstring'''


import json
import os
import tempfile
import unittest
import unittest.mock as mock
from pathlib import Path

from requests.exceptions import HTTPError

from transformers.utils import (
    CONFIG_NAME,
    FLAX_WEIGHTS_NAME,
    TF2_WEIGHTS_NAME,
    TRANSFORMERS_CACHE,
    WEIGHTS_NAME,
    cached_file,
    get_file_from_repo,
    has_file,
)


__lowerCAmelCase	:       List[Any]						       =	"hf-internal-testing/tiny-random-bert"
__lowerCAmelCase	:       int						       =	os.path.join(TRANSFORMERS_CACHE, "models--hf-internal-testing--tiny-random-bert")
__lowerCAmelCase	:       List[str]						       =	"9b8c223d42b2188cb49d29af482996f9d0f3e5a6"






class 						A   (   unittest.TestCase   ):





							def       snake_case__						(      self				:							List[str]	)							->	Union[str, Any]:
								__UpperCAmelCase							=			cached_file(__a     ,		__a	)
								# Should have downloaded the file in here
								self.assertTrue(os.path.isdir(__a	)	)
								# Cache should contain at least those three subfolders:
								for subfolder in ["blobs", "refs", "snapshots"]:
									self.assertTrue(os.path.isdir(os.path.join(__a     ,		__a	)	)	)
								with open(os.path.join(__a     ,		'''refs'''     ,		'''main'''	)	) as f:
									__UpperCAmelCase							=			f.read()
								self.assertEqual(__a     ,		os.path.join(__a     ,		'''snapshots'''     ,		__a     ,		__a	)	)
								self.assertTrue(os.path.isfile(__a	)	)

								# File is cached at the same place the second time.
								__UpperCAmelCase							=			cached_file(__a     ,		__a	)
								self.assertEqual(__a     ,		__a	)

								# Using a specific revision to test the full commit hash.
								__UpperCAmelCase							=			cached_file(__a     ,		__a     ,		revision='''9b8c223'''	)
								self.assertEqual(__a     ,		os.path.join(__a     ,		'''snapshots'''     ,		__a     ,		__a	)	)





							def       snake_case__						(      self				:							Tuple	)							->	List[Any]:
								with self.assertRaisesRegex(__a     ,		'''is not a valid model identifier'''	):
									__UpperCAmelCase							=			cached_file('''tiny-random-bert'''     ,		__a	)

								with self.assertRaisesRegex(__a     ,		'''is not a valid git identifier'''	):
									__UpperCAmelCase							=			cached_file(__a     ,		__a     ,		revision='''aaaa'''	)

								with self.assertRaisesRegex(__a     ,		'''does not appear to have a file named'''	):
									__UpperCAmelCase							=			cached_file(__a     ,		'''conf'''	)





							def       snake_case__						(      self				:							List[Any]	)							->	Optional[int]:
								with self.assertRaisesRegex(__a     ,		'''does not appear to have a file named'''	):
									__UpperCAmelCase							=			cached_file(__a     ,		'''conf'''	)

								with open(os.path.join(__a     ,		'''refs'''     ,		'''main'''	)	) as f:
									__UpperCAmelCase							=			f.read()
								self.assertTrue(os.path.isfile(os.path.join(__a     ,		'''.no_exist'''     ,		__a     ,		'''conf'''	)	)	)

								__UpperCAmelCase							=			cached_file(__a     ,		'''conf'''     ,		_raise_exceptions_for_missing_entries=__a	)
								self.assertIsNone(__a	)

								__UpperCAmelCase							=			cached_file(__a     ,		'''conf'''     ,		local_files_only=__a     ,		_raise_exceptions_for_missing_entries=__a	)
								self.assertIsNone(__a	)

								__UpperCAmelCase							=			mock.Mock()
								__UpperCAmelCase							=			5_0_0
								__UpperCAmelCase							=			{}
								__UpperCAmelCase							=			HTTPError
								__UpperCAmelCase							=			{}

								# Under the mock environment we get a 500 error when trying to reach the tokenizer.
								with mock.patch('''requests.Session.request'''     ,		return_value=__a	) as mock_head:
									__UpperCAmelCase							=			cached_file(__a     ,		'''conf'''     ,		_raise_exceptions_for_connection_errors=__a	)
									self.assertIsNone(__a	)
									# This check we did call the fake head request
									mock_head.assert_called()





							def       snake_case__						(      self				:							Optional[Any]	)							->	Optional[Any]:
								self.assertTrue(has_file('''hf-internal-testing/tiny-bert-pt-only'''     ,		__a	)	)
								self.assertFalse(has_file('''hf-internal-testing/tiny-bert-pt-only'''     ,		__a	)	)
								self.assertFalse(has_file('''hf-internal-testing/tiny-bert-pt-only'''     ,		__a	)	)





							def       snake_case__						(      self				:							Optional[int]	)							->	int:
								# `get_file_from_repo` returns None if the file does not exist
								self.assertIsNone(get_file_from_repo('''bert-base-cased'''     ,		'''ahah.txt'''	)	)

								# The function raises if the repository does not exist.
								with self.assertRaisesRegex(__a     ,		'''is not a valid model identifier'''	):
									get_file_from_repo('''bert-base-case'''     ,		__a	)

								# The function raises if the revision does not exist.
								with self.assertRaisesRegex(__a     ,		'''is not a valid git identifier'''	):
									get_file_from_repo('''bert-base-cased'''     ,		__a     ,		revision='''ahaha'''	)

								__UpperCAmelCase							=			get_file_from_repo('''bert-base-cased'''     ,		__a	)
								# The name is the cached name which is not very easy to test, so instead we load the content.
								__UpperCAmelCase							=			json.loads(open(__a     ,		'''r'''	).read()	)
								self.assertEqual(config['''hidden_size''']     ,		7_6_8	)






							def       snake_case__						(      self				:							Optional[int]	)							->	Optional[Any]:
								with tempfile.TemporaryDirectory() as tmp_dir:
									__UpperCAmelCase							=			Path(__a	) / '''a.txt'''
									filename.touch()
									self.assertEqual(get_file_from_repo(__a     ,		'''a.txt'''	)     ,		str(__a	)	)

									self.assertIsNone(get_file_from_repo(__a     ,		'''b.txt'''	)	)






'''simple docstring'''


import requests
from bsa import BeautifulSoup





def       lowerCAmelCase					(		UpperCamelCase__				:   str = "AAPL"       ):


	"""simple docstring"""
	__UpperCAmelCase							=			f"""https://in.finance.yahoo.com/quote/{symbol}?s={symbol}"""
	__UpperCAmelCase							=			BeautifulSoup(requests.get(UpperCamelCase__       ).text    ,					'''html.parser'''       )
	__UpperCAmelCase							=			'''My(6px) Pos(r) smartphone_Mt(6px)'''
	return soup.find('''div'''    ,					class_=class_       ).find('''span'''       ).text


if __name__ == "__main__":
					for symbol in "AAPL AMZN IBM GOOG MSFT ORCL".split():
										print(F"""Current {symbol:<4} stock price is {stock_price(symbol):>8}""")
