

"""simple docstring"""




import bza
import gzip
import lzma
import os
import shutil
import struct
import tarfile
import warnings
import zipfile
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Dict, List, Optional, Type, Union

from .. import config
from .filelock import FileLock
from .logging import get_logger


A_				:      List[str]           =			get_logger(__name__)





class  lowerCamelCase    :

			def __init__(       self					:    str     ,					__UpperCAmelCase					:    Optional[str] = None							) ->     Optional[Any]:
						SCREAMING_SNAKE_CASE__										=   (
						    os.path.join(__UpperCAmelCase     ,					config.EXTRACTED_DATASETS_DIR							) if cache_dir else config.EXTRACTED_DATASETS_PATH
						)
						SCREAMING_SNAKE_CASE__										=   Extractor

			def        SCREAMING_SNAKE_CASE					(       self					:    Dict     ,					__UpperCAmelCase					:    str							) ->     str:
						from .file_utils import hash_url_to_filename

						# Path where we extract compressed archives
						# We extract in the cache dir, and get the extracted path name by hashing the original path"
						SCREAMING_SNAKE_CASE__										=   os.path.abspath(__UpperCAmelCase							)
						return os.path.join(self.extract_dir     ,					hash_url_to_filename(__UpperCAmelCase							)							)

			def        SCREAMING_SNAKE_CASE					(       self					:    List[Any]     ,					__UpperCAmelCase					:    str     ,					__UpperCAmelCase					:    bool							) ->     bool:
						return force_extract or (
						    not os.path.isfile(__UpperCAmelCase							) and not (os.path.isdir(__UpperCAmelCase							) and os.listdir(__UpperCAmelCase							))
						)





			def        SCREAMING_SNAKE_CASE					(       self					:    List[str]     ,					__UpperCAmelCase					:    str     ,					__UpperCAmelCase					:    bool = False							) ->     str:
						SCREAMING_SNAKE_CASE__										=   self.extractor.infer_extractor_format(__UpperCAmelCase							)
						if not extractor_format:
									return input_path
						SCREAMING_SNAKE_CASE__										=   self._get_output_path(__UpperCAmelCase							)
						if self._do_extract(__UpperCAmelCase     ,					__UpperCAmelCase							):
									self.extractor.extract(__UpperCAmelCase     ,					__UpperCAmelCase     ,					__UpperCAmelCase							)
						return output_path





class  lowerCamelCase    (A__      ):

			@classmethod
			@abstractmethod
			def        SCREAMING_SNAKE_CASE					(       cls					:    Optional[int]     ,					__UpperCAmelCase					:    Union[Path, str]     ,					**__UpperCAmelCase					:    Any							) ->     bool:
						...





			@staticmethod
			@abstractmethod
			def        SCREAMING_SNAKE_CASE					(       __UpperCAmelCase					:    Union[Path, str]     ,					__UpperCAmelCase					:    Union[Path, str]							) ->     None:
						...





class  lowerCamelCase    (A__      ,A__      ):
			lowerCamelCase__ :		List[bytes]       		=				[]

			@staticmethod
			def        SCREAMING_SNAKE_CASE					(       __UpperCAmelCase					:    Union[Path, str]     ,					__UpperCAmelCase					:    int							) ->     int:
						with open(__UpperCAmelCase     ,					"""rb"""							) as f:
									return f.read(__UpperCAmelCase							)





			@classmethod
			def        SCREAMING_SNAKE_CASE					(       cls					:    Dict     ,					__UpperCAmelCase					:    Union[Path, str]     ,					__UpperCAmelCase					:    bytes = b""							) ->     bool:
						if not magic_number:
									SCREAMING_SNAKE_CASE__										=   max(len(__UpperCAmelCase							) for cls_magic_number in cls.magic_numbers							)
									try:
												SCREAMING_SNAKE_CASE__										=   cls.read_magic_number(__UpperCAmelCase     ,					__UpperCAmelCase							)
									except OSError:
												return False
						return any(magic_number.startswith(__UpperCAmelCase							) for cls_magic_number in cls.magic_numbers							)





