
"""simple docstring"""




import json
import sys
import tempfile
import unittest
from pathlib import Path

import transformers
from transformers import (
    CONFIG_MAPPING,
    IMAGE_PROCESSOR_MAPPING,
    AutoConfig,
    AutoImageProcessor,
    CLIPConfig,
    CLIPImageProcessor,
)
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER


sys.path.append(str(Path(__file__).parent.parent.parent.parent / 'utils'))

from test_module.custom_configuration import CustomConfig  # noqa E402
from test_module.custom_image_processing import CustomImageProcessor  # noqa E402





class 			snake_case  (				unittest.TestCase ):

							def _lowercase       (self     ):

									"""simple docstring"""







									SCREAMING_SNAKE_CASE_    			=			0

							def _lowercase       (self     ):

									"""simple docstring"""







									SCREAMING_SNAKE_CASE_    			=			AutoImageProcessor.from_pretrained('''openai/clip-vit-base-patch32'''     )
									self.assertIsInstance(SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_     )

							def _lowercase       (self     ):

									"""simple docstring"""







									with tempfile.TemporaryDirectory() as tmpdirname:
											SCREAMING_SNAKE_CASE_    			=			Path(SCREAMING_SNAKE_CASE_     ) / '''preprocessor_config.json'''
											SCREAMING_SNAKE_CASE_    			=			Path(SCREAMING_SNAKE_CASE_     ) / '''config.json'''
											json.dump(
											    {'''image_processor_type''': '''CLIPImageProcessor''', '''processor_class''': '''CLIPProcessor'''}							,							open(SCREAMING_SNAKE_CASE_							,							'''w'''     )							,							)
											json.dump({'''model_type''': '''clip'''}							,							open(SCREAMING_SNAKE_CASE_							,							'''w'''     )     )

											SCREAMING_SNAKE_CASE_    			=			AutoImageProcessor.from_pretrained(SCREAMING_SNAKE_CASE_     )
											self.assertIsInstance(SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_     )

							def _lowercase       (self     ):

									"""simple docstring"""







									with tempfile.TemporaryDirectory() as tmpdirname:
											SCREAMING_SNAKE_CASE_    			=			Path(SCREAMING_SNAKE_CASE_     ) / '''preprocessor_config.json'''
											SCREAMING_SNAKE_CASE_    			=			Path(SCREAMING_SNAKE_CASE_     ) / '''config.json'''
											json.dump(
											    {'''feature_extractor_type''': '''CLIPFeatureExtractor''', '''processor_class''': '''CLIPProcessor'''}							,							open(SCREAMING_SNAKE_CASE_							,							'''w'''     )							,							)
											json.dump({'''model_type''': '''clip'''}							,							open(SCREAMING_SNAKE_CASE_							,							'''w'''     )     )

											SCREAMING_SNAKE_CASE_    			=			AutoImageProcessor.from_pretrained(SCREAMING_SNAKE_CASE_     )
											self.assertIsInstance(SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_     )

							def _lowercase       (self     ):

									"""simple docstring"""







									with tempfile.TemporaryDirectory() as tmpdirname:
											SCREAMING_SNAKE_CASE_    			=			CLIPConfig()

											# Create a dummy config file with image_proceesor_type
											SCREAMING_SNAKE_CASE_    			=			Path(SCREAMING_SNAKE_CASE_     ) / '''preprocessor_config.json'''
											SCREAMING_SNAKE_CASE_    			=			Path(SCREAMING_SNAKE_CASE_     ) / '''config.json'''
											json.dump(
											    {'''image_processor_type''': '''CLIPImageProcessor''', '''processor_class''': '''CLIPProcessor'''}							,							open(SCREAMING_SNAKE_CASE_							,							'''w'''     )							,							)
											json.dump({'''model_type''': '''clip'''}							,							open(SCREAMING_SNAKE_CASE_							,							'''w'''     )     )

											# remove image_processor_type to make sure config.json alone is enough to load image processor locally
											SCREAMING_SNAKE_CASE_    			=			AutoImageProcessor.from_pretrained(SCREAMING_SNAKE_CASE_     ).to_dict()

											config_dict.pop('''image_processor_type'''     )
											SCREAMING_SNAKE_CASE_    			=			CLIPImageProcessor(**SCREAMING_SNAKE_CASE_     )

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

											SCREAMING_SNAKE_CASE_    			=			AutoImageProcessor.from_pretrained(SCREAMING_SNAKE_CASE_     )

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

									self.assertIsInstance(SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_     )

							def _lowercase       (self     ):

									"""simple docstring"""







									with tempfile.TemporaryDirectory() as tmpdirname:
											SCREAMING_SNAKE_CASE_    			=			Path(SCREAMING_SNAKE_CASE_     ) / '''preprocessor_config.json'''
											json.dump(
											    {'''image_processor_type''': '''CLIPImageProcessor''', '''processor_class''': '''CLIPProcessor'''}							,							open(SCREAMING_SNAKE_CASE_							,							'''w'''     )							,							)

											SCREAMING_SNAKE_CASE_    			=			AutoImageProcessor.from_pretrained(SCREAMING_SNAKE_CASE_     )
											self.assertIsInstance(SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_     )

							def _lowercase       (self     ):

									"""simple docstring"""







									with self.assertRaisesRegex(
									    SCREAMING_SNAKE_CASE_							,							'''clip-base is not a local folder and is not a valid model identifier'''     ):
											SCREAMING_SNAKE_CASE_    			=			AutoImageProcessor.from_pretrained('''clip-base'''     )

							def _lowercase       (self     ):

									"""simple docstring"""







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

							def _lowercase       (self     ):

									"""simple docstring"""







									with self.assertRaisesRegex(
									    SCREAMING_SNAKE_CASE_							,							'''hf-internal-testing/config-no-model does not appear to have a file named preprocessor_config.json.'''							,							):
											SCREAMING_SNAKE_CASE_    			=			AutoImageProcessor.from_pretrained('''hf-internal-testing/config-no-model'''     )

							def _lowercase       (self     ):

									"""simple docstring"""







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

									SCREAMING_SNAKE_CASE_    			=			AutoImageProcessor.from_pretrained(
									    '''hf-internal-testing/test_dynamic_image_processor'''							,							trust_remote_code=SCREAMING_SNAKE_CASE_     )
									self.assertEqual(image_processor.__class__.__name__							,							'''NewImageProcessor'''     )

									# Test image processor can be reloaded.
									with tempfile.TemporaryDirectory() as tmp_dir:
											image_processor.save_pretrained(SCREAMING_SNAKE_CASE_     )
											SCREAMING_SNAKE_CASE_    			=			AutoImageProcessor.from_pretrained(SCREAMING_SNAKE_CASE_							,							trust_remote_code=SCREAMING_SNAKE_CASE_     )
									self.assertEqual(reloaded_image_processor.__class__.__name__							,							'''NewImageProcessor'''     )

							def _lowercase       (self     ):

									"""simple docstring"""







									try:
											AutoConfig.register('''custom'''							,							SCREAMING_SNAKE_CASE_     )
											AutoImageProcessor.register(SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_     )
											# Trying to register something existing in the Transformers library will raise an error
											with self.assertRaises(SCREAMING_SNAKE_CASE_     ):
													AutoImageProcessor.register(SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_     )

											with tempfile.TemporaryDirectory() as tmpdirname:
													SCREAMING_SNAKE_CASE_    			=			Path(SCREAMING_SNAKE_CASE_     ) / '''preprocessor_config.json'''
													SCREAMING_SNAKE_CASE_    			=			Path(SCREAMING_SNAKE_CASE_     ) / '''config.json'''
													json.dump(
													    {'''feature_extractor_type''': '''CLIPFeatureExtractor''', '''processor_class''': '''CLIPProcessor'''}							,							open(SCREAMING_SNAKE_CASE_							,							'''w'''     )							,							)
													json.dump({'''model_type''': '''clip'''}							,							open(SCREAMING_SNAKE_CASE_							,							'''w'''     )     )

													SCREAMING_SNAKE_CASE_    			=			CustomImageProcessor.from_pretrained(SCREAMING_SNAKE_CASE_     )

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

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







							def _lowercase       (self     ):

									"""simple docstring"""







									class 			snake_case  (				_a ):
																UpperCAmelCase__      =   True

									try:
											AutoConfig.register('''custom'''							,							SCREAMING_SNAKE_CASE_     )
											AutoImageProcessor.register(SCREAMING_SNAKE_CASE_							,							SCREAMING_SNAKE_CASE_     )
											# If remote code is not set, the default is to use local
											SCREAMING_SNAKE_CASE_    			=			AutoImageProcessor.from_pretrained('''hf-internal-testing/test_dynamic_image_processor'''     )
											self.assertEqual(image_processor.__class__.__name__							,							'''NewImageProcessor'''     )
											self.assertTrue(image_processor.is_local     )

											# If remote code is disabled, we load the local one.
											SCREAMING_SNAKE_CASE_    			=			AutoImageProcessor.from_pretrained(
											    '''hf-internal-testing/test_dynamic_image_processor'''							,							trust_remote_code=SCREAMING_SNAKE_CASE_     )
											self.assertEqual(image_processor.__class__.__name__							,							'''NewImageProcessor'''     )
											self.assertTrue(image_processor.is_local     )

											# If remote is enabled, we load from the Hub
											SCREAMING_SNAKE_CASE_    			=			AutoImageProcessor.from_pretrained(
											    '''hf-internal-testing/test_dynamic_image_processor'''							,							trust_remote_code=SCREAMING_SNAKE_CASE_     )
											self.assertEqual(image_processor.__class__.__name__							,							'''NewImageProcessor'''     )
											self.assertTrue(not hasattr(SCREAMING_SNAKE_CASE_							,							'''is_local'''     )     )

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



import requests
from bsa import BeautifulSoup





def 						_lowerCAmelCase							(     _lowerCAmelCase = "AAPL"			)    ->						str:


						'''simple docstring'''






						__snake_case				=		F'''https://in.finance.yahoo.com/quote/{symbol}?s={symbol}'''
						__snake_case				=		BeautifulSoup(requests.get(_lowerCAmelCase			).text   ,						"html.parser"			)
						__snake_case				=		"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}''')





