



"""simple docstring"""






import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
   import torch

if is_vision_available():
   from PIL import Image

   from transformers import ChineseCLIPImageProcessor






class        __snake_case       (	unittest.TestCase):




  def __init__( self     :						Any						,					__lowerCAmelCase     :						List[Any]						,					__lowerCAmelCase     :						List[str]=7						,					__lowerCAmelCase     :						Union[str, Any]=3						,					__lowerCAmelCase     :						Dict=1_8						,					__lowerCAmelCase     :						str=3_0						,					__lowerCAmelCase     :						Union[str, Any]=4_0_0						,					__lowerCAmelCase     :						int=True						,					__lowerCAmelCase     :						Any=None						,					__lowerCAmelCase     :						Union[str, Any]=True						,					__lowerCAmelCase     :						Union[str, Any]=None						,					__lowerCAmelCase     :						Tuple=True						,					__lowerCAmelCase     :						List[Any]=[0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]						,					__lowerCAmelCase     :						Optional[Any]=[0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]						,					__lowerCAmelCase     :						Optional[int]=True						,					):






         """simple docstring"""






         _lowerCamelCase						:				Dict    			= size if size is not None else {'''height''': 2_2_4, '''width''': 2_2_4}
         _lowerCamelCase						:				Dict    			= crop_size if crop_size is not None else {'''height''': 1_8, '''width''': 1_8}
         _lowerCamelCase						:				Dict    			= parent
         _lowerCamelCase						:				List[Any]    			= batch_size
         _lowerCamelCase						:				List[Any]    			= num_channels
         _lowerCamelCase						:				Optional[Any]    			= image_size
         _lowerCamelCase						:				List[Any]    			= min_resolution
         _lowerCamelCase						:				Optional[Any]    			= max_resolution
         _lowerCamelCase						:				Dict    			= do_resize
         _lowerCamelCase						:				List[Any]    			= size
         _lowerCamelCase						:				Tuple    			= do_center_crop
         _lowerCamelCase						:				List[str]    			= crop_size
         _lowerCamelCase						:				Dict    			= do_normalize
         _lowerCamelCase						:				Optional[Any]    			= image_mean
         _lowerCamelCase						:				Dict    			= image_std
         _lowerCamelCase						:				Optional[Any]    			= do_convert_rgb




  def 						SCREAMING_SNAKE_CASE				( self     :						Optional[Any]		):






         """simple docstring"""






         return {
             "do_resize": self.do_resize,
             "size": self.size,
             "do_center_crop": self.do_center_crop,
             "crop_size": self.crop_size,
             "do_normalize": self.do_normalize,
             "image_mean": self.image_mean,
             "image_std": self.image_std,
             "do_convert_rgb": self.do_convert_rgb,
         }




  def 						SCREAMING_SNAKE_CASE				( self     :						List[Any]						,					__lowerCAmelCase     :						Optional[int]=False						,					__lowerCAmelCase     :						Tuple=False						,					__lowerCAmelCase     :						Optional[Any]=False		):






         """simple docstring"""






         assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

         if equal_resolution:
                _lowerCamelCase						:				Optional[Any]    			= []
                for i in range(self.batch_size		):
                       image_inputs.append(
                           np.random.randint(
                               2_5_5						,					size=(self.num_channels, self.max_resolution, self.max_resolution)						,					dtype=np.uinta		)		)
         else:
                _lowerCamelCase						:				Union[str, Any]    			= []
                for i in range(self.batch_size		):
                       _lowerCamelCase			,    _lowerCamelCase						:				Dict    			= np.random.choice(np.arange(self.min_resolution						,					self.max_resolution		)						,					2		)
                       image_inputs.append(np.random.randint(2_5_5						,					size=(self.num_channels, width, height)						,					dtype=np.uinta		)		)

         if not numpify and not torchify:
                # PIL expects the channel dimension as last dimension
                _lowerCamelCase						:				Any    			= [Image.fromarray(np.moveaxis(__lowerCAmelCase						,					0						,					-1		)		) for x in image_inputs]

         if torchify:
                _lowerCamelCase						:				List[Any]    			= [torch.from_numpy(__lowerCAmelCase		) for x in image_inputs]

         return image_inputs