class  lowerCamelCase    (A__      ):

			@classmethod
			def        SCREAMING_SNAKE_CASE					(       cls					:    str     ,					__UpperCAmelCase					:    Union[Path, str]     ,					**__UpperCAmelCase					:    List[str]							) ->     bool:
						return tarfile.is_tarfile(__UpperCAmelCase							)

			@staticmethod
			def        SCREAMING_SNAKE_CASE					(       __UpperCAmelCase					:    str     ,					__UpperCAmelCase					:    Union[str, Any]							) ->     int:

						def resolved(__UpperCAmelCase					:    str							) -> str:
									return os.path.realpath(os.path.abspath(__UpperCAmelCase							)							)

						def badpath(__UpperCAmelCase					:    str     ,					__UpperCAmelCase					:    str							) -> bool:
									# joinpath will ignore base if path is absolute
									return not resolved(os.path.join(__UpperCAmelCase     ,					__UpperCAmelCase							)							).startswith(__UpperCAmelCase							)

						def badlink(__UpperCAmelCase					:    Optional[Any]     ,					__UpperCAmelCase					:    str							) -> bool:
									# Links are interpreted relative to the directory containing the link
									SCREAMING_SNAKE_CASE__										=   resolved(os.path.join(__UpperCAmelCase     ,					os.path.dirname(info.name							)							)							)
									return badpath(info.linkname     ,					base=__UpperCAmelCase							)

						SCREAMING_SNAKE_CASE__										=   resolved(__UpperCAmelCase							)

						for finfo in members:
									if badpath(finfo.name     ,					__UpperCAmelCase							):
												logger.error(F"""Extraction of {finfo.name} is blocked (illegal path)"""							)
									elif finfo.issym() and badlink(__UpperCAmelCase     ,					__UpperCAmelCase							):
												logger.error(F"""Extraction of {finfo.name} is blocked: Symlink to {finfo.linkname}"""							)
									elif finfo.islnk() and badlink(__UpperCAmelCase     ,					__UpperCAmelCase							):
												logger.error(F"""Extraction of {finfo.name} is blocked: Hard link to {finfo.linkname}"""							)
									else:
												yield finfo





			@staticmethod
			def        SCREAMING_SNAKE_CASE					(       __UpperCAmelCase					:    Union[Path, str]     ,					__UpperCAmelCase					:    Union[Path, str]							) ->     None:
						os.makedirs(__UpperCAmelCase     ,					exist_ok=__UpperCAmelCase							)
						SCREAMING_SNAKE_CASE__										=   tarfile.open(__UpperCAmelCase							)
						tar_file.extractall(__UpperCAmelCase     ,					members=TarExtractor.safemembers(__UpperCAmelCase     ,					__UpperCAmelCase							)							)
						tar_file.close()





class  lowerCamelCase    (A__      ):
			lowerCamelCase__ :		int       		=				[b'\x1F\x8B']

			@staticmethod
			def        SCREAMING_SNAKE_CASE					(       __UpperCAmelCase					:    Union[Path, str]     ,					__UpperCAmelCase					:    Union[Path, str]							) ->     None:
						with gzip.open(__UpperCAmelCase     ,					"""rb"""							) as gzip_file:
									with open(__UpperCAmelCase     ,					"""wb"""							) as extracted_file:
												shutil.copyfileobj(__UpperCAmelCase     ,					__UpperCAmelCase							)





class  lowerCamelCase    (A__      ):
			lowerCamelCase__ :		int       		=				[
			    b'PK\x03\x04',
			    b'PK\x05\x06',  # empty archive
			    b'PK\x07\x08',  # spanned archive
			]

			@classmethod
			def        SCREAMING_SNAKE_CASE					(       cls					:    Union[str, Any]     ,					__UpperCAmelCase					:    Union[Path, str]     ,					__UpperCAmelCase					:    bytes = b""							) ->     bool:
						if super().is_extractable(__UpperCAmelCase     ,					magic_number=__UpperCAmelCase							):
									return True
						try:
									# Alternative version of zipfile.is_zipfile that has less false positives, but misses executable zip archives.
									# From: https://github.com/python/cpython/pull/5053
									from zipfile import (
									    _CD_SIGNATURE,
									    _ECD_DISK_NUMBER,
									    _ECD_DISK_START,
									    _ECD_ENTRIES_TOTAL,
									    _ECD_OFFSET,
									    _ECD_SIZE,
									    _EndRecData,
									    sizeCentralDir,
									    stringCentralDir,
									    structCentralDir,
									)

									with open(__UpperCAmelCase     ,					"""rb"""							) as fp:
												SCREAMING_SNAKE_CASE__										=   _EndRecData(__UpperCAmelCase							)
												if endrec:
															if endrec[_ECD_ENTRIES_TOTAL] == 0 and endrec[_ECD_SIZE] == 0 and endrec[_ECD_OFFSET] == 0:
																		return True  # Empty zipfiles are still zipfiles
															elif endrec[_ECD_DISK_NUMBER] == endrec[_ECD_DISK_START]:
																		fp.seek(endrec[_ECD_OFFSET]							)  # Central directory is on the same disk
																		if fp.tell() == endrec[_ECD_OFFSET] and endrec[_ECD_SIZE] >= sizeCentralDir:
																					SCREAMING_SNAKE_CASE__										=   fp.read(__UpperCAmelCase							)  # CD is where we expect it to be
																					if len(__UpperCAmelCase							) == sizeCentralDir:
																								SCREAMING_SNAKE_CASE__										=   struct.unpack(__UpperCAmelCase     ,					__UpperCAmelCase							)  # CD is the right size
																								if centdir[_CD_SIGNATURE] == stringCentralDir:
																											return True  # First central directory entry  has correct magic number
									return False
						except Exception:  # catch all errors in case future python versions change the zipfile internals
									return False





			@staticmethod
			def        SCREAMING_SNAKE_CASE					(       __UpperCAmelCase					:    Union[Path, str]     ,					__UpperCAmelCase					:    Union[Path, str]							) ->     None:
						os.makedirs(__UpperCAmelCase     ,					exist_ok=__UpperCAmelCase							)
						with zipfile.ZipFile(__UpperCAmelCase     ,					"""r"""							) as zip_file:
									zip_file.extractall(__UpperCAmelCase							)
									zip_file.close()





class  lowerCamelCase    (A__      ):
			lowerCamelCase__ :		Optional[Any]       		=				[b'\xFD\x37\x7A\x58\x5A\x00']

			@staticmethod
			def        SCREAMING_SNAKE_CASE					(       __UpperCAmelCase					:    Union[Path, str]     ,					__UpperCAmelCase					:    Union[Path, str]							) ->     None:
						with lzma.open(__UpperCAmelCase							) as compressed_file:
									with open(__UpperCAmelCase     ,					"""wb"""							) as extracted_file:
												shutil.copyfileobj(__UpperCAmelCase     ,					__UpperCAmelCase							)





class  lowerCamelCase    (A__      ):
			lowerCamelCase__ :		int       		=				[b'Rar!\x1a\x07\x00', b'Rar!\x1a\x07\x01\x00']  # RAR_ID  # RAR5_ID

			@staticmethod
			def        SCREAMING_SNAKE_CASE					(       __UpperCAmelCase					:    Union[Path, str]     ,					__UpperCAmelCase					:    Union[Path, str]							) ->     None:
						if not config.RARFILE_AVAILABLE:
									raise ImportError("""Please pip install rarfile"""							)
						import rarfile

						os.makedirs(__UpperCAmelCase     ,					exist_ok=__UpperCAmelCase							)
						SCREAMING_SNAKE_CASE__										=   rarfile.RarFile(__UpperCAmelCase							)
						rf.extractall(__UpperCAmelCase							)
						rf.close()





class  lowerCamelCase    (A__      ):
			lowerCamelCase__ :		int       		=				[b'\x28\xb5\x2F\xFD']

			@staticmethod
			def        SCREAMING_SNAKE_CASE					(       __UpperCAmelCase					:    Union[Path, str]     ,					__UpperCAmelCase					:    Union[Path, str]							) ->     None:
						if not config.ZSTANDARD_AVAILABLE:
									raise ImportError("""Please pip install zstandard"""							)
						import zstandard as zstd

						SCREAMING_SNAKE_CASE__										=   zstd.ZstdDecompressor()
						with open(__UpperCAmelCase     ,					"""rb"""							) as ifh, open(__UpperCAmelCase     ,					"""wb"""							) as ofh:
									dctx.copy_stream(__UpperCAmelCase     ,					__UpperCAmelCase							)