@require_torch
@require_vision
class        __snake_case       (	_lowercase  ,     unittest.TestCase):
  snake_case__				:   Union[str, Any]  			=						ChineseCLIPImageProcessor if is_vision_available() else None




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






         """simple docstring"""






         _lowerCamelCase						:				List[str]    			= ChineseCLIPImageProcessingTester(self						,					do_center_crop=__lowerCAmelCase		)




  @property
  def 						SCREAMING_SNAKE_CASE				( self     :						Tuple		):






         """simple docstring"""






         return self.image_processor_tester.prepare_image_processor_dict()




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






         """simple docstring"""






         _lowerCamelCase						:				Tuple    			= self.image_processing_class(**self.image_processor_dict		)
         self.assertTrue(hasattr(__lowerCAmelCase						,					'''do_resize'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						,					'''size'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						,					'''do_center_crop'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						,					'''center_crop'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						,					'''do_normalize'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						,					'''image_mean'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						,					'''image_std'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						,					'''do_convert_rgb'''		)		)




  def 						SCREAMING_SNAKE_CASE				( self     :						Optional[Any]		):






         """simple docstring"""






         _lowerCamelCase						:				Optional[Any]    			= self.image_processing_class.from_dict(self.image_processor_dict		)
         self.assertEqual(image_processor.size						,					{'''height''': 2_2_4, '''width''': 2_2_4}		)
         self.assertEqual(image_processor.crop_size						,					{'''height''': 1_8, '''width''': 1_8}		)

         _lowerCamelCase						:				Any    			= self.image_processing_class.from_dict(self.image_processor_dict						,					size=4_2						,					crop_size=8_4		)
         self.assertEqual(image_processor.size						,					{'''shortest_edge''': 4_2}		)
         self.assertEqual(image_processor.crop_size						,					{'''height''': 8_4, '''width''': 8_4}		)




  def 						SCREAMING_SNAKE_CASE				( self     :						Optional[Any]		):






         """simple docstring"""






         pass




  def 						SCREAMING_SNAKE_CASE				( self     :						Optional[int]		):






         """simple docstring"""






         _lowerCamelCase						:				Union[str, Any]    			= self.image_processing_class(**self.image_processor_dict		)
         # create random PIL images
         _lowerCamelCase						:				Tuple    			= self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCAmelCase		)
         for image in image_inputs:
                self.assertIsInstance(__lowerCAmelCase						,					Image.Image		)

         # Test not batched input
         _lowerCamelCase						:				Optional[Any]    			= image_processing(image_inputs[0]						,					return_tensors='''pt'''		).pixel_values
         self.assertEqual(
             encoded_images.shape						,					(
                 1,
                 self.image_processor_tester.num_channels,
                 self.image_processor_tester.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             )						,					)

         # Test batched
         _lowerCamelCase						:				str    			= image_processing(__lowerCAmelCase						,					return_tensors='''pt'''		).pixel_values
         self.assertEqual(
             encoded_images.shape						,					(
                 self.image_processor_tester.batch_size,
                 self.image_processor_tester.num_channels,
                 self.image_processor_tester.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             )						,					)




  def 						SCREAMING_SNAKE_CASE				( self     :						int		):






         """simple docstring"""






         _lowerCamelCase						:				Tuple    			= self.image_processing_class(**self.image_processor_dict		)
         # create random numpy tensors
         _lowerCamelCase						:				Tuple    			= self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCAmelCase						,					numpify=__lowerCAmelCase		)
         for image in image_inputs:
                self.assertIsInstance(__lowerCAmelCase						,					np.ndarray		)

         # Test not batched input
         _lowerCamelCase						:				Dict    			= image_processing(image_inputs[0]						,					return_tensors='''pt'''		).pixel_values
         self.assertEqual(
             encoded_images.shape						,					(
                 1,
                 self.image_processor_tester.num_channels,
                 self.image_processor_tester.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             )						,					)

         # Test batched
         _lowerCamelCase						:				Optional[int]    			= image_processing(__lowerCAmelCase						,					return_tensors='''pt'''		).pixel_values
         self.assertEqual(
             encoded_images.shape						,					(
                 self.image_processor_tester.batch_size,
                 self.image_processor_tester.num_channels,
                 self.image_processor_tester.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             )						,					)




  def 						SCREAMING_SNAKE_CASE				( self     :						Optional[Any]		):






         """simple docstring"""






         _lowerCamelCase						:				Any    			= self.image_processing_class(**self.image_processor_dict		)
         # create random PyTorch tensors
         _lowerCamelCase						:				Dict    			= self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCAmelCase						,					torchify=__lowerCAmelCase		)
         for image in image_inputs:
                self.assertIsInstance(__lowerCAmelCase						,					torch.Tensor		)

         # Test not batched input
         _lowerCamelCase						:				Dict    			= image_processing(image_inputs[0]						,					return_tensors='''pt'''		).pixel_values
         self.assertEqual(
             encoded_images.shape						,					(
                 1,
                 self.image_processor_tester.num_channels,
                 self.image_processor_tester.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             )						,					)

         # Test batched
         _lowerCamelCase						:				Union[str, Any]    			= image_processing(__lowerCAmelCase						,					return_tensors='''pt'''		).pixel_values
         self.assertEqual(
             encoded_images.shape						,					(
                 self.image_processor_tester.batch_size,
                 self.image_processor_tester.num_channels,
                 self.image_processor_tester.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             )						,					)






@require_torch
@require_vision
class        __snake_case       (	_lowercase  ,     unittest.TestCase):
  snake_case__				:   Optional[int]  			=						ChineseCLIPImageProcessor if is_vision_available() else None




  def 						SCREAMING_SNAKE_CASE				( self     :						Tuple		):






         """simple docstring"""






         _lowerCamelCase						:				Any    			= ChineseCLIPImageProcessingTester(self						,					num_channels=4						,					do_center_crop=__lowerCAmelCase		)
         _lowerCamelCase						:				List[Any]    			= 3




  @property
  def 						SCREAMING_SNAKE_CASE				( self     :						Tuple		):






         """simple docstring"""






         return self.image_processor_tester.prepare_image_processor_dict()




  def 						SCREAMING_SNAKE_CASE				( self     :						str		):






         """simple docstring"""






         _lowerCamelCase						:				int    			= self.image_processing_class(**self.image_processor_dict		)
         self.assertTrue(hasattr(__lowerCAmelCase						,					'''do_resize'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						,					'''size'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						,					'''do_center_crop'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						,					'''center_crop'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						,					'''do_normalize'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						,					'''image_mean'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						,					'''image_std'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						,					'''do_convert_rgb'''		)		)




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






         """simple docstring"""






         pass




  def 						SCREAMING_SNAKE_CASE				( self     :						List[Any]		):






         """simple docstring"""






         _lowerCamelCase						:				List[Any]    			= self.image_processing_class(**self.image_processor_dict		)
         # create random PIL images
         _lowerCamelCase						:				List[Any]    			= self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCAmelCase		)
         for image in image_inputs:
                self.assertIsInstance(__lowerCAmelCase						,					Image.Image		)

         # Test not batched input
         _lowerCamelCase						:				Optional[int]    			= image_processing(image_inputs[0]						,					return_tensors='''pt'''		).pixel_values
         self.assertEqual(
             encoded_images.shape						,					(
                 1,
                 self.expected_encoded_image_num_channels,
                 self.image_processor_tester.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             )						,					)

         # Test batched
         _lowerCamelCase						:				str    			= image_processing(__lowerCAmelCase						,					return_tensors='''pt'''		).pixel_values
         self.assertEqual(
             encoded_images.shape						,					(
                 self.image_processor_tester.batch_size,
                 self.expected_encoded_image_num_channels,
                 self.image_processor_tester.crop_size['''height'''],
                 self.image_processor_tester.crop_size['''width'''],
             )						,					)



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 					lowercase__						(   unittest.TestCase):


						def        __A       (       self	:				List[Any]						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    Dict							=							0


						def        __A       (       self	:				Dict						):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:    str							=							AutoImageProcessor.from_pretrained('''openai/clip-vit-base-patch32'''						)
												self.assertIsInstance(UpperCamelCase__    ,		UpperCamelCase__						)


						def        __A       (       self	:				Dict						):





												'''simple docstring'''





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

																		SCREAMING_SNAKE_CASE							:    Any							=							AutoImageProcessor.from_pretrained(UpperCamelCase__						)
																		self.assertIsInstance(UpperCamelCase__    ,		UpperCamelCase__						)


						def        __A       (       self	:				int						):





												'''simple docstring'''





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

																		SCREAMING_SNAKE_CASE							:    Optional[Any]							=							AutoImageProcessor.from_pretrained(UpperCamelCase__						)
																		self.assertIsInstance(UpperCamelCase__    ,		UpperCamelCase__						)


						def        __A       (       self	:				List[str]						):





												'''simple docstring'''





												with tempfile.TemporaryDirectory() as tmpdirname:
																		SCREAMING_SNAKE_CASE							:    Dict							=							CLIPConfig()

																		# Create a dummy config file with image_proceesor_type
																		SCREAMING_SNAKE_CASE							:    Dict							=							Path(UpperCamelCase__						) / '''preprocessor_config.json'''
																		SCREAMING_SNAKE_CASE							:    List[str]							=							Path(UpperCamelCase__						) / '''config.json'''
																		json.dump(
																		    {'''image_processor_type''': '''CLIPImageProcessor''', '''processor_class''': '''CLIPProcessor'''}    ,		open(UpperCamelCase__    ,		'''w'''						)    ,		)
																		json.dump({'''model_type''': '''clip'''}    ,		open(UpperCamelCase__    ,		'''w'''						)						)

																		# remove image_processor_type to make sure config.json alone is enough to load image processor locally
																		SCREAMING_SNAKE_CASE							:    List[Any]							=							AutoImageProcessor.from_pretrained(UpperCamelCase__						).to_dict()

																		config_dict.pop('''image_processor_type'''						)
																		SCREAMING_SNAKE_CASE							:    str							=							CLIPImageProcessor(**UpperCamelCase__						)

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

																		SCREAMING_SNAKE_CASE							:    Union[str, Any]							=							AutoImageProcessor.from_pretrained(UpperCamelCase__						)

																		# make sure private variable is not incorrectly saved
																		SCREAMING_SNAKE_CASE							:    List[Any]							=							json.loads(config.to_json_string()						)
																		self.assertTrue('''_processor_class''' not in dict_as_saved						)

												self.assertIsInstance(UpperCamelCase__    ,		UpperCamelCase__						)


						def        __A       (       self	:				Tuple						):





												'''simple docstring'''





												with tempfile.TemporaryDirectory() as tmpdirname:
																		SCREAMING_SNAKE_CASE							:    Optional[int]							=							Path(UpperCamelCase__						) / '''preprocessor_config.json'''
																		json.dump(
																		    {'''image_processor_type''': '''CLIPImageProcessor''', '''processor_class''': '''CLIPProcessor'''}    ,		open(UpperCamelCase__    ,		'''w'''						)    ,		)

																		SCREAMING_SNAKE_CASE							:    Dict							=							AutoImageProcessor.from_pretrained(UpperCamelCase__						)
																		self.assertIsInstance(UpperCamelCase__    ,		UpperCamelCase__						)


						def        __A       (       self	:				int						):





												'''simple docstring'''





												with self.assertRaisesRegex(
												    UpperCamelCase__    ,		'''clip-base is not a local folder and is not a valid model identifier'''						):
																		SCREAMING_SNAKE_CASE							:    List[str]							=							AutoImageProcessor.from_pretrained('''clip-base'''						)


						def        __A       (       self	:				List[str]						):





												'''simple docstring'''





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


						def        __A       (       self	:				Dict						):





												'''simple docstring'''





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


						def        __A       (       self	:				List[Any]						):





												'''simple docstring'''





												with self.assertRaises(UpperCamelCase__						):
																		SCREAMING_SNAKE_CASE							:    str							=							AutoImageProcessor.from_pretrained('''hf-internal-testing/test_dynamic_image_processor'''						)
												# If remote code is disabled, we can't load this config.
												with self.assertRaises(UpperCamelCase__						):
																		SCREAMING_SNAKE_CASE							:    List[Any]							=							AutoImageProcessor.from_pretrained(
																		    '''hf-internal-testing/test_dynamic_image_processor'''    ,		trust_remote_code=UpperCamelCase__						)

												SCREAMING_SNAKE_CASE							:    List[Any]							=							AutoImageProcessor.from_pretrained(
												    '''hf-internal-testing/test_dynamic_image_processor'''    ,		trust_remote_code=UpperCamelCase__						)
												self.assertEqual(image_processor.__class__.__name__    ,		'''NewImageProcessor'''						)

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


						def        __A       (       self	:				Optional[Any]						):





												'''simple docstring'''





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

																		with tempfile.TemporaryDirectory() as tmpdirname:
																								SCREAMING_SNAKE_CASE							:    Union[str, Any]							=							Path(UpperCamelCase__						) / '''preprocessor_config.json'''
																								SCREAMING_SNAKE_CASE							:    Any							=							Path(UpperCamelCase__						) / '''config.json'''
																								json.dump(
																								    {'''feature_extractor_type''': '''CLIPFeatureExtractor''', '''processor_class''': '''CLIPProcessor'''}    ,		open(UpperCamelCase__    ,		'''w'''						)    ,		)
																								json.dump({'''model_type''': '''clip'''}    ,		open(UpperCamelCase__    ,		'''w'''						)						)

																								SCREAMING_SNAKE_CASE							:    Tuple							=							CustomImageProcessor.from_pretrained(UpperCamelCase__						)

																		# 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(UpperCamelCase__						)
																								SCREAMING_SNAKE_CASE							:    Any							=							AutoImageProcessor.from_pretrained(UpperCamelCase__						)
																								self.assertIsInstance(UpperCamelCase__    ,		UpperCamelCase__						)

												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        __A       (       self	:				Any						):





												'''simple docstring'''





												class 					lowercase__						(   UpperCamelCase_):
																		UpperCamelCase_     =		True

												try:
																		AutoConfig.register('''custom'''    ,		UpperCamelCase__						)
																		AutoImageProcessor.register(UpperCamelCase__    ,		UpperCamelCase__						)
																		# If remote code is not set, the default is to use local
																		SCREAMING_SNAKE_CASE							:    str							=							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							:    Union[str, Any]							=							AutoImageProcessor.from_pretrained(
																		    '''hf-internal-testing/test_dynamic_image_processor'''    ,		trust_remote_code=UpperCamelCase__						)
																		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							:    Optional[Any]							=							AutoImageProcessor.from_pretrained(
																		    '''hf-internal-testing/test_dynamic_image_processor'''    ,		trust_remote_code=UpperCamelCase__						)
																		self.assertEqual(image_processor.__class__.__name__    ,		'''NewImageProcessor'''						)
																		self.assertTrue(not hasattr(UpperCamelCase__    ,		'''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]