class  lowerCamelCase    (A__      ):
			lowerCamelCase__ :		Optional[int]       		=				[b'\x42\x5A\x68']

			@staticmethod
			def        SCREAMING_SNAKE_CASE					(       __UpperCAmelCase					:    Union[Path, str]     ,					__UpperCAmelCase					:    Union[Path, str]							) ->     None:
						with bza.open(__UpperCAmelCase     ,					"""rb"""							) as compressed_file:
									with open(__UpperCAmelCase     ,					"""wb"""							) as extracted_file:
												shutil.copyfileobj(__UpperCAmelCase     ,					__UpperCAmelCase							)





class  lowerCamelCase    (A__      ):
			lowerCamelCase__ :		int       		=				[b'\x37\x7A\xBC\xAF\x27\x1C']

			@staticmethod
			def        SCREAMING_SNAKE_CASE					(       __UpperCAmelCase					:    Union[Path, str]     ,					__UpperCAmelCase					:    Union[Path, str]							) ->     None:
						if not config.PY7ZR_AVAILABLE:
									raise ImportError("""Please pip install py7zr"""							)
						import pyazr

						os.makedirs(__UpperCAmelCase     ,					exist_ok=__UpperCAmelCase							)
						with pyazr.SevenZipFile(__UpperCAmelCase     ,					"""r"""							) as archive:
									archive.extractall(__UpperCAmelCase							)





class  lowerCamelCase    (A__      ):
			lowerCamelCase__ :		Any       		=				[b'\x04\x22\x4D\x18']

			@staticmethod
			def        SCREAMING_SNAKE_CASE					(       __UpperCAmelCase					:    Union[Path, str]     ,					__UpperCAmelCase					:    Union[Path, str]							) ->     None:
						if not config.LZ4_AVAILABLE:
									raise ImportError("""Please pip install lz4"""							)
						import lza.frame

						with lza.frame.open(__UpperCAmelCase     ,					"""rb"""							) as compressed_file:
									with open(__UpperCAmelCase     ,					"""wb"""							) as extracted_file:
												shutil.copyfileobj(__UpperCAmelCase     ,					__UpperCAmelCase							)





class  lowerCamelCase    :
			#  Put zip file to the last, b/c it is possible wrongly detected as zip (I guess it means: as tar or gzip)
			lowerCamelCase__ :		Dict[str, Type[BaseExtractor]]       		=				{
			    "tar": TarExtractor,
			    "gzip": GzipExtractor,
			    "zip": ZipExtractor,
			    "xz": XzExtractor,
			    "rar": RarExtractor,
			    "zstd": ZstdExtractor,
			    "bz2": BzipaExtractor,
			    "7z": SevenZipExtractor,  # <Added version="2.4.0"/>
			    "lz4": LzaExtractor,  # <Added version="2.4.0"/>
			}

			@classmethod
			def        SCREAMING_SNAKE_CASE					(       cls					:    str							) ->     Any:
						return max(
						    len(__UpperCAmelCase							)
						    for extractor in cls.extractors.values()
						    if issubclass(__UpperCAmelCase     ,					__UpperCAmelCase							)
						    for extractor_magic_number in extractor.magic_numbers							)

			@staticmethod
			def        SCREAMING_SNAKE_CASE					(       __UpperCAmelCase					:    Union[Path, str]     ,					__UpperCAmelCase					:    int							) ->     Union[str, Any]:
						try:
									return MagicNumberBaseExtractor.read_magic_number(__UpperCAmelCase     ,					magic_number_length=__UpperCAmelCase							)
						except OSError:
									return b""

			@classmethod
			def        SCREAMING_SNAKE_CASE					(       cls					:    Dict     ,					__UpperCAmelCase					:    Union[Path, str]     ,					__UpperCAmelCase					:    bool = False							) ->     bool:
						warnings.warn(
						    """Method 'is_extractable' was deprecated in version 2.4.0 and will be removed in 3.0.0. """
						    """Use 'infer_extractor_format' instead."""     ,					category=__UpperCAmelCase     ,					)
						SCREAMING_SNAKE_CASE__										=   cls.infer_extractor_format(__UpperCAmelCase							)
						if extractor_format:
									return True if not return_extractor else (True, cls.extractors[extractor_format])
						return False if not return_extractor else (False, None)

			@classmethod
			def        SCREAMING_SNAKE_CASE					(       cls					:    Union[str, Any]     ,					__UpperCAmelCase					:    Union[Path, str]							) ->     str:  # <Added version="2.4.0"/>
						SCREAMING_SNAKE_CASE__										=   cls._get_magic_number_max_length()
						SCREAMING_SNAKE_CASE__										=   cls._read_magic_number(__UpperCAmelCase     ,					__UpperCAmelCase							)
						for extractor_format, extractor in cls.extractors.items():
									if extractor.is_extractable(__UpperCAmelCase     ,					magic_number=__UpperCAmelCase							):
												return extractor_format





			@classmethod
			def        SCREAMING_SNAKE_CASE					(       cls					:    str     ,					__UpperCAmelCase					:    Union[Path, str]     ,					__UpperCAmelCase					:    Union[Path, str]     ,					__UpperCAmelCase					:    Optional[str] = None     ,					__UpperCAmelCase					:    Optional[BaseExtractor] = "deprecated"     ,					) ->     None:
						os.makedirs(os.path.dirname(__UpperCAmelCase							)     ,					exist_ok=__UpperCAmelCase							)
						# Prevent parallel extractions
						SCREAMING_SNAKE_CASE__										=   str(Path(__UpperCAmelCase							).with_suffix(""".lock"""							)							)
						with FileLock(__UpperCAmelCase							):
									shutil.rmtree(__UpperCAmelCase     ,					ignore_errors=__UpperCAmelCase							)
									if extractor_format or extractor != "deprecated":
												if extractor != "deprecated" or not isinstance(__UpperCAmelCase     ,					__UpperCAmelCase							):  # passed as positional arg
															warnings.warn(
															    """Parameter 'extractor' was deprecated in version 2.4.0 and will be removed in 3.0.0. """
															    """Use 'extractor_format' instead."""     ,					category=__UpperCAmelCase     ,					)
															SCREAMING_SNAKE_CASE__										=   extractor if extractor != """deprecated""" else extractor_format
												else:
															SCREAMING_SNAKE_CASE__										=   cls.extractors[extractor_format]
												return extractor.extract(__UpperCAmelCase     ,					__UpperCAmelCase							)
									else:
												warnings.warn(
												    """Parameter 'extractor_format' was made required in version 2.4.0 and not passing it will raise an """
												    """exception in 3.0.0."""     ,					category=__UpperCAmelCase     ,					)
												for extractor in cls.extractors.values():
															if extractor.is_extractable(__UpperCAmelCase							):
																		return extractor.extract(__UpperCAmelCase     ,					__UpperCAmelCase							)





"""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, prepare_image_inputs


if is_torch_available():
						import torch

if is_vision_available():
						from PIL import Image

						from transformers import MobileViTImageProcessor





class  lowerCamelCase    (unittest.TestCase      ):

			def __init__(       self					:    Tuple     ,					__UpperCAmelCase					:    str     ,					__UpperCAmelCase					:    Any=7     ,					__UpperCAmelCase					:    Union[str, Any]=3     ,					__UpperCAmelCase					:    Any=1_8     ,					__UpperCAmelCase					:    Tuple=3_0     ,					__UpperCAmelCase					:    List[Any]=4_0_0     ,					__UpperCAmelCase					:    Dict=True     ,					__UpperCAmelCase					:    int=None     ,					__UpperCAmelCase					:    List[Any]=True     ,					__UpperCAmelCase					:    Any=None     ,					__UpperCAmelCase					:    Any=True     ,					) ->     Tuple:
						SCREAMING_SNAKE_CASE__										=   size if size is not None else {"""shortest_edge""": 2_0}
						SCREAMING_SNAKE_CASE__										=   crop_size if crop_size is not None else {"""height""": 1_8, """width""": 1_8}
						SCREAMING_SNAKE_CASE__										=   parent
						SCREAMING_SNAKE_CASE__										=   batch_size
						SCREAMING_SNAKE_CASE__										=   num_channels
						SCREAMING_SNAKE_CASE__										=   image_size
						SCREAMING_SNAKE_CASE__										=   min_resolution
						SCREAMING_SNAKE_CASE__										=   max_resolution
						SCREAMING_SNAKE_CASE__										=   do_resize
						SCREAMING_SNAKE_CASE__										=   size
						SCREAMING_SNAKE_CASE__										=   do_center_crop
						SCREAMING_SNAKE_CASE__										=   crop_size
						SCREAMING_SNAKE_CASE__										=   do_flip_channel_order





			def        SCREAMING_SNAKE_CASE					(       self					:    Tuple							) ->     Any:
						return {
						    "do_resize": self.do_resize,
						    "size": self.size,
						    "do_center_crop": self.do_center_crop,
						    "crop_size": self.crop_size,
						    "do_flip_channel_order": self.do_flip_channel_order,
						}





@require_torch
@require_vision
class  lowerCamelCase    (A__      ,unittest.TestCase      ):
			lowerCamelCase__ :		Tuple       		=				MobileViTImageProcessor if is_vision_available() else None

			def        SCREAMING_SNAKE_CASE					(       self					:    Dict							) ->     Any:
						SCREAMING_SNAKE_CASE__										=   MobileViTImageProcessingTester(self							)

			@property
			def        SCREAMING_SNAKE_CASE					(       self					:    List[str]							) ->     int:
						return self.image_processor_tester.prepare_image_processor_dict()

			def        SCREAMING_SNAKE_CASE					(       self					:    Tuple							) ->     Optional[Any]:
						SCREAMING_SNAKE_CASE__										=   self.image_processing_class(**self.image_processor_dict							)
						self.assertTrue(hasattr(__UpperCAmelCase     ,					"""do_resize"""							)							)
						self.assertTrue(hasattr(__UpperCAmelCase     ,					"""size"""							)							)
						self.assertTrue(hasattr(__UpperCAmelCase     ,					"""do_center_crop"""							)							)
						self.assertTrue(hasattr(__UpperCAmelCase     ,					"""center_crop"""							)							)
						self.assertTrue(hasattr(__UpperCAmelCase     ,					"""do_flip_channel_order"""							)							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Tuple							) ->     List[str]:
						SCREAMING_SNAKE_CASE__										=   self.image_processing_class.from_dict(self.image_processor_dict							)
						self.assertEqual(image_processor.size     ,					{"""shortest_edge""": 2_0}							)
						self.assertEqual(image_processor.crop_size     ,					{"""height""": 1_8, """width""": 1_8}							)

						SCREAMING_SNAKE_CASE__										=   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					:    Dict							) ->     Dict:
						pass

			def        SCREAMING_SNAKE_CASE					(       self					:    Any							) ->     List[str]:
						# Initialize image_processing
						SCREAMING_SNAKE_CASE__										=   self.image_processing_class(**self.image_processor_dict							)
						# create random PIL images
						SCREAMING_SNAKE_CASE__										=   prepare_image_inputs(self.image_processor_tester     ,					equal_resolution=__UpperCAmelCase							)
						for image in image_inputs:
									self.assertIsInstance(__UpperCAmelCase     ,					Image.Image							)

						# Test not batched input
						SCREAMING_SNAKE_CASE__										=   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
						SCREAMING_SNAKE_CASE__										=   image_processing(__UpperCAmelCase     ,					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					:    List[Any]							) ->     Optional[int]:
						# Initialize image_processing
						SCREAMING_SNAKE_CASE__										=   self.image_processing_class(**self.image_processor_dict							)
						# create random numpy tensors
						SCREAMING_SNAKE_CASE__										=   prepare_image_inputs(self.image_processor_tester     ,					equal_resolution=__UpperCAmelCase     ,					numpify=__UpperCAmelCase							)
						for image in image_inputs:
									self.assertIsInstance(__UpperCAmelCase     ,					np.ndarray							)

						# Test not batched input
						SCREAMING_SNAKE_CASE__										=   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
						SCREAMING_SNAKE_CASE__										=   image_processing(__UpperCAmelCase     ,					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					:    List[str]							) ->     str:
						# Initialize image_processing
						SCREAMING_SNAKE_CASE__										=   self.image_processing_class(**self.image_processor_dict							)
						# create random PyTorch tensors
						SCREAMING_SNAKE_CASE__										=   prepare_image_inputs(self.image_processor_tester     ,					equal_resolution=__UpperCAmelCase     ,					torchify=__UpperCAmelCase							)
						for image in image_inputs:
									self.assertIsInstance(__UpperCAmelCase     ,					torch.Tensor							)

						# Test not batched input
						SCREAMING_SNAKE_CASE__										=   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
						SCREAMING_SNAKE_CASE__										=   image_processing(__UpperCAmelCase     ,					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"""],
						    )     ,					)


